xref: /openbmc/linux/drivers/media/dvb-frontends/stv0900_core.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
29a0bf528SMauro Carvalho Chehab /*
39a0bf528SMauro Carvalho Chehab  * stv0900_core.c
49a0bf528SMauro Carvalho Chehab  *
59a0bf528SMauro Carvalho Chehab  * Driver for ST STV0900 satellite demodulator IC.
69a0bf528SMauro Carvalho Chehab  *
79a0bf528SMauro Carvalho Chehab  * Copyright (C) ST Microelectronics.
89a0bf528SMauro Carvalho Chehab  * Copyright (C) 2009 NetUP Inc.
99a0bf528SMauro Carvalho Chehab  * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
109a0bf528SMauro Carvalho Chehab  */
119a0bf528SMauro Carvalho Chehab 
129a0bf528SMauro Carvalho Chehab #include <linux/kernel.h>
139a0bf528SMauro Carvalho Chehab #include <linux/module.h>
149a0bf528SMauro Carvalho Chehab #include <linux/string.h>
159a0bf528SMauro Carvalho Chehab #include <linux/slab.h>
169a0bf528SMauro Carvalho Chehab #include <linux/i2c.h>
179a0bf528SMauro Carvalho Chehab 
189a0bf528SMauro Carvalho Chehab #include "stv0900.h"
199a0bf528SMauro Carvalho Chehab #include "stv0900_reg.h"
209a0bf528SMauro Carvalho Chehab #include "stv0900_priv.h"
219a0bf528SMauro Carvalho Chehab #include "stv0900_init.h"
229a0bf528SMauro Carvalho Chehab 
239a0bf528SMauro Carvalho Chehab int stvdebug = 1;
249a0bf528SMauro Carvalho Chehab module_param_named(debug, stvdebug, int, 0644);
259a0bf528SMauro Carvalho Chehab 
269a0bf528SMauro Carvalho Chehab /* internal params node */
279a0bf528SMauro Carvalho Chehab struct stv0900_inode {
289a0bf528SMauro Carvalho Chehab 	/* pointer for internal params, one for each pair of demods */
299a0bf528SMauro Carvalho Chehab 	struct stv0900_internal		*internal;
309a0bf528SMauro Carvalho Chehab 	struct stv0900_inode		*next_inode;
319a0bf528SMauro Carvalho Chehab };
329a0bf528SMauro Carvalho Chehab 
339a0bf528SMauro Carvalho Chehab /* first internal params */
349a0bf528SMauro Carvalho Chehab static struct stv0900_inode *stv0900_first_inode;
359a0bf528SMauro Carvalho Chehab 
369a0bf528SMauro Carvalho Chehab /* find chip by i2c adapter and i2c address */
find_inode(struct i2c_adapter * i2c_adap,u8 i2c_addr)379a0bf528SMauro Carvalho Chehab static struct stv0900_inode *find_inode(struct i2c_adapter *i2c_adap,
389a0bf528SMauro Carvalho Chehab 							u8 i2c_addr)
399a0bf528SMauro Carvalho Chehab {
409a0bf528SMauro Carvalho Chehab 	struct stv0900_inode *temp_chip = stv0900_first_inode;
419a0bf528SMauro Carvalho Chehab 
429a0bf528SMauro Carvalho Chehab 	if (temp_chip != NULL) {
439a0bf528SMauro Carvalho Chehab 		/*
449a0bf528SMauro Carvalho Chehab 		 Search of the last stv0900 chip or
459a0bf528SMauro Carvalho Chehab 		 find it by i2c adapter and i2c address */
469a0bf528SMauro Carvalho Chehab 		while ((temp_chip != NULL) &&
479a0bf528SMauro Carvalho Chehab 			((temp_chip->internal->i2c_adap != i2c_adap) ||
489a0bf528SMauro Carvalho Chehab 			(temp_chip->internal->i2c_addr != i2c_addr)))
499a0bf528SMauro Carvalho Chehab 
509a0bf528SMauro Carvalho Chehab 			temp_chip = temp_chip->next_inode;
519a0bf528SMauro Carvalho Chehab 
529a0bf528SMauro Carvalho Chehab 	}
539a0bf528SMauro Carvalho Chehab 
549a0bf528SMauro Carvalho Chehab 	return temp_chip;
559a0bf528SMauro Carvalho Chehab }
569a0bf528SMauro Carvalho Chehab 
579a0bf528SMauro Carvalho Chehab /* deallocating chip */
remove_inode(struct stv0900_internal * internal)589a0bf528SMauro Carvalho Chehab static void remove_inode(struct stv0900_internal *internal)
599a0bf528SMauro Carvalho Chehab {
609a0bf528SMauro Carvalho Chehab 	struct stv0900_inode *prev_node = stv0900_first_inode;
619a0bf528SMauro Carvalho Chehab 	struct stv0900_inode *del_node = find_inode(internal->i2c_adap,
629a0bf528SMauro Carvalho Chehab 						internal->i2c_addr);
639a0bf528SMauro Carvalho Chehab 
649a0bf528SMauro Carvalho Chehab 	if (del_node != NULL) {
659a0bf528SMauro Carvalho Chehab 		if (del_node == stv0900_first_inode) {
669a0bf528SMauro Carvalho Chehab 			stv0900_first_inode = del_node->next_inode;
679a0bf528SMauro Carvalho Chehab 		} else {
689a0bf528SMauro Carvalho Chehab 			while (prev_node->next_inode != del_node)
699a0bf528SMauro Carvalho Chehab 				prev_node = prev_node->next_inode;
709a0bf528SMauro Carvalho Chehab 
719a0bf528SMauro Carvalho Chehab 			if (del_node->next_inode == NULL)
729a0bf528SMauro Carvalho Chehab 				prev_node->next_inode = NULL;
739a0bf528SMauro Carvalho Chehab 			else
749a0bf528SMauro Carvalho Chehab 				prev_node->next_inode =
759a0bf528SMauro Carvalho Chehab 					prev_node->next_inode->next_inode;
769a0bf528SMauro Carvalho Chehab 		}
779a0bf528SMauro Carvalho Chehab 
789a0bf528SMauro Carvalho Chehab 		kfree(del_node);
799a0bf528SMauro Carvalho Chehab 	}
809a0bf528SMauro Carvalho Chehab }
819a0bf528SMauro Carvalho Chehab 
829a0bf528SMauro Carvalho Chehab /* allocating new chip */
append_internal(struct stv0900_internal * internal)839a0bf528SMauro Carvalho Chehab static struct stv0900_inode *append_internal(struct stv0900_internal *internal)
849a0bf528SMauro Carvalho Chehab {
859a0bf528SMauro Carvalho Chehab 	struct stv0900_inode *new_node = stv0900_first_inode;
869a0bf528SMauro Carvalho Chehab 
879a0bf528SMauro Carvalho Chehab 	if (new_node == NULL) {
889a0bf528SMauro Carvalho Chehab 		new_node = kmalloc(sizeof(struct stv0900_inode), GFP_KERNEL);
899a0bf528SMauro Carvalho Chehab 		stv0900_first_inode = new_node;
909a0bf528SMauro Carvalho Chehab 	} else {
919a0bf528SMauro Carvalho Chehab 		while (new_node->next_inode != NULL)
929a0bf528SMauro Carvalho Chehab 			new_node = new_node->next_inode;
939a0bf528SMauro Carvalho Chehab 
949a0bf528SMauro Carvalho Chehab 		new_node->next_inode = kmalloc(sizeof(struct stv0900_inode),
959a0bf528SMauro Carvalho Chehab 								GFP_KERNEL);
969a0bf528SMauro Carvalho Chehab 		if (new_node->next_inode != NULL)
979a0bf528SMauro Carvalho Chehab 			new_node = new_node->next_inode;
989a0bf528SMauro Carvalho Chehab 		else
999a0bf528SMauro Carvalho Chehab 			new_node = NULL;
1009a0bf528SMauro Carvalho Chehab 	}
1019a0bf528SMauro Carvalho Chehab 
1029a0bf528SMauro Carvalho Chehab 	if (new_node != NULL) {
1039a0bf528SMauro Carvalho Chehab 		new_node->internal = internal;
1049a0bf528SMauro Carvalho Chehab 		new_node->next_inode = NULL;
1059a0bf528SMauro Carvalho Chehab 	}
1069a0bf528SMauro Carvalho Chehab 
1079a0bf528SMauro Carvalho Chehab 	return new_node;
1089a0bf528SMauro Carvalho Chehab }
1099a0bf528SMauro Carvalho Chehab 
ge2comp(s32 a,s32 width)1109a0bf528SMauro Carvalho Chehab s32 ge2comp(s32 a, s32 width)
1119a0bf528SMauro Carvalho Chehab {
1129a0bf528SMauro Carvalho Chehab 	if (width == 32)
1139a0bf528SMauro Carvalho Chehab 		return a;
1149a0bf528SMauro Carvalho Chehab 	else
1159a0bf528SMauro Carvalho Chehab 		return (a >= (1 << (width - 1))) ? (a - (1 << width)) : a;
1169a0bf528SMauro Carvalho Chehab }
1179a0bf528SMauro Carvalho Chehab 
stv0900_write_reg(struct stv0900_internal * intp,u16 reg_addr,u8 reg_data)1189a0bf528SMauro Carvalho Chehab void stv0900_write_reg(struct stv0900_internal *intp, u16 reg_addr,
1199a0bf528SMauro Carvalho Chehab 								u8 reg_data)
1209a0bf528SMauro Carvalho Chehab {
1219a0bf528SMauro Carvalho Chehab 	u8 data[3];
1229a0bf528SMauro Carvalho Chehab 	int ret;
1239a0bf528SMauro Carvalho Chehab 	struct i2c_msg i2cmsg = {
1249a0bf528SMauro Carvalho Chehab 		.addr  = intp->i2c_addr,
1259a0bf528SMauro Carvalho Chehab 		.flags = 0,
1269a0bf528SMauro Carvalho Chehab 		.len   = 3,
1279a0bf528SMauro Carvalho Chehab 		.buf   = data,
1289a0bf528SMauro Carvalho Chehab 	};
1299a0bf528SMauro Carvalho Chehab 
1309a0bf528SMauro Carvalho Chehab 	data[0] = MSB(reg_addr);
1319a0bf528SMauro Carvalho Chehab 	data[1] = LSB(reg_addr);
1329a0bf528SMauro Carvalho Chehab 	data[2] = reg_data;
1339a0bf528SMauro Carvalho Chehab 
1349a0bf528SMauro Carvalho Chehab 	ret = i2c_transfer(intp->i2c_adap, &i2cmsg, 1);
1359a0bf528SMauro Carvalho Chehab 	if (ret != 1)
1369a0bf528SMauro Carvalho Chehab 		dprintk("%s: i2c error %d\n", __func__, ret);
1379a0bf528SMauro Carvalho Chehab }
1389a0bf528SMauro Carvalho Chehab 
stv0900_read_reg(struct stv0900_internal * intp,u16 reg)1399a0bf528SMauro Carvalho Chehab u8 stv0900_read_reg(struct stv0900_internal *intp, u16 reg)
1409a0bf528SMauro Carvalho Chehab {
1419a0bf528SMauro Carvalho Chehab 	int ret;
1429a0bf528SMauro Carvalho Chehab 	u8 b0[] = { MSB(reg), LSB(reg) };
1439a0bf528SMauro Carvalho Chehab 	u8 buf = 0;
1449a0bf528SMauro Carvalho Chehab 	struct i2c_msg msg[] = {
1459a0bf528SMauro Carvalho Chehab 		{
1469a0bf528SMauro Carvalho Chehab 			.addr	= intp->i2c_addr,
1479a0bf528SMauro Carvalho Chehab 			.flags	= 0,
1489a0bf528SMauro Carvalho Chehab 			.buf = b0,
1499a0bf528SMauro Carvalho Chehab 			.len = 2,
1509a0bf528SMauro Carvalho Chehab 		}, {
1519a0bf528SMauro Carvalho Chehab 			.addr	= intp->i2c_addr,
1529a0bf528SMauro Carvalho Chehab 			.flags	= I2C_M_RD,
1539a0bf528SMauro Carvalho Chehab 			.buf = &buf,
1549a0bf528SMauro Carvalho Chehab 			.len = 1,
1559a0bf528SMauro Carvalho Chehab 		},
1569a0bf528SMauro Carvalho Chehab 	};
1579a0bf528SMauro Carvalho Chehab 
1589a0bf528SMauro Carvalho Chehab 	ret = i2c_transfer(intp->i2c_adap, msg, 2);
1599a0bf528SMauro Carvalho Chehab 	if (ret != 2)
1609a0bf528SMauro Carvalho Chehab 		dprintk("%s: i2c error %d, reg[0x%02x]\n",
1619a0bf528SMauro Carvalho Chehab 				__func__, ret, reg);
1629a0bf528SMauro Carvalho Chehab 
1639a0bf528SMauro Carvalho Chehab 	return buf;
1649a0bf528SMauro Carvalho Chehab }
1659a0bf528SMauro Carvalho Chehab 
extract_mask_pos(u32 label,u8 * mask,u8 * pos)1669a0bf528SMauro Carvalho Chehab static void extract_mask_pos(u32 label, u8 *mask, u8 *pos)
1679a0bf528SMauro Carvalho Chehab {
1689a0bf528SMauro Carvalho Chehab 	u8 position = 0, i = 0;
1699a0bf528SMauro Carvalho Chehab 
1709a0bf528SMauro Carvalho Chehab 	(*mask) = label & 0xff;
1719a0bf528SMauro Carvalho Chehab 
1729a0bf528SMauro Carvalho Chehab 	while ((position == 0) && (i < 8)) {
1739a0bf528SMauro Carvalho Chehab 		position = ((*mask) >> i) & 0x01;
1749a0bf528SMauro Carvalho Chehab 		i++;
1759a0bf528SMauro Carvalho Chehab 	}
1769a0bf528SMauro Carvalho Chehab 
1779a0bf528SMauro Carvalho Chehab 	(*pos) = (i - 1);
1789a0bf528SMauro Carvalho Chehab }
1799a0bf528SMauro Carvalho Chehab 
stv0900_write_bits(struct stv0900_internal * intp,u32 label,u8 val)1809a0bf528SMauro Carvalho Chehab void stv0900_write_bits(struct stv0900_internal *intp, u32 label, u8 val)
1819a0bf528SMauro Carvalho Chehab {
1829a0bf528SMauro Carvalho Chehab 	u8 reg, mask, pos;
1839a0bf528SMauro Carvalho Chehab 
1849a0bf528SMauro Carvalho Chehab 	reg = stv0900_read_reg(intp, (label >> 16) & 0xffff);
1859a0bf528SMauro Carvalho Chehab 	extract_mask_pos(label, &mask, &pos);
1869a0bf528SMauro Carvalho Chehab 
1879a0bf528SMauro Carvalho Chehab 	val = mask & (val << pos);
1889a0bf528SMauro Carvalho Chehab 
1899a0bf528SMauro Carvalho Chehab 	reg = (reg & (~mask)) | val;
1909a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, (label >> 16) & 0xffff, reg);
1919a0bf528SMauro Carvalho Chehab 
1929a0bf528SMauro Carvalho Chehab }
1939a0bf528SMauro Carvalho Chehab 
stv0900_get_bits(struct stv0900_internal * intp,u32 label)1949a0bf528SMauro Carvalho Chehab u8 stv0900_get_bits(struct stv0900_internal *intp, u32 label)
1959a0bf528SMauro Carvalho Chehab {
1964e054aabSColin Ian King 	u8 val;
1979a0bf528SMauro Carvalho Chehab 	u8 mask, pos;
1989a0bf528SMauro Carvalho Chehab 
1999a0bf528SMauro Carvalho Chehab 	extract_mask_pos(label, &mask, &pos);
2009a0bf528SMauro Carvalho Chehab 
2019a0bf528SMauro Carvalho Chehab 	val = stv0900_read_reg(intp, label >> 16);
2029a0bf528SMauro Carvalho Chehab 	val = (val & mask) >> pos;
2039a0bf528SMauro Carvalho Chehab 
2049a0bf528SMauro Carvalho Chehab 	return val;
2059a0bf528SMauro Carvalho Chehab }
2069a0bf528SMauro Carvalho Chehab 
stv0900_initialize(struct stv0900_internal * intp)2079a0bf528SMauro Carvalho Chehab static enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp)
2089a0bf528SMauro Carvalho Chehab {
2099a0bf528SMauro Carvalho Chehab 	s32 i;
2109a0bf528SMauro Carvalho Chehab 
2119a0bf528SMauro Carvalho Chehab 	if (intp == NULL)
2129a0bf528SMauro Carvalho Chehab 		return STV0900_INVALID_HANDLE;
2139a0bf528SMauro Carvalho Chehab 
2149a0bf528SMauro Carvalho Chehab 	intp->chip_id = stv0900_read_reg(intp, R0900_MID);
2159a0bf528SMauro Carvalho Chehab 
2169a0bf528SMauro Carvalho Chehab 	if (intp->errs != STV0900_NO_ERROR)
2179a0bf528SMauro Carvalho Chehab 		return intp->errs;
2189a0bf528SMauro Carvalho Chehab 
2199a0bf528SMauro Carvalho Chehab 	/*Startup sequence*/
2209a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_DMDISTATE, 0x5c);
2219a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_DMDISTATE, 0x5c);
2229a0bf528SMauro Carvalho Chehab 	msleep(3);
2239a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x6c);
2249a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x6f);
2259a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_I2CRPT, 0x20);
2269a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_I2CRPT, 0x20);
2279a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_NCOARSE, 0x13);
2289a0bf528SMauro Carvalho Chehab 	msleep(3);
2299a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_I2CCFG, 0x08);
2309a0bf528SMauro Carvalho Chehab 
2319a0bf528SMauro Carvalho Chehab 	switch (intp->clkmode) {
2329a0bf528SMauro Carvalho Chehab 	case 0:
2339a0bf528SMauro Carvalho Chehab 	case 2:
2349a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20
2359a0bf528SMauro Carvalho Chehab 				| intp->clkmode);
2369a0bf528SMauro Carvalho Chehab 		break;
2379a0bf528SMauro Carvalho Chehab 	default:
2389a0bf528SMauro Carvalho Chehab 		/* preserve SELOSCI bit */
2399a0bf528SMauro Carvalho Chehab 		i = 0x02 & stv0900_read_reg(intp, R0900_SYNTCTRL);
2409a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | i);
2419a0bf528SMauro Carvalho Chehab 		break;
2429a0bf528SMauro Carvalho Chehab 	}
2439a0bf528SMauro Carvalho Chehab 
2449a0bf528SMauro Carvalho Chehab 	msleep(3);
2459a0bf528SMauro Carvalho Chehab 	for (i = 0; i < 181; i++)
2469a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, STV0900_InitVal[i][0],
2479a0bf528SMauro Carvalho Chehab 				STV0900_InitVal[i][1]);
2489a0bf528SMauro Carvalho Chehab 
2499a0bf528SMauro Carvalho Chehab 	if (stv0900_read_reg(intp, R0900_MID) >= 0x20) {
2509a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_TSGENERAL, 0x0c);
2519a0bf528SMauro Carvalho Chehab 		for (i = 0; i < 32; i++)
2529a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, STV0900_Cut20_AddOnVal[i][0],
2539a0bf528SMauro Carvalho Chehab 					STV0900_Cut20_AddOnVal[i][1]);
2549a0bf528SMauro Carvalho Chehab 	}
2559a0bf528SMauro Carvalho Chehab 
2569a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_FSPYCFG, 0x6c);
2579a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_FSPYCFG, 0x6c);
2589a0bf528SMauro Carvalho Chehab 
2599a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_PDELCTRL2, 0x01);
2609a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_PDELCTRL2, 0x21);
2619a0bf528SMauro Carvalho Chehab 
2629a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_PDELCTRL3, 0x20);
2639a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_PDELCTRL3, 0x20);
2649a0bf528SMauro Carvalho Chehab 
2659a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_TSTRES0, 0x80);
2669a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_TSTRES0, 0x00);
2679a0bf528SMauro Carvalho Chehab 
2689a0bf528SMauro Carvalho Chehab 	return STV0900_NO_ERROR;
2699a0bf528SMauro Carvalho Chehab }
2709a0bf528SMauro Carvalho Chehab 
stv0900_get_mclk_freq(struct stv0900_internal * intp,u32 ext_clk)2719a0bf528SMauro Carvalho Chehab static u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk)
2729a0bf528SMauro Carvalho Chehab {
273247d46b3SColin Ian King 	u32 mclk, div, ad_div;
2749a0bf528SMauro Carvalho Chehab 
2759a0bf528SMauro Carvalho Chehab 	div = stv0900_get_bits(intp, F0900_M_DIV);
2769a0bf528SMauro Carvalho Chehab 	ad_div = ((stv0900_get_bits(intp, F0900_SELX1RATIO) == 1) ? 4 : 6);
2779a0bf528SMauro Carvalho Chehab 
2789a0bf528SMauro Carvalho Chehab 	mclk = (div + 1) * ext_clk / ad_div;
2799a0bf528SMauro Carvalho Chehab 
2809a0bf528SMauro Carvalho Chehab 	dprintk("%s: Calculated Mclk = %d\n", __func__, mclk);
2819a0bf528SMauro Carvalho Chehab 
2829a0bf528SMauro Carvalho Chehab 	return mclk;
2839a0bf528SMauro Carvalho Chehab }
2849a0bf528SMauro Carvalho Chehab 
stv0900_set_mclk(struct stv0900_internal * intp,u32 mclk)2859a0bf528SMauro Carvalho Chehab static enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk)
2869a0bf528SMauro Carvalho Chehab {
2879a0bf528SMauro Carvalho Chehab 	u32 m_div, clk_sel;
2889a0bf528SMauro Carvalho Chehab 
2899a0bf528SMauro Carvalho Chehab 	if (intp == NULL)
2909a0bf528SMauro Carvalho Chehab 		return STV0900_INVALID_HANDLE;
2919a0bf528SMauro Carvalho Chehab 
2929a0bf528SMauro Carvalho Chehab 	if (intp->errs)
2939a0bf528SMauro Carvalho Chehab 		return STV0900_I2C_ERROR;
2949a0bf528SMauro Carvalho Chehab 
295b0f9bf36SWei Yongjun 	dprintk("%s: Mclk set to %d, Quartz = %d\n", __func__, mclk,
296b0f9bf36SWei Yongjun 			intp->quartz);
297b0f9bf36SWei Yongjun 
2989a0bf528SMauro Carvalho Chehab 	clk_sel = ((stv0900_get_bits(intp, F0900_SELX1RATIO) == 1) ? 4 : 6);
2999a0bf528SMauro Carvalho Chehab 	m_div = ((clk_sel * mclk) / intp->quartz) - 1;
3009a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_M_DIV, m_div);
3019a0bf528SMauro Carvalho Chehab 	intp->mclk = stv0900_get_mclk_freq(intp,
3029a0bf528SMauro Carvalho Chehab 					intp->quartz);
3039a0bf528SMauro Carvalho Chehab 
3049a0bf528SMauro Carvalho Chehab 	/*Set the DiseqC frequency to 22KHz */
3059a0bf528SMauro Carvalho Chehab 	/*
3069a0bf528SMauro Carvalho Chehab 		Formula:
3079a0bf528SMauro Carvalho Chehab 		DiseqC_TX_Freq= MasterClock/(32*F22TX_Reg)
3089a0bf528SMauro Carvalho Chehab 		DiseqC_RX_Freq= MasterClock/(32*F22RX_Reg)
3099a0bf528SMauro Carvalho Chehab 	*/
3109a0bf528SMauro Carvalho Chehab 	m_div = intp->mclk / 704000;
3119a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_F22TX, m_div);
3129a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_F22RX, m_div);
3139a0bf528SMauro Carvalho Chehab 
3149a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_F22TX, m_div);
3159a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_F22RX, m_div);
3169a0bf528SMauro Carvalho Chehab 
3179a0bf528SMauro Carvalho Chehab 	if ((intp->errs))
3189a0bf528SMauro Carvalho Chehab 		return STV0900_I2C_ERROR;
3199a0bf528SMauro Carvalho Chehab 
3209a0bf528SMauro Carvalho Chehab 	return STV0900_NO_ERROR;
3219a0bf528SMauro Carvalho Chehab }
3229a0bf528SMauro Carvalho Chehab 
stv0900_get_err_count(struct stv0900_internal * intp,int cntr,enum fe_stv0900_demod_num demod)3239a0bf528SMauro Carvalho Chehab static u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr,
3249a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_demod_num demod)
3259a0bf528SMauro Carvalho Chehab {
3269a0bf528SMauro Carvalho Chehab 	u32 lsb, msb, hsb, err_val;
3279a0bf528SMauro Carvalho Chehab 
3289a0bf528SMauro Carvalho Chehab 	switch (cntr) {
3299a0bf528SMauro Carvalho Chehab 	case 0:
3309a0bf528SMauro Carvalho Chehab 	default:
3319a0bf528SMauro Carvalho Chehab 		hsb = stv0900_get_bits(intp, ERR_CNT12);
3329a0bf528SMauro Carvalho Chehab 		msb = stv0900_get_bits(intp, ERR_CNT11);
3339a0bf528SMauro Carvalho Chehab 		lsb = stv0900_get_bits(intp, ERR_CNT10);
3349a0bf528SMauro Carvalho Chehab 		break;
3359a0bf528SMauro Carvalho Chehab 	case 1:
3369a0bf528SMauro Carvalho Chehab 		hsb = stv0900_get_bits(intp, ERR_CNT22);
3379a0bf528SMauro Carvalho Chehab 		msb = stv0900_get_bits(intp, ERR_CNT21);
3389a0bf528SMauro Carvalho Chehab 		lsb = stv0900_get_bits(intp, ERR_CNT20);
3399a0bf528SMauro Carvalho Chehab 		break;
3409a0bf528SMauro Carvalho Chehab 	}
3419a0bf528SMauro Carvalho Chehab 
3429a0bf528SMauro Carvalho Chehab 	err_val = (hsb << 16) + (msb << 8) + (lsb);
3439a0bf528SMauro Carvalho Chehab 
3449a0bf528SMauro Carvalho Chehab 	return err_val;
3459a0bf528SMauro Carvalho Chehab }
3469a0bf528SMauro Carvalho Chehab 
stv0900_i2c_gate_ctrl(struct dvb_frontend * fe,int enable)3479a0bf528SMauro Carvalho Chehab static int stv0900_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
3489a0bf528SMauro Carvalho Chehab {
3499a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
3509a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
3519a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
3529a0bf528SMauro Carvalho Chehab 
3539a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, I2CT_ON, enable);
3549a0bf528SMauro Carvalho Chehab 
3559a0bf528SMauro Carvalho Chehab 	return 0;
3569a0bf528SMauro Carvalho Chehab }
3579a0bf528SMauro Carvalho Chehab 
stv0900_set_ts_parallel_serial(struct stv0900_internal * intp,enum fe_stv0900_clock_type path1_ts,enum fe_stv0900_clock_type path2_ts)3589a0bf528SMauro Carvalho Chehab static void stv0900_set_ts_parallel_serial(struct stv0900_internal *intp,
3599a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_clock_type path1_ts,
3609a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_clock_type path2_ts)
3619a0bf528SMauro Carvalho Chehab {
3629a0bf528SMauro Carvalho Chehab 
3639a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
3649a0bf528SMauro Carvalho Chehab 
3659a0bf528SMauro Carvalho Chehab 	if (intp->chip_id >= 0x20) {
3669a0bf528SMauro Carvalho Chehab 		switch (path1_ts) {
3679a0bf528SMauro Carvalho Chehab 		case STV0900_PARALLEL_PUNCT_CLOCK:
3689a0bf528SMauro Carvalho Chehab 		case STV0900_DVBCI_CLOCK:
3699a0bf528SMauro Carvalho Chehab 			switch (path2_ts) {
3709a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_PUNCT_CLOCK:
3719a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_CONT_CLOCK:
3729a0bf528SMauro Carvalho Chehab 			default:
3739a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL,
3749a0bf528SMauro Carvalho Chehab 							0x00);
3759a0bf528SMauro Carvalho Chehab 				break;
3769a0bf528SMauro Carvalho Chehab 			case STV0900_PARALLEL_PUNCT_CLOCK:
3779a0bf528SMauro Carvalho Chehab 			case STV0900_DVBCI_CLOCK:
3789a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL,
3799a0bf528SMauro Carvalho Chehab 							0x06);
3809a0bf528SMauro Carvalho Chehab 				stv0900_write_bits(intp,
3819a0bf528SMauro Carvalho Chehab 						F0900_P1_TSFIFO_MANSPEED, 3);
3829a0bf528SMauro Carvalho Chehab 				stv0900_write_bits(intp,
3839a0bf528SMauro Carvalho Chehab 						F0900_P2_TSFIFO_MANSPEED, 0);
3849a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
3859a0bf528SMauro Carvalho Chehab 						R0900_P1_TSSPEED, 0x14);
3869a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
3879a0bf528SMauro Carvalho Chehab 						R0900_P2_TSSPEED, 0x28);
3889a0bf528SMauro Carvalho Chehab 				break;
3899a0bf528SMauro Carvalho Chehab 			}
3909a0bf528SMauro Carvalho Chehab 			break;
3919a0bf528SMauro Carvalho Chehab 		case STV0900_SERIAL_PUNCT_CLOCK:
3929a0bf528SMauro Carvalho Chehab 		case STV0900_SERIAL_CONT_CLOCK:
3939a0bf528SMauro Carvalho Chehab 		default:
3949a0bf528SMauro Carvalho Chehab 			switch (path2_ts) {
3959a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_PUNCT_CLOCK:
3969a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_CONT_CLOCK:
3979a0bf528SMauro Carvalho Chehab 			default:
3989a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
3999a0bf528SMauro Carvalho Chehab 						R0900_TSGENERAL, 0x0C);
4009a0bf528SMauro Carvalho Chehab 				break;
4019a0bf528SMauro Carvalho Chehab 			case STV0900_PARALLEL_PUNCT_CLOCK:
4029a0bf528SMauro Carvalho Chehab 			case STV0900_DVBCI_CLOCK:
4039a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
4049a0bf528SMauro Carvalho Chehab 						R0900_TSGENERAL, 0x0A);
4059a0bf528SMauro Carvalho Chehab 				dprintk("%s: 0x0a\n", __func__);
4069a0bf528SMauro Carvalho Chehab 				break;
4079a0bf528SMauro Carvalho Chehab 			}
4089a0bf528SMauro Carvalho Chehab 			break;
4099a0bf528SMauro Carvalho Chehab 		}
4109a0bf528SMauro Carvalho Chehab 	} else {
4119a0bf528SMauro Carvalho Chehab 		switch (path1_ts) {
4129a0bf528SMauro Carvalho Chehab 		case STV0900_PARALLEL_PUNCT_CLOCK:
4139a0bf528SMauro Carvalho Chehab 		case STV0900_DVBCI_CLOCK:
4149a0bf528SMauro Carvalho Chehab 			switch (path2_ts) {
4159a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_PUNCT_CLOCK:
4169a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_CONT_CLOCK:
4179a0bf528SMauro Carvalho Chehab 			default:
4189a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL1X,
4199a0bf528SMauro Carvalho Chehab 							0x10);
4209a0bf528SMauro Carvalho Chehab 				break;
4219a0bf528SMauro Carvalho Chehab 			case STV0900_PARALLEL_PUNCT_CLOCK:
4229a0bf528SMauro Carvalho Chehab 			case STV0900_DVBCI_CLOCK:
4239a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL1X,
4249a0bf528SMauro Carvalho Chehab 							0x16);
4259a0bf528SMauro Carvalho Chehab 				stv0900_write_bits(intp,
4269a0bf528SMauro Carvalho Chehab 						F0900_P1_TSFIFO_MANSPEED, 3);
4279a0bf528SMauro Carvalho Chehab 				stv0900_write_bits(intp,
4289a0bf528SMauro Carvalho Chehab 						F0900_P2_TSFIFO_MANSPEED, 0);
4299a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_P1_TSSPEED,
4309a0bf528SMauro Carvalho Chehab 							0x14);
4319a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_P2_TSSPEED,
4329a0bf528SMauro Carvalho Chehab 							0x28);
4339a0bf528SMauro Carvalho Chehab 				break;
4349a0bf528SMauro Carvalho Chehab 			}
4359a0bf528SMauro Carvalho Chehab 
4369a0bf528SMauro Carvalho Chehab 			break;
4379a0bf528SMauro Carvalho Chehab 		case STV0900_SERIAL_PUNCT_CLOCK:
4389a0bf528SMauro Carvalho Chehab 		case STV0900_SERIAL_CONT_CLOCK:
4399a0bf528SMauro Carvalho Chehab 		default:
4409a0bf528SMauro Carvalho Chehab 			switch (path2_ts) {
4419a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_PUNCT_CLOCK:
4429a0bf528SMauro Carvalho Chehab 			case STV0900_SERIAL_CONT_CLOCK:
4439a0bf528SMauro Carvalho Chehab 			default:
4449a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL1X,
4459a0bf528SMauro Carvalho Chehab 							0x14);
4469a0bf528SMauro Carvalho Chehab 				break;
4479a0bf528SMauro Carvalho Chehab 			case STV0900_PARALLEL_PUNCT_CLOCK:
4489a0bf528SMauro Carvalho Chehab 			case STV0900_DVBCI_CLOCK:
4499a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, R0900_TSGENERAL1X,
4509a0bf528SMauro Carvalho Chehab 							0x12);
4519a0bf528SMauro Carvalho Chehab 				dprintk("%s: 0x12\n", __func__);
4529a0bf528SMauro Carvalho Chehab 				break;
4539a0bf528SMauro Carvalho Chehab 			}
4549a0bf528SMauro Carvalho Chehab 
4559a0bf528SMauro Carvalho Chehab 			break;
4569a0bf528SMauro Carvalho Chehab 		}
4579a0bf528SMauro Carvalho Chehab 	}
4589a0bf528SMauro Carvalho Chehab 
4599a0bf528SMauro Carvalho Chehab 	switch (path1_ts) {
4609a0bf528SMauro Carvalho Chehab 	case STV0900_PARALLEL_PUNCT_CLOCK:
4619a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x00);
4629a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x00);
4639a0bf528SMauro Carvalho Chehab 		break;
4649a0bf528SMauro Carvalho Chehab 	case STV0900_DVBCI_CLOCK:
4659a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x00);
4669a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x01);
4679a0bf528SMauro Carvalho Chehab 		break;
4689a0bf528SMauro Carvalho Chehab 	case STV0900_SERIAL_PUNCT_CLOCK:
4699a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x01);
4709a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x00);
4719a0bf528SMauro Carvalho Chehab 		break;
4729a0bf528SMauro Carvalho Chehab 	case STV0900_SERIAL_CONT_CLOCK:
4739a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x01);
4749a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x01);
4759a0bf528SMauro Carvalho Chehab 		break;
4769a0bf528SMauro Carvalho Chehab 	default:
4779a0bf528SMauro Carvalho Chehab 		break;
4789a0bf528SMauro Carvalho Chehab 	}
4799a0bf528SMauro Carvalho Chehab 
4809a0bf528SMauro Carvalho Chehab 	switch (path2_ts) {
4819a0bf528SMauro Carvalho Chehab 	case STV0900_PARALLEL_PUNCT_CLOCK:
4829a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x00);
4839a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x00);
4849a0bf528SMauro Carvalho Chehab 		break;
4859a0bf528SMauro Carvalho Chehab 	case STV0900_DVBCI_CLOCK:
4869a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x00);
4879a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x01);
4889a0bf528SMauro Carvalho Chehab 		break;
4899a0bf528SMauro Carvalho Chehab 	case STV0900_SERIAL_PUNCT_CLOCK:
4909a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x01);
4919a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x00);
4929a0bf528SMauro Carvalho Chehab 		break;
4939a0bf528SMauro Carvalho Chehab 	case STV0900_SERIAL_CONT_CLOCK:
4949a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x01);
4959a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x01);
4969a0bf528SMauro Carvalho Chehab 		break;
4979a0bf528SMauro Carvalho Chehab 	default:
4989a0bf528SMauro Carvalho Chehab 		break;
4999a0bf528SMauro Carvalho Chehab 	}
5009a0bf528SMauro Carvalho Chehab 
5019a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P2_RST_HWARE, 1);
5029a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P2_RST_HWARE, 0);
5039a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P1_RST_HWARE, 1);
5049a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0);
5059a0bf528SMauro Carvalho Chehab }
5069a0bf528SMauro Carvalho Chehab 
stv0900_set_tuner(struct dvb_frontend * fe,u32 frequency,u32 bandwidth)5079a0bf528SMauro Carvalho Chehab void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
5089a0bf528SMauro Carvalho Chehab 							u32 bandwidth)
5099a0bf528SMauro Carvalho Chehab {
5109a0bf528SMauro Carvalho Chehab 	struct dvb_frontend_ops *frontend_ops = NULL;
5119a0bf528SMauro Carvalho Chehab 	struct dvb_tuner_ops *tuner_ops = NULL;
5129a0bf528SMauro Carvalho Chehab 
5139a0bf528SMauro Carvalho Chehab 	frontend_ops = &fe->ops;
5149a0bf528SMauro Carvalho Chehab 	tuner_ops = &frontend_ops->tuner_ops;
5159a0bf528SMauro Carvalho Chehab 
5169a0bf528SMauro Carvalho Chehab 	if (tuner_ops->set_frequency) {
5179a0bf528SMauro Carvalho Chehab 		if ((tuner_ops->set_frequency(fe, frequency)) < 0)
5189a0bf528SMauro Carvalho Chehab 			dprintk("%s: Invalid parameter\n", __func__);
5199a0bf528SMauro Carvalho Chehab 		else
5209a0bf528SMauro Carvalho Chehab 			dprintk("%s: Frequency=%d\n", __func__, frequency);
5219a0bf528SMauro Carvalho Chehab 
5229a0bf528SMauro Carvalho Chehab 	}
5239a0bf528SMauro Carvalho Chehab 
5249a0bf528SMauro Carvalho Chehab 	if (tuner_ops->set_bandwidth) {
5259a0bf528SMauro Carvalho Chehab 		if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0)
5269a0bf528SMauro Carvalho Chehab 			dprintk("%s: Invalid parameter\n", __func__);
5279a0bf528SMauro Carvalho Chehab 		else
5289a0bf528SMauro Carvalho Chehab 			dprintk("%s: Bandwidth=%d\n", __func__, bandwidth);
5299a0bf528SMauro Carvalho Chehab 
5309a0bf528SMauro Carvalho Chehab 	}
5319a0bf528SMauro Carvalho Chehab }
5329a0bf528SMauro Carvalho Chehab 
stv0900_set_bandwidth(struct dvb_frontend * fe,u32 bandwidth)5339a0bf528SMauro Carvalho Chehab void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
5349a0bf528SMauro Carvalho Chehab {
5359a0bf528SMauro Carvalho Chehab 	struct dvb_frontend_ops *frontend_ops = NULL;
5369a0bf528SMauro Carvalho Chehab 	struct dvb_tuner_ops *tuner_ops = NULL;
5379a0bf528SMauro Carvalho Chehab 
5389a0bf528SMauro Carvalho Chehab 	frontend_ops = &fe->ops;
5399a0bf528SMauro Carvalho Chehab 	tuner_ops = &frontend_ops->tuner_ops;
5409a0bf528SMauro Carvalho Chehab 
5419a0bf528SMauro Carvalho Chehab 	if (tuner_ops->set_bandwidth) {
5429a0bf528SMauro Carvalho Chehab 		if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0)
5439a0bf528SMauro Carvalho Chehab 			dprintk("%s: Invalid parameter\n", __func__);
5449a0bf528SMauro Carvalho Chehab 		else
5459a0bf528SMauro Carvalho Chehab 			dprintk("%s: Bandwidth=%d\n", __func__, bandwidth);
5469a0bf528SMauro Carvalho Chehab 
5479a0bf528SMauro Carvalho Chehab 	}
5489a0bf528SMauro Carvalho Chehab }
5499a0bf528SMauro Carvalho Chehab 
stv0900_get_freq_auto(struct stv0900_internal * intp,int demod)5509a0bf528SMauro Carvalho Chehab u32 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod)
5519a0bf528SMauro Carvalho Chehab {
5529a0bf528SMauro Carvalho Chehab 	u32 freq, round;
5539a0bf528SMauro Carvalho Chehab 	/*	Formulat :
5549a0bf528SMauro Carvalho Chehab 	Tuner_Frequency(MHz)	= Regs / 64
5559a0bf528SMauro Carvalho Chehab 	Tuner_granularity(MHz)	= Regs / 2048
5569a0bf528SMauro Carvalho Chehab 	real_Tuner_Frequency	= Tuner_Frequency(MHz) - Tuner_granularity(MHz)
5579a0bf528SMauro Carvalho Chehab 	*/
5589a0bf528SMauro Carvalho Chehab 	freq = (stv0900_get_bits(intp, TUN_RFFREQ2) << 10) +
5599a0bf528SMauro Carvalho Chehab 		(stv0900_get_bits(intp, TUN_RFFREQ1) << 2) +
5609a0bf528SMauro Carvalho Chehab 		stv0900_get_bits(intp, TUN_RFFREQ0);
5619a0bf528SMauro Carvalho Chehab 
5629a0bf528SMauro Carvalho Chehab 	freq = (freq * 1000) / 64;
5639a0bf528SMauro Carvalho Chehab 
5649a0bf528SMauro Carvalho Chehab 	round = (stv0900_get_bits(intp, TUN_RFRESTE1) >> 2) +
5659a0bf528SMauro Carvalho Chehab 		stv0900_get_bits(intp, TUN_RFRESTE0);
5669a0bf528SMauro Carvalho Chehab 
5679a0bf528SMauro Carvalho Chehab 	round = (round * 1000) / 2048;
5689a0bf528SMauro Carvalho Chehab 
5699a0bf528SMauro Carvalho Chehab 	return freq + round;
5709a0bf528SMauro Carvalho Chehab }
5719a0bf528SMauro Carvalho Chehab 
stv0900_set_tuner_auto(struct stv0900_internal * intp,u32 Frequency,u32 Bandwidth,int demod)5729a0bf528SMauro Carvalho Chehab void stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
5739a0bf528SMauro Carvalho Chehab 						u32 Bandwidth, int demod)
5749a0bf528SMauro Carvalho Chehab {
5759a0bf528SMauro Carvalho Chehab 	u32 tunerFrequency;
5769a0bf528SMauro Carvalho Chehab 	/* Formulat:
5779a0bf528SMauro Carvalho Chehab 	Tuner_frequency_reg= Frequency(MHz)*64
5789a0bf528SMauro Carvalho Chehab 	*/
5799a0bf528SMauro Carvalho Chehab 	tunerFrequency = (Frequency * 64) / 1000;
5809a0bf528SMauro Carvalho Chehab 
5819a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, TUN_RFFREQ2, (tunerFrequency >> 10));
5829a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, TUN_RFFREQ1, (tunerFrequency >> 2) & 0xff);
5839a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, TUN_RFFREQ0, (tunerFrequency & 0x03));
5849a0bf528SMauro Carvalho Chehab 	/* Low Pass Filter = BW /2 (MHz)*/
5859a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, TUN_BW, Bandwidth / 2000000);
5869a0bf528SMauro Carvalho Chehab 	/* Tuner Write trig */
5879a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, TNRLD, 1);
5889a0bf528SMauro Carvalho Chehab }
5899a0bf528SMauro Carvalho Chehab 
stv0900_get_rf_level(struct stv0900_internal * intp,const struct stv0900_table * lookup,enum fe_stv0900_demod_num demod)5909a0bf528SMauro Carvalho Chehab static s32 stv0900_get_rf_level(struct stv0900_internal *intp,
5919a0bf528SMauro Carvalho Chehab 				const struct stv0900_table *lookup,
5929a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_demod_num demod)
5939a0bf528SMauro Carvalho Chehab {
5949a0bf528SMauro Carvalho Chehab 	s32 agc_gain = 0,
5959a0bf528SMauro Carvalho Chehab 		imin,
5969a0bf528SMauro Carvalho Chehab 		imax,
5979a0bf528SMauro Carvalho Chehab 		i,
5989a0bf528SMauro Carvalho Chehab 		rf_lvl = 0;
5999a0bf528SMauro Carvalho Chehab 
6009a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
6019a0bf528SMauro Carvalho Chehab 
6029a0bf528SMauro Carvalho Chehab 	if ((lookup == NULL) || (lookup->size <= 0))
6039a0bf528SMauro Carvalho Chehab 		return 0;
6049a0bf528SMauro Carvalho Chehab 
6059a0bf528SMauro Carvalho Chehab 	agc_gain = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1),
6069a0bf528SMauro Carvalho Chehab 				stv0900_get_bits(intp, AGCIQ_VALUE0));
6079a0bf528SMauro Carvalho Chehab 
6089a0bf528SMauro Carvalho Chehab 	imin = 0;
6099a0bf528SMauro Carvalho Chehab 	imax = lookup->size - 1;
6109a0bf528SMauro Carvalho Chehab 	if (INRANGE(lookup->table[imin].regval, agc_gain,
6119a0bf528SMauro Carvalho Chehab 					lookup->table[imax].regval)) {
6129a0bf528SMauro Carvalho Chehab 		while ((imax - imin) > 1) {
6139a0bf528SMauro Carvalho Chehab 			i = (imax + imin) >> 1;
6149a0bf528SMauro Carvalho Chehab 
6159a0bf528SMauro Carvalho Chehab 			if (INRANGE(lookup->table[imin].regval,
6169a0bf528SMauro Carvalho Chehab 					agc_gain,
6179a0bf528SMauro Carvalho Chehab 					lookup->table[i].regval))
6189a0bf528SMauro Carvalho Chehab 				imax = i;
6199a0bf528SMauro Carvalho Chehab 			else
6209a0bf528SMauro Carvalho Chehab 				imin = i;
6219a0bf528SMauro Carvalho Chehab 		}
6229a0bf528SMauro Carvalho Chehab 
6239a0bf528SMauro Carvalho Chehab 		rf_lvl = (s32)agc_gain - lookup->table[imin].regval;
6249a0bf528SMauro Carvalho Chehab 		rf_lvl *= (lookup->table[imax].realval -
6259a0bf528SMauro Carvalho Chehab 				lookup->table[imin].realval);
6269a0bf528SMauro Carvalho Chehab 		rf_lvl /= (lookup->table[imax].regval -
6279a0bf528SMauro Carvalho Chehab 				lookup->table[imin].regval);
6289a0bf528SMauro Carvalho Chehab 		rf_lvl += lookup->table[imin].realval;
6299a0bf528SMauro Carvalho Chehab 	} else if (agc_gain > lookup->table[0].regval)
6309a0bf528SMauro Carvalho Chehab 		rf_lvl = 5;
6319a0bf528SMauro Carvalho Chehab 	else if (agc_gain < lookup->table[lookup->size-1].regval)
6329a0bf528SMauro Carvalho Chehab 		rf_lvl = -100;
6339a0bf528SMauro Carvalho Chehab 
6349a0bf528SMauro Carvalho Chehab 	dprintk("%s: RFLevel = %d\n", __func__, rf_lvl);
6359a0bf528SMauro Carvalho Chehab 
6369a0bf528SMauro Carvalho Chehab 	return rf_lvl;
6379a0bf528SMauro Carvalho Chehab }
6389a0bf528SMauro Carvalho Chehab 
stv0900_read_signal_strength(struct dvb_frontend * fe,u16 * strength)6399a0bf528SMauro Carvalho Chehab static int stv0900_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
6409a0bf528SMauro Carvalho Chehab {
6419a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
6429a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *internal = state->internal;
6439a0bf528SMauro Carvalho Chehab 	s32 rflevel = stv0900_get_rf_level(internal, &stv0900_rf,
6449a0bf528SMauro Carvalho Chehab 								state->demod);
6459a0bf528SMauro Carvalho Chehab 
6469a0bf528SMauro Carvalho Chehab 	rflevel = (rflevel + 100) * (65535 / 70);
6479a0bf528SMauro Carvalho Chehab 	if (rflevel < 0)
6489a0bf528SMauro Carvalho Chehab 		rflevel = 0;
6499a0bf528SMauro Carvalho Chehab 
6509a0bf528SMauro Carvalho Chehab 	if (rflevel > 65535)
6519a0bf528SMauro Carvalho Chehab 		rflevel = 65535;
6529a0bf528SMauro Carvalho Chehab 
6539a0bf528SMauro Carvalho Chehab 	*strength = rflevel;
6549a0bf528SMauro Carvalho Chehab 
6559a0bf528SMauro Carvalho Chehab 	return 0;
6569a0bf528SMauro Carvalho Chehab }
6579a0bf528SMauro Carvalho Chehab 
stv0900_carr_get_quality(struct dvb_frontend * fe,const struct stv0900_table * lookup)6589a0bf528SMauro Carvalho Chehab static s32 stv0900_carr_get_quality(struct dvb_frontend *fe,
6599a0bf528SMauro Carvalho Chehab 					const struct stv0900_table *lookup)
6609a0bf528SMauro Carvalho Chehab {
6619a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
6629a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
6639a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
6649a0bf528SMauro Carvalho Chehab 
6659a0bf528SMauro Carvalho Chehab 	s32	c_n = -100,
6669a0bf528SMauro Carvalho Chehab 		regval,
6679a0bf528SMauro Carvalho Chehab 		imin,
6689a0bf528SMauro Carvalho Chehab 		imax,
6699a0bf528SMauro Carvalho Chehab 		i,
6709a0bf528SMauro Carvalho Chehab 		noise_field1,
6719a0bf528SMauro Carvalho Chehab 		noise_field0;
6729a0bf528SMauro Carvalho Chehab 
6739a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
6749a0bf528SMauro Carvalho Chehab 
6759a0bf528SMauro Carvalho Chehab 	if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) {
6769a0bf528SMauro Carvalho Chehab 		noise_field1 = NOSPLHT_NORMED1;
6779a0bf528SMauro Carvalho Chehab 		noise_field0 = NOSPLHT_NORMED0;
6789a0bf528SMauro Carvalho Chehab 	} else {
6799a0bf528SMauro Carvalho Chehab 		noise_field1 = NOSDATAT_NORMED1;
6809a0bf528SMauro Carvalho Chehab 		noise_field0 = NOSDATAT_NORMED0;
6819a0bf528SMauro Carvalho Chehab 	}
6829a0bf528SMauro Carvalho Chehab 
6839a0bf528SMauro Carvalho Chehab 	if (stv0900_get_bits(intp, LOCK_DEFINITIF)) {
6849a0bf528SMauro Carvalho Chehab 		if ((lookup != NULL) && lookup->size) {
6859a0bf528SMauro Carvalho Chehab 			regval = 0;
6869a0bf528SMauro Carvalho Chehab 			msleep(5);
6879a0bf528SMauro Carvalho Chehab 			for (i = 0; i < 16; i++) {
6889a0bf528SMauro Carvalho Chehab 				regval += MAKEWORD(stv0900_get_bits(intp,
6899a0bf528SMauro Carvalho Chehab 								noise_field1),
6909a0bf528SMauro Carvalho Chehab 						stv0900_get_bits(intp,
6919a0bf528SMauro Carvalho Chehab 								noise_field0));
6929a0bf528SMauro Carvalho Chehab 				msleep(1);
6939a0bf528SMauro Carvalho Chehab 			}
6949a0bf528SMauro Carvalho Chehab 
6959a0bf528SMauro Carvalho Chehab 			regval /= 16;
6969a0bf528SMauro Carvalho Chehab 			imin = 0;
6979a0bf528SMauro Carvalho Chehab 			imax = lookup->size - 1;
6989a0bf528SMauro Carvalho Chehab 			if (INRANGE(lookup->table[imin].regval,
6999a0bf528SMauro Carvalho Chehab 					regval,
7009a0bf528SMauro Carvalho Chehab 					lookup->table[imax].regval)) {
7019a0bf528SMauro Carvalho Chehab 				while ((imax - imin) > 1) {
7029a0bf528SMauro Carvalho Chehab 					i = (imax + imin) >> 1;
7039a0bf528SMauro Carvalho Chehab 					if (INRANGE(lookup->table[imin].regval,
7049a0bf528SMauro Carvalho Chehab 						    regval,
7059a0bf528SMauro Carvalho Chehab 						    lookup->table[i].regval))
7069a0bf528SMauro Carvalho Chehab 						imax = i;
7079a0bf528SMauro Carvalho Chehab 					else
7089a0bf528SMauro Carvalho Chehab 						imin = i;
7099a0bf528SMauro Carvalho Chehab 				}
7109a0bf528SMauro Carvalho Chehab 
7119a0bf528SMauro Carvalho Chehab 				c_n = ((regval - lookup->table[imin].regval)
7129a0bf528SMauro Carvalho Chehab 						* (lookup->table[imax].realval
7139a0bf528SMauro Carvalho Chehab 						- lookup->table[imin].realval)
7149a0bf528SMauro Carvalho Chehab 						/ (lookup->table[imax].regval
7159a0bf528SMauro Carvalho Chehab 						- lookup->table[imin].regval))
7169a0bf528SMauro Carvalho Chehab 						+ lookup->table[imin].realval;
7179a0bf528SMauro Carvalho Chehab 			} else if (regval < lookup->table[imin].regval)
7189a0bf528SMauro Carvalho Chehab 				c_n = 1000;
7199a0bf528SMauro Carvalho Chehab 		}
7209a0bf528SMauro Carvalho Chehab 	}
7219a0bf528SMauro Carvalho Chehab 
7229a0bf528SMauro Carvalho Chehab 	return c_n;
7239a0bf528SMauro Carvalho Chehab }
7249a0bf528SMauro Carvalho Chehab 
stv0900_read_ucblocks(struct dvb_frontend * fe,u32 * ucblocks)7259a0bf528SMauro Carvalho Chehab static int stv0900_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks)
7269a0bf528SMauro Carvalho Chehab {
7279a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
7289a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
7299a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
7309a0bf528SMauro Carvalho Chehab 	u8 err_val1, err_val0;
7319a0bf528SMauro Carvalho Chehab 	u32 header_err_val = 0;
7329a0bf528SMauro Carvalho Chehab 
7339a0bf528SMauro Carvalho Chehab 	*ucblocks = 0x0;
7349a0bf528SMauro Carvalho Chehab 	if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) {
7359a0bf528SMauro Carvalho Chehab 		/* DVB-S2 delineator errors count */
7369a0bf528SMauro Carvalho Chehab 
737868c9a17SMauro Carvalho Chehab 		/* retrieving number for errnous headers */
7389a0bf528SMauro Carvalho Chehab 		err_val1 = stv0900_read_reg(intp, BBFCRCKO1);
7399a0bf528SMauro Carvalho Chehab 		err_val0 = stv0900_read_reg(intp, BBFCRCKO0);
7409a0bf528SMauro Carvalho Chehab 		header_err_val = (err_val1 << 8) | err_val0;
7419a0bf528SMauro Carvalho Chehab 
742868c9a17SMauro Carvalho Chehab 		/* retrieving number for errnous packets */
7439a0bf528SMauro Carvalho Chehab 		err_val1 = stv0900_read_reg(intp, UPCRCKO1);
7449a0bf528SMauro Carvalho Chehab 		err_val0 = stv0900_read_reg(intp, UPCRCKO0);
7459a0bf528SMauro Carvalho Chehab 		*ucblocks = (err_val1 << 8) | err_val0;
7469a0bf528SMauro Carvalho Chehab 		*ucblocks += header_err_val;
7479a0bf528SMauro Carvalho Chehab 	}
7489a0bf528SMauro Carvalho Chehab 
7499a0bf528SMauro Carvalho Chehab 	return 0;
7509a0bf528SMauro Carvalho Chehab }
7519a0bf528SMauro Carvalho Chehab 
stv0900_read_snr(struct dvb_frontend * fe,u16 * snr)7529a0bf528SMauro Carvalho Chehab static int stv0900_read_snr(struct dvb_frontend *fe, u16 *snr)
7539a0bf528SMauro Carvalho Chehab {
7549a0bf528SMauro Carvalho Chehab 	s32 snrlcl = stv0900_carr_get_quality(fe,
7559a0bf528SMauro Carvalho Chehab 			(const struct stv0900_table *)&stv0900_s2_cn);
7569a0bf528SMauro Carvalho Chehab 	snrlcl = (snrlcl + 30) * 384;
7579a0bf528SMauro Carvalho Chehab 	if (snrlcl < 0)
7589a0bf528SMauro Carvalho Chehab 		snrlcl = 0;
7599a0bf528SMauro Carvalho Chehab 
7609a0bf528SMauro Carvalho Chehab 	if (snrlcl > 65535)
7619a0bf528SMauro Carvalho Chehab 		snrlcl = 65535;
7629a0bf528SMauro Carvalho Chehab 
7639a0bf528SMauro Carvalho Chehab 	*snr = snrlcl;
7649a0bf528SMauro Carvalho Chehab 
7659a0bf528SMauro Carvalho Chehab 	return 0;
7669a0bf528SMauro Carvalho Chehab }
7679a0bf528SMauro Carvalho Chehab 
stv0900_get_ber(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)7689a0bf528SMauro Carvalho Chehab static u32 stv0900_get_ber(struct stv0900_internal *intp,
7699a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_demod_num demod)
7709a0bf528SMauro Carvalho Chehab {
7719a0bf528SMauro Carvalho Chehab 	u32 ber = 10000000, i;
7729a0bf528SMauro Carvalho Chehab 	s32 demod_state;
7739a0bf528SMauro Carvalho Chehab 
7749a0bf528SMauro Carvalho Chehab 	demod_state = stv0900_get_bits(intp, HEADER_MODE);
7759a0bf528SMauro Carvalho Chehab 
7769a0bf528SMauro Carvalho Chehab 	switch (demod_state) {
7779a0bf528SMauro Carvalho Chehab 	case STV0900_SEARCH:
7789a0bf528SMauro Carvalho Chehab 	case STV0900_PLH_DETECTED:
7799a0bf528SMauro Carvalho Chehab 	default:
7809a0bf528SMauro Carvalho Chehab 		ber = 10000000;
7819a0bf528SMauro Carvalho Chehab 		break;
7829a0bf528SMauro Carvalho Chehab 	case STV0900_DVBS_FOUND:
7839a0bf528SMauro Carvalho Chehab 		ber = 0;
7849a0bf528SMauro Carvalho Chehab 		for (i = 0; i < 5; i++) {
7859a0bf528SMauro Carvalho Chehab 			msleep(5);
7869a0bf528SMauro Carvalho Chehab 			ber += stv0900_get_err_count(intp, 0, demod);
7879a0bf528SMauro Carvalho Chehab 		}
7889a0bf528SMauro Carvalho Chehab 
7899a0bf528SMauro Carvalho Chehab 		ber /= 5;
7909a0bf528SMauro Carvalho Chehab 		if (stv0900_get_bits(intp, PRFVIT)) {
7919a0bf528SMauro Carvalho Chehab 			ber *= 9766;
7929a0bf528SMauro Carvalho Chehab 			ber = ber >> 13;
7939a0bf528SMauro Carvalho Chehab 		}
7949a0bf528SMauro Carvalho Chehab 
7959a0bf528SMauro Carvalho Chehab 		break;
7969a0bf528SMauro Carvalho Chehab 	case STV0900_DVBS2_FOUND:
7979a0bf528SMauro Carvalho Chehab 		ber = 0;
7989a0bf528SMauro Carvalho Chehab 		for (i = 0; i < 5; i++) {
7999a0bf528SMauro Carvalho Chehab 			msleep(5);
8009a0bf528SMauro Carvalho Chehab 			ber += stv0900_get_err_count(intp, 0, demod);
8019a0bf528SMauro Carvalho Chehab 		}
8029a0bf528SMauro Carvalho Chehab 
8039a0bf528SMauro Carvalho Chehab 		ber /= 5;
8049a0bf528SMauro Carvalho Chehab 		if (stv0900_get_bits(intp, PKTDELIN_LOCK)) {
8059a0bf528SMauro Carvalho Chehab 			ber *= 9766;
8069a0bf528SMauro Carvalho Chehab 			ber = ber >> 13;
8079a0bf528SMauro Carvalho Chehab 		}
8089a0bf528SMauro Carvalho Chehab 
8099a0bf528SMauro Carvalho Chehab 		break;
8109a0bf528SMauro Carvalho Chehab 	}
8119a0bf528SMauro Carvalho Chehab 
8129a0bf528SMauro Carvalho Chehab 	return ber;
8139a0bf528SMauro Carvalho Chehab }
8149a0bf528SMauro Carvalho Chehab 
stv0900_read_ber(struct dvb_frontend * fe,u32 * ber)8159a0bf528SMauro Carvalho Chehab static int stv0900_read_ber(struct dvb_frontend *fe, u32 *ber)
8169a0bf528SMauro Carvalho Chehab {
8179a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
8189a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *internal = state->internal;
8199a0bf528SMauro Carvalho Chehab 
8209a0bf528SMauro Carvalho Chehab 	*ber = stv0900_get_ber(internal, state->demod);
8219a0bf528SMauro Carvalho Chehab 
8229a0bf528SMauro Carvalho Chehab 	return 0;
8239a0bf528SMauro Carvalho Chehab }
8249a0bf528SMauro Carvalho Chehab 
stv0900_get_demod_lock(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod,s32 time_out)8259a0bf528SMauro Carvalho Chehab int stv0900_get_demod_lock(struct stv0900_internal *intp,
8269a0bf528SMauro Carvalho Chehab 			enum fe_stv0900_demod_num demod, s32 time_out)
8279a0bf528SMauro Carvalho Chehab {
8289a0bf528SMauro Carvalho Chehab 	s32 timer = 0,
8299a0bf528SMauro Carvalho Chehab 		lock = 0;
8309a0bf528SMauro Carvalho Chehab 
8319a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_search_state	dmd_state;
8329a0bf528SMauro Carvalho Chehab 
8339a0bf528SMauro Carvalho Chehab 	while ((timer < time_out) && (lock == 0)) {
8349a0bf528SMauro Carvalho Chehab 		dmd_state = stv0900_get_bits(intp, HEADER_MODE);
8359a0bf528SMauro Carvalho Chehab 		dprintk("Demod State = %d\n", dmd_state);
8369a0bf528SMauro Carvalho Chehab 		switch (dmd_state) {
8379a0bf528SMauro Carvalho Chehab 		case STV0900_SEARCH:
8389a0bf528SMauro Carvalho Chehab 		case STV0900_PLH_DETECTED:
8399a0bf528SMauro Carvalho Chehab 		default:
8409a0bf528SMauro Carvalho Chehab 			lock = 0;
8419a0bf528SMauro Carvalho Chehab 			break;
8429a0bf528SMauro Carvalho Chehab 		case STV0900_DVBS2_FOUND:
8439a0bf528SMauro Carvalho Chehab 		case STV0900_DVBS_FOUND:
8449a0bf528SMauro Carvalho Chehab 			lock = stv0900_get_bits(intp, LOCK_DEFINITIF);
8459a0bf528SMauro Carvalho Chehab 			break;
8469a0bf528SMauro Carvalho Chehab 		}
8479a0bf528SMauro Carvalho Chehab 
8489a0bf528SMauro Carvalho Chehab 		if (lock == 0)
8499a0bf528SMauro Carvalho Chehab 			msleep(10);
8509a0bf528SMauro Carvalho Chehab 
8519a0bf528SMauro Carvalho Chehab 		timer += 10;
8529a0bf528SMauro Carvalho Chehab 	}
8539a0bf528SMauro Carvalho Chehab 
8549a0bf528SMauro Carvalho Chehab 	if (lock)
8559a0bf528SMauro Carvalho Chehab 		dprintk("DEMOD LOCK OK\n");
8569a0bf528SMauro Carvalho Chehab 	else
8579a0bf528SMauro Carvalho Chehab 		dprintk("DEMOD LOCK FAIL\n");
8589a0bf528SMauro Carvalho Chehab 
8599a0bf528SMauro Carvalho Chehab 	return lock;
8609a0bf528SMauro Carvalho Chehab }
8619a0bf528SMauro Carvalho Chehab 
stv0900_stop_all_s2_modcod(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)8629a0bf528SMauro Carvalho Chehab void stv0900_stop_all_s2_modcod(struct stv0900_internal *intp,
8639a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_demod_num demod)
8649a0bf528SMauro Carvalho Chehab {
8659a0bf528SMauro Carvalho Chehab 	s32 regflist,
8669a0bf528SMauro Carvalho Chehab 	i;
8679a0bf528SMauro Carvalho Chehab 
8689a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
8699a0bf528SMauro Carvalho Chehab 
8709a0bf528SMauro Carvalho Chehab 	regflist = MODCODLST0;
8719a0bf528SMauro Carvalho Chehab 
8729a0bf528SMauro Carvalho Chehab 	for (i = 0; i < 16; i++)
8739a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, regflist + i, 0xff);
8749a0bf528SMauro Carvalho Chehab }
8759a0bf528SMauro Carvalho Chehab 
stv0900_activate_s2_modcod(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)8769a0bf528SMauro Carvalho Chehab void stv0900_activate_s2_modcod(struct stv0900_internal *intp,
8779a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_demod_num demod)
8789a0bf528SMauro Carvalho Chehab {
8799a0bf528SMauro Carvalho Chehab 	u32 matype,
8809a0bf528SMauro Carvalho Chehab 		mod_code,
8819a0bf528SMauro Carvalho Chehab 		fmod,
8829a0bf528SMauro Carvalho Chehab 		reg_index,
8839a0bf528SMauro Carvalho Chehab 		field_index;
8849a0bf528SMauro Carvalho Chehab 
8859a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
8869a0bf528SMauro Carvalho Chehab 
8879a0bf528SMauro Carvalho Chehab 	if (intp->chip_id <= 0x11) {
8889a0bf528SMauro Carvalho Chehab 		msleep(5);
8899a0bf528SMauro Carvalho Chehab 
8909a0bf528SMauro Carvalho Chehab 		mod_code = stv0900_read_reg(intp, PLHMODCOD);
8919a0bf528SMauro Carvalho Chehab 		matype = mod_code & 0x3;
8929a0bf528SMauro Carvalho Chehab 		mod_code = (mod_code & 0x7f) >> 2;
8939a0bf528SMauro Carvalho Chehab 
8949a0bf528SMauro Carvalho Chehab 		reg_index = MODCODLSTF - mod_code / 2;
8959a0bf528SMauro Carvalho Chehab 		field_index = mod_code % 2;
8969a0bf528SMauro Carvalho Chehab 
8979a0bf528SMauro Carvalho Chehab 		switch (matype) {
8989a0bf528SMauro Carvalho Chehab 		case 0:
8999a0bf528SMauro Carvalho Chehab 		default:
9009a0bf528SMauro Carvalho Chehab 			fmod = 14;
9019a0bf528SMauro Carvalho Chehab 			break;
9029a0bf528SMauro Carvalho Chehab 		case 1:
9039a0bf528SMauro Carvalho Chehab 			fmod = 13;
9049a0bf528SMauro Carvalho Chehab 			break;
9059a0bf528SMauro Carvalho Chehab 		case 2:
9069a0bf528SMauro Carvalho Chehab 			fmod = 11;
9079a0bf528SMauro Carvalho Chehab 			break;
9089a0bf528SMauro Carvalho Chehab 		case 3:
9099a0bf528SMauro Carvalho Chehab 			fmod = 7;
9109a0bf528SMauro Carvalho Chehab 			break;
9119a0bf528SMauro Carvalho Chehab 		}
9129a0bf528SMauro Carvalho Chehab 
9139a0bf528SMauro Carvalho Chehab 		if ((INRANGE(STV0900_QPSK_12, mod_code, STV0900_8PSK_910))
9149a0bf528SMauro Carvalho Chehab 						&& (matype <= 1)) {
9159a0bf528SMauro Carvalho Chehab 			if (field_index == 0)
9169a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, reg_index,
9179a0bf528SMauro Carvalho Chehab 							0xf0 | fmod);
9189a0bf528SMauro Carvalho Chehab 			else
9199a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, reg_index,
9209a0bf528SMauro Carvalho Chehab 							(fmod << 4) | 0xf);
9219a0bf528SMauro Carvalho Chehab 		}
9229a0bf528SMauro Carvalho Chehab 
9239a0bf528SMauro Carvalho Chehab 	} else if (intp->chip_id >= 0x12) {
9249a0bf528SMauro Carvalho Chehab 		for (reg_index = 0; reg_index < 7; reg_index++)
9259a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, MODCODLST0 + reg_index, 0xff);
9269a0bf528SMauro Carvalho Chehab 
9279a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, MODCODLSTE, 0xff);
9289a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, MODCODLSTF, 0xcf);
9299a0bf528SMauro Carvalho Chehab 		for (reg_index = 0; reg_index < 8; reg_index++)
9309a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, MODCODLST7 + reg_index, 0xcc);
9319a0bf528SMauro Carvalho Chehab 
9329a0bf528SMauro Carvalho Chehab 
9339a0bf528SMauro Carvalho Chehab 	}
9349a0bf528SMauro Carvalho Chehab }
9359a0bf528SMauro Carvalho Chehab 
stv0900_activate_s2_modcod_single(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)9369a0bf528SMauro Carvalho Chehab void stv0900_activate_s2_modcod_single(struct stv0900_internal *intp,
9379a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_demod_num demod)
9389a0bf528SMauro Carvalho Chehab {
9399a0bf528SMauro Carvalho Chehab 	u32 reg_index;
9409a0bf528SMauro Carvalho Chehab 
9419a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
9429a0bf528SMauro Carvalho Chehab 
9439a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, MODCODLST0, 0xff);
9449a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, MODCODLST1, 0xf0);
9459a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, MODCODLSTF, 0x0f);
9469a0bf528SMauro Carvalho Chehab 	for (reg_index = 0; reg_index < 13; reg_index++)
9479a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, MODCODLST2 + reg_index, 0);
9489a0bf528SMauro Carvalho Chehab 
9499a0bf528SMauro Carvalho Chehab }
9509a0bf528SMauro Carvalho Chehab 
stv0900_frontend_algo(struct dvb_frontend * fe)9519a0bf528SMauro Carvalho Chehab static enum dvbfe_algo stv0900_frontend_algo(struct dvb_frontend *fe)
9529a0bf528SMauro Carvalho Chehab {
9539a0bf528SMauro Carvalho Chehab 	return DVBFE_ALGO_CUSTOM;
9549a0bf528SMauro Carvalho Chehab }
9559a0bf528SMauro Carvalho Chehab 
stv0900_start_search(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)9569a0bf528SMauro Carvalho Chehab void stv0900_start_search(struct stv0900_internal *intp,
9579a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_demod_num demod)
9589a0bf528SMauro Carvalho Chehab {
9599a0bf528SMauro Carvalho Chehab 	u32 freq;
9609a0bf528SMauro Carvalho Chehab 	s16 freq_s16 ;
9619a0bf528SMauro Carvalho Chehab 
9629a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DEMOD_MODE, 0x1f);
9639a0bf528SMauro Carvalho Chehab 	if (intp->chip_id == 0x10)
9649a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, CORRELEXP, 0xaa);
9659a0bf528SMauro Carvalho Chehab 
9669a0bf528SMauro Carvalho Chehab 	if (intp->chip_id < 0x20)
9679a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, CARHDR, 0x55);
9689a0bf528SMauro Carvalho Chehab 
9699a0bf528SMauro Carvalho Chehab 	if (intp->chip_id <= 0x20) {
9709a0bf528SMauro Carvalho Chehab 		if (intp->symbol_rate[0] <= 5000000) {
9719a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARCFG, 0x44);
9729a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CFRUP1, 0x0f);
9739a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CFRUP0, 0xff);
9749a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CFRLOW1, 0xf0);
9759a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CFRLOW0, 0x00);
9769a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, RTCS2, 0x68);
9779a0bf528SMauro Carvalho Chehab 		} else {
9789a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARCFG, 0xc4);
9799a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, RTCS2, 0x44);
9809a0bf528SMauro Carvalho Chehab 		}
9819a0bf528SMauro Carvalho Chehab 
9829a0bf528SMauro Carvalho Chehab 	} else { /*cut 3.0 above*/
9839a0bf528SMauro Carvalho Chehab 		if (intp->symbol_rate[demod] <= 5000000)
9849a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, RTCS2, 0x68);
9859a0bf528SMauro Carvalho Chehab 		else
9869a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, RTCS2, 0x44);
9879a0bf528SMauro Carvalho Chehab 
9889a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, CARCFG, 0x46);
9899a0bf528SMauro Carvalho Chehab 		if (intp->srch_algo[demod] == STV0900_WARM_START) {
9909a0bf528SMauro Carvalho Chehab 			freq = 1000 << 16;
9919a0bf528SMauro Carvalho Chehab 			freq /= (intp->mclk / 1000);
9929a0bf528SMauro Carvalho Chehab 			freq_s16 = (s16)freq;
9939a0bf528SMauro Carvalho Chehab 		} else {
9949a0bf528SMauro Carvalho Chehab 			freq = (intp->srch_range[demod] / 2000);
9959a0bf528SMauro Carvalho Chehab 			if (intp->symbol_rate[demod] <= 5000000)
9969a0bf528SMauro Carvalho Chehab 				freq += 80;
9979a0bf528SMauro Carvalho Chehab 			else
9989a0bf528SMauro Carvalho Chehab 				freq += 600;
9999a0bf528SMauro Carvalho Chehab 
10009a0bf528SMauro Carvalho Chehab 			freq = freq << 16;
10019a0bf528SMauro Carvalho Chehab 			freq /= (intp->mclk / 1000);
10029a0bf528SMauro Carvalho Chehab 			freq_s16 = (s16)freq;
10039a0bf528SMauro Carvalho Chehab 		}
10049a0bf528SMauro Carvalho Chehab 
10059a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, CFR_UP1, MSB(freq_s16));
10069a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, CFR_UP0, LSB(freq_s16));
10079a0bf528SMauro Carvalho Chehab 		freq_s16 *= (-1);
10089a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, CFR_LOW1, MSB(freq_s16));
10099a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, CFR_LOW0, LSB(freq_s16));
10109a0bf528SMauro Carvalho Chehab 	}
10119a0bf528SMauro Carvalho Chehab 
10129a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, CFRINIT1, 0);
10139a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, CFRINIT0, 0);
10149a0bf528SMauro Carvalho Chehab 
10159a0bf528SMauro Carvalho Chehab 	if (intp->chip_id >= 0x20) {
10169a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, EQUALCFG, 0x41);
10179a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, FFECFG, 0x41);
10189a0bf528SMauro Carvalho Chehab 
10199a0bf528SMauro Carvalho Chehab 		if ((intp->srch_standard[demod] == STV0900_SEARCH_DVBS1) ||
10209a0bf528SMauro Carvalho Chehab 			(intp->srch_standard[demod] == STV0900_SEARCH_DSS) ||
10219a0bf528SMauro Carvalho Chehab 			(intp->srch_standard[demod] == STV0900_AUTO_SEARCH)) {
10229a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, VITSCALE,
10239a0bf528SMauro Carvalho Chehab 								0x82);
10249a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, VAVSRVIT, 0x0);
10259a0bf528SMauro Carvalho Chehab 		}
10269a0bf528SMauro Carvalho Chehab 	}
10279a0bf528SMauro Carvalho Chehab 
10289a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, SFRSTEP, 0x00);
10299a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, TMGTHRISE, 0xe0);
10309a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, TMGTHFALL, 0xc0);
10319a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, SCAN_ENABLE, 0);
10329a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, CFR_AUTOSCAN, 0);
10339a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, S1S2_SEQUENTIAL, 0);
10349a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, RTC, 0x88);
10359a0bf528SMauro Carvalho Chehab 	if (intp->chip_id >= 0x20) {
10369a0bf528SMauro Carvalho Chehab 		if (intp->symbol_rate[demod] < 2000000) {
10379a0bf528SMauro Carvalho Chehab 			if (intp->chip_id <= 0x20)
10389a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, CARFREQ, 0x39);
10399a0bf528SMauro Carvalho Chehab 			else  /*cut 3.0*/
10409a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp, CARFREQ, 0x89);
10419a0bf528SMauro Carvalho Chehab 
10429a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARHDR, 0x40);
10439a0bf528SMauro Carvalho Chehab 		} else if (intp->symbol_rate[demod] < 10000000) {
10449a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARFREQ, 0x4c);
10459a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARHDR, 0x20);
10469a0bf528SMauro Carvalho Chehab 		} else {
10479a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARFREQ, 0x4b);
10489a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARHDR, 0x20);
10499a0bf528SMauro Carvalho Chehab 		}
10509a0bf528SMauro Carvalho Chehab 
10519a0bf528SMauro Carvalho Chehab 	} else {
10529a0bf528SMauro Carvalho Chehab 		if (intp->symbol_rate[demod] < 10000000)
10539a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARFREQ, 0xef);
10549a0bf528SMauro Carvalho Chehab 		else
10559a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, CARFREQ, 0xed);
10569a0bf528SMauro Carvalho Chehab 	}
10579a0bf528SMauro Carvalho Chehab 
10589a0bf528SMauro Carvalho Chehab 	switch (intp->srch_algo[demod]) {
10599a0bf528SMauro Carvalho Chehab 	case STV0900_WARM_START:
10609a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, DMDISTATE, 0x1f);
10619a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, DMDISTATE, 0x18);
10629a0bf528SMauro Carvalho Chehab 		break;
10639a0bf528SMauro Carvalho Chehab 	case STV0900_COLD_START:
10649a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, DMDISTATE, 0x1f);
10659a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, DMDISTATE, 0x15);
10669a0bf528SMauro Carvalho Chehab 		break;
10679a0bf528SMauro Carvalho Chehab 	default:
10689a0bf528SMauro Carvalho Chehab 		break;
10699a0bf528SMauro Carvalho Chehab 	}
10709a0bf528SMauro Carvalho Chehab }
10719a0bf528SMauro Carvalho Chehab 
stv0900_get_optim_carr_loop(s32 srate,enum fe_stv0900_modcode modcode,s32 pilot,u8 chip_id)10729a0bf528SMauro Carvalho Chehab u8 stv0900_get_optim_carr_loop(s32 srate, enum fe_stv0900_modcode modcode,
10739a0bf528SMauro Carvalho Chehab 							s32 pilot, u8 chip_id)
10749a0bf528SMauro Carvalho Chehab {
10759a0bf528SMauro Carvalho Chehab 	u8 aclc_value = 0x29;
1076d079e36dSMauro Carvalho Chehab 	s32 i, cllas2_size;
10779a0bf528SMauro Carvalho Chehab 	const struct stv0900_car_loop_optim *cls2, *cllqs2, *cllas2;
10789a0bf528SMauro Carvalho Chehab 
10799a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
10809a0bf528SMauro Carvalho Chehab 
10819a0bf528SMauro Carvalho Chehab 	if (chip_id <= 0x12) {
10829a0bf528SMauro Carvalho Chehab 		cls2 = FE_STV0900_S2CarLoop;
10839a0bf528SMauro Carvalho Chehab 		cllqs2 = FE_STV0900_S2LowQPCarLoopCut30;
10849a0bf528SMauro Carvalho Chehab 		cllas2 = FE_STV0900_S2APSKCarLoopCut30;
1085d079e36dSMauro Carvalho Chehab 		cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut30);
10869a0bf528SMauro Carvalho Chehab 	} else if (chip_id == 0x20) {
10879a0bf528SMauro Carvalho Chehab 		cls2 = FE_STV0900_S2CarLoopCut20;
10889a0bf528SMauro Carvalho Chehab 		cllqs2 = FE_STV0900_S2LowQPCarLoopCut20;
10899a0bf528SMauro Carvalho Chehab 		cllas2 = FE_STV0900_S2APSKCarLoopCut20;
1090d079e36dSMauro Carvalho Chehab 		cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut20);
10919a0bf528SMauro Carvalho Chehab 	} else {
10929a0bf528SMauro Carvalho Chehab 		cls2 = FE_STV0900_S2CarLoopCut30;
10939a0bf528SMauro Carvalho Chehab 		cllqs2 = FE_STV0900_S2LowQPCarLoopCut30;
10949a0bf528SMauro Carvalho Chehab 		cllas2 = FE_STV0900_S2APSKCarLoopCut30;
1095d079e36dSMauro Carvalho Chehab 		cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut30);
10969a0bf528SMauro Carvalho Chehab 	}
10979a0bf528SMauro Carvalho Chehab 
10989a0bf528SMauro Carvalho Chehab 	if (modcode < STV0900_QPSK_12) {
10999a0bf528SMauro Carvalho Chehab 		i = 0;
11009a0bf528SMauro Carvalho Chehab 		while ((i < 3) && (modcode != cllqs2[i].modcode))
11019a0bf528SMauro Carvalho Chehab 			i++;
11029a0bf528SMauro Carvalho Chehab 
11039a0bf528SMauro Carvalho Chehab 		if (i >= 3)
11049a0bf528SMauro Carvalho Chehab 			i = 2;
11059a0bf528SMauro Carvalho Chehab 	} else {
11069a0bf528SMauro Carvalho Chehab 		i = 0;
11079a0bf528SMauro Carvalho Chehab 		while ((i < 14) && (modcode != cls2[i].modcode))
11089a0bf528SMauro Carvalho Chehab 			i++;
11099a0bf528SMauro Carvalho Chehab 
11109a0bf528SMauro Carvalho Chehab 		if (i >= 14) {
11119a0bf528SMauro Carvalho Chehab 			i = 0;
11129a0bf528SMauro Carvalho Chehab 			while ((i < 11) && (modcode != cllas2[i].modcode))
11139a0bf528SMauro Carvalho Chehab 				i++;
11149a0bf528SMauro Carvalho Chehab 
11159a0bf528SMauro Carvalho Chehab 			if (i >= 11)
11169a0bf528SMauro Carvalho Chehab 				i = 10;
11179a0bf528SMauro Carvalho Chehab 		}
11189a0bf528SMauro Carvalho Chehab 	}
11199a0bf528SMauro Carvalho Chehab 
11209a0bf528SMauro Carvalho Chehab 	if (modcode <= STV0900_QPSK_25) {
11219a0bf528SMauro Carvalho Chehab 		if (pilot) {
11229a0bf528SMauro Carvalho Chehab 			if (srate <= 3000000)
11239a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_on_2;
11249a0bf528SMauro Carvalho Chehab 			else if (srate <= 7000000)
11259a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_on_5;
11269a0bf528SMauro Carvalho Chehab 			else if (srate <= 15000000)
11279a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_on_10;
11289a0bf528SMauro Carvalho Chehab 			else if (srate <= 25000000)
11299a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_on_20;
11309a0bf528SMauro Carvalho Chehab 			else
11319a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_on_30;
11329a0bf528SMauro Carvalho Chehab 		} else {
11339a0bf528SMauro Carvalho Chehab 			if (srate <= 3000000)
11349a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_off_2;
11359a0bf528SMauro Carvalho Chehab 			else if (srate <= 7000000)
11369a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_off_5;
11379a0bf528SMauro Carvalho Chehab 			else if (srate <= 15000000)
11389a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_off_10;
11399a0bf528SMauro Carvalho Chehab 			else if (srate <= 25000000)
11409a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_off_20;
11419a0bf528SMauro Carvalho Chehab 			else
11429a0bf528SMauro Carvalho Chehab 				aclc_value = cllqs2[i].car_loop_pilots_off_30;
11439a0bf528SMauro Carvalho Chehab 		}
11449a0bf528SMauro Carvalho Chehab 
11459a0bf528SMauro Carvalho Chehab 	} else if (modcode <= STV0900_8PSK_910) {
11469a0bf528SMauro Carvalho Chehab 		if (pilot) {
11479a0bf528SMauro Carvalho Chehab 			if (srate <= 3000000)
11489a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_on_2;
11499a0bf528SMauro Carvalho Chehab 			else if (srate <= 7000000)
11509a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_on_5;
11519a0bf528SMauro Carvalho Chehab 			else if (srate <= 15000000)
11529a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_on_10;
11539a0bf528SMauro Carvalho Chehab 			else if (srate <= 25000000)
11549a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_on_20;
11559a0bf528SMauro Carvalho Chehab 			else
11569a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_on_30;
11579a0bf528SMauro Carvalho Chehab 		} else {
11589a0bf528SMauro Carvalho Chehab 			if (srate <= 3000000)
11599a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_off_2;
11609a0bf528SMauro Carvalho Chehab 			else if (srate <= 7000000)
11619a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_off_5;
11629a0bf528SMauro Carvalho Chehab 			else if (srate <= 15000000)
11639a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_off_10;
11649a0bf528SMauro Carvalho Chehab 			else if (srate <= 25000000)
11659a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_off_20;
11669a0bf528SMauro Carvalho Chehab 			else
11679a0bf528SMauro Carvalho Chehab 				aclc_value = cls2[i].car_loop_pilots_off_30;
11689a0bf528SMauro Carvalho Chehab 		}
11699a0bf528SMauro Carvalho Chehab 
1170d079e36dSMauro Carvalho Chehab 	} else if (i < cllas2_size) {
11719a0bf528SMauro Carvalho Chehab 		if (srate <= 3000000)
11729a0bf528SMauro Carvalho Chehab 			aclc_value = cllas2[i].car_loop_pilots_on_2;
11739a0bf528SMauro Carvalho Chehab 		else if (srate <= 7000000)
11749a0bf528SMauro Carvalho Chehab 			aclc_value = cllas2[i].car_loop_pilots_on_5;
11759a0bf528SMauro Carvalho Chehab 		else if (srate <= 15000000)
11769a0bf528SMauro Carvalho Chehab 			aclc_value = cllas2[i].car_loop_pilots_on_10;
11779a0bf528SMauro Carvalho Chehab 		else if (srate <= 25000000)
11789a0bf528SMauro Carvalho Chehab 			aclc_value = cllas2[i].car_loop_pilots_on_20;
11799a0bf528SMauro Carvalho Chehab 		else
11809a0bf528SMauro Carvalho Chehab 			aclc_value = cllas2[i].car_loop_pilots_on_30;
11819a0bf528SMauro Carvalho Chehab 	}
11829a0bf528SMauro Carvalho Chehab 
11839a0bf528SMauro Carvalho Chehab 	return aclc_value;
11849a0bf528SMauro Carvalho Chehab }
11859a0bf528SMauro Carvalho Chehab 
stv0900_get_optim_short_carr_loop(s32 srate,enum fe_stv0900_modulation modulation,u8 chip_id)11869a0bf528SMauro Carvalho Chehab u8 stv0900_get_optim_short_carr_loop(s32 srate,
11879a0bf528SMauro Carvalho Chehab 				enum fe_stv0900_modulation modulation,
11889a0bf528SMauro Carvalho Chehab 				u8 chip_id)
11899a0bf528SMauro Carvalho Chehab {
11909a0bf528SMauro Carvalho Chehab 	const struct stv0900_short_frames_car_loop_optim *s2scl;
11919a0bf528SMauro Carvalho Chehab 	const struct stv0900_short_frames_car_loop_optim_vs_mod *s2sclc30;
11929a0bf528SMauro Carvalho Chehab 	s32 mod_index = 0;
11939a0bf528SMauro Carvalho Chehab 	u8 aclc_value = 0x0b;
11949a0bf528SMauro Carvalho Chehab 
11959a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
11969a0bf528SMauro Carvalho Chehab 
11979a0bf528SMauro Carvalho Chehab 	s2scl = FE_STV0900_S2ShortCarLoop;
11989a0bf528SMauro Carvalho Chehab 	s2sclc30 = FE_STV0900_S2ShortCarLoopCut30;
11999a0bf528SMauro Carvalho Chehab 
12009a0bf528SMauro Carvalho Chehab 	switch (modulation) {
12019a0bf528SMauro Carvalho Chehab 	case STV0900_QPSK:
12029a0bf528SMauro Carvalho Chehab 	default:
12039a0bf528SMauro Carvalho Chehab 		mod_index = 0;
12049a0bf528SMauro Carvalho Chehab 		break;
12059a0bf528SMauro Carvalho Chehab 	case STV0900_8PSK:
12069a0bf528SMauro Carvalho Chehab 		mod_index = 1;
12079a0bf528SMauro Carvalho Chehab 		break;
12089a0bf528SMauro Carvalho Chehab 	case STV0900_16APSK:
12099a0bf528SMauro Carvalho Chehab 		mod_index = 2;
12109a0bf528SMauro Carvalho Chehab 		break;
12119a0bf528SMauro Carvalho Chehab 	case STV0900_32APSK:
12129a0bf528SMauro Carvalho Chehab 		mod_index = 3;
12139a0bf528SMauro Carvalho Chehab 		break;
12149a0bf528SMauro Carvalho Chehab 	}
12159a0bf528SMauro Carvalho Chehab 
12169a0bf528SMauro Carvalho Chehab 	if (chip_id >= 0x30) {
12179a0bf528SMauro Carvalho Chehab 		if (srate <= 3000000)
12189a0bf528SMauro Carvalho Chehab 			aclc_value = s2sclc30[mod_index].car_loop_2;
12199a0bf528SMauro Carvalho Chehab 		else if (srate <= 7000000)
12209a0bf528SMauro Carvalho Chehab 			aclc_value = s2sclc30[mod_index].car_loop_5;
12219a0bf528SMauro Carvalho Chehab 		else if (srate <= 15000000)
12229a0bf528SMauro Carvalho Chehab 			aclc_value = s2sclc30[mod_index].car_loop_10;
12239a0bf528SMauro Carvalho Chehab 		else if (srate <= 25000000)
12249a0bf528SMauro Carvalho Chehab 			aclc_value = s2sclc30[mod_index].car_loop_20;
12259a0bf528SMauro Carvalho Chehab 		else
12269a0bf528SMauro Carvalho Chehab 			aclc_value = s2sclc30[mod_index].car_loop_30;
12279a0bf528SMauro Carvalho Chehab 
12289a0bf528SMauro Carvalho Chehab 	} else if (chip_id >= 0x20) {
12299a0bf528SMauro Carvalho Chehab 		if (srate <= 3000000)
12309a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut20_2;
12319a0bf528SMauro Carvalho Chehab 		else if (srate <= 7000000)
12329a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut20_5;
12339a0bf528SMauro Carvalho Chehab 		else if (srate <= 15000000)
12349a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut20_10;
12359a0bf528SMauro Carvalho Chehab 		else if (srate <= 25000000)
12369a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut20_20;
12379a0bf528SMauro Carvalho Chehab 		else
12389a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut20_30;
12399a0bf528SMauro Carvalho Chehab 
12409a0bf528SMauro Carvalho Chehab 	} else {
12419a0bf528SMauro Carvalho Chehab 		if (srate <= 3000000)
12429a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut12_2;
12439a0bf528SMauro Carvalho Chehab 		else if (srate <= 7000000)
12449a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut12_5;
12459a0bf528SMauro Carvalho Chehab 		else if (srate <= 15000000)
12469a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut12_10;
12479a0bf528SMauro Carvalho Chehab 		else if (srate <= 25000000)
12489a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut12_20;
12499a0bf528SMauro Carvalho Chehab 		else
12509a0bf528SMauro Carvalho Chehab 			aclc_value = s2scl[mod_index].car_loop_cut12_30;
12519a0bf528SMauro Carvalho Chehab 
12529a0bf528SMauro Carvalho Chehab 	}
12539a0bf528SMauro Carvalho Chehab 
12549a0bf528SMauro Carvalho Chehab 	return aclc_value;
12559a0bf528SMauro Carvalho Chehab }
12569a0bf528SMauro Carvalho Chehab 
12579a0bf528SMauro Carvalho Chehab static
stv0900_st_dvbs2_single(struct stv0900_internal * intp,enum fe_stv0900_demod_mode LDPC_Mode,enum fe_stv0900_demod_num demod)12589a0bf528SMauro Carvalho Chehab enum fe_stv0900_error stv0900_st_dvbs2_single(struct stv0900_internal *intp,
12599a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_demod_mode LDPC_Mode,
12609a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_demod_num demod)
12619a0bf528SMauro Carvalho Chehab {
12629a0bf528SMauro Carvalho Chehab 	s32 reg_ind;
12639a0bf528SMauro Carvalho Chehab 
12649a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
12659a0bf528SMauro Carvalho Chehab 
12669a0bf528SMauro Carvalho Chehab 	switch (LDPC_Mode) {
12679a0bf528SMauro Carvalho Chehab 	case STV0900_DUAL:
12689a0bf528SMauro Carvalho Chehab 	default:
12699a0bf528SMauro Carvalho Chehab 		if ((intp->demod_mode != STV0900_DUAL)
12709a0bf528SMauro Carvalho Chehab 			|| (stv0900_get_bits(intp, F0900_DDEMOD) != 1)) {
12719a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_GENCFG, 0x1d);
12729a0bf528SMauro Carvalho Chehab 
12739a0bf528SMauro Carvalho Chehab 			intp->demod_mode = STV0900_DUAL;
12749a0bf528SMauro Carvalho Chehab 
12759a0bf528SMauro Carvalho Chehab 			stv0900_write_bits(intp, F0900_FRESFEC, 1);
12769a0bf528SMauro Carvalho Chehab 			stv0900_write_bits(intp, F0900_FRESFEC, 0);
12779a0bf528SMauro Carvalho Chehab 
12789a0bf528SMauro Carvalho Chehab 			for (reg_ind = 0; reg_ind < 7; reg_ind++)
12799a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
12809a0bf528SMauro Carvalho Chehab 						R0900_P1_MODCODLST0 + reg_ind,
12819a0bf528SMauro Carvalho Chehab 						0xff);
12829a0bf528SMauro Carvalho Chehab 			for (reg_ind = 0; reg_ind < 8; reg_ind++)
12839a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
12849a0bf528SMauro Carvalho Chehab 						R0900_P1_MODCODLST7 + reg_ind,
12859a0bf528SMauro Carvalho Chehab 						0xcc);
12869a0bf528SMauro Carvalho Chehab 
12879a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_P1_MODCODLSTE, 0xff);
12889a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_P1_MODCODLSTF, 0xcf);
12899a0bf528SMauro Carvalho Chehab 
12909a0bf528SMauro Carvalho Chehab 			for (reg_ind = 0; reg_ind < 7; reg_ind++)
12919a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
12929a0bf528SMauro Carvalho Chehab 						R0900_P2_MODCODLST0 + reg_ind,
12939a0bf528SMauro Carvalho Chehab 						0xff);
12949a0bf528SMauro Carvalho Chehab 			for (reg_ind = 0; reg_ind < 8; reg_ind++)
12959a0bf528SMauro Carvalho Chehab 				stv0900_write_reg(intp,
12969a0bf528SMauro Carvalho Chehab 						R0900_P2_MODCODLST7 + reg_ind,
12979a0bf528SMauro Carvalho Chehab 						0xcc);
12989a0bf528SMauro Carvalho Chehab 
12999a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_P2_MODCODLSTE, 0xff);
13009a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_P2_MODCODLSTF, 0xcf);
13019a0bf528SMauro Carvalho Chehab 		}
13029a0bf528SMauro Carvalho Chehab 
13039a0bf528SMauro Carvalho Chehab 		break;
13049a0bf528SMauro Carvalho Chehab 	case STV0900_SINGLE:
13059a0bf528SMauro Carvalho Chehab 		if (demod == STV0900_DEMOD_2) {
13069a0bf528SMauro Carvalho Chehab 			stv0900_stop_all_s2_modcod(intp, STV0900_DEMOD_1);
13079a0bf528SMauro Carvalho Chehab 			stv0900_activate_s2_modcod_single(intp,
13089a0bf528SMauro Carvalho Chehab 							STV0900_DEMOD_2);
13099a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_GENCFG, 0x06);
13109a0bf528SMauro Carvalho Chehab 		} else {
13119a0bf528SMauro Carvalho Chehab 			stv0900_stop_all_s2_modcod(intp, STV0900_DEMOD_2);
13129a0bf528SMauro Carvalho Chehab 			stv0900_activate_s2_modcod_single(intp,
13139a0bf528SMauro Carvalho Chehab 							STV0900_DEMOD_1);
13149a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp, R0900_GENCFG, 0x04);
13159a0bf528SMauro Carvalho Chehab 		}
13169a0bf528SMauro Carvalho Chehab 
13179a0bf528SMauro Carvalho Chehab 		intp->demod_mode = STV0900_SINGLE;
13189a0bf528SMauro Carvalho Chehab 
13199a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_FRESFEC, 1);
13209a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_FRESFEC, 0);
13219a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_ALGOSWRST, 1);
13229a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_ALGOSWRST, 0);
13239a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_ALGOSWRST, 1);
13249a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_ALGOSWRST, 0);
13259a0bf528SMauro Carvalho Chehab 		break;
13269a0bf528SMauro Carvalho Chehab 	}
13279a0bf528SMauro Carvalho Chehab 
132849bc8962SMauro Carvalho Chehab 	return STV0900_NO_ERROR;
13299a0bf528SMauro Carvalho Chehab }
13309a0bf528SMauro Carvalho Chehab 
stv0900_init_internal(struct dvb_frontend * fe,struct stv0900_init_params * p_init)13319a0bf528SMauro Carvalho Chehab static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
13329a0bf528SMauro Carvalho Chehab 					struct stv0900_init_params *p_init)
13339a0bf528SMauro Carvalho Chehab {
13349a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
13359a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_error error = STV0900_NO_ERROR;
13369a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_error demodError = STV0900_NO_ERROR;
13379a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = NULL;
13389a0bf528SMauro Carvalho Chehab 	int selosci, i;
13399a0bf528SMauro Carvalho Chehab 
13409a0bf528SMauro Carvalho Chehab 	struct stv0900_inode *temp_int = find_inode(state->i2c_adap,
13419a0bf528SMauro Carvalho Chehab 						state->config->demod_address);
13429a0bf528SMauro Carvalho Chehab 
13439a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
13449a0bf528SMauro Carvalho Chehab 
13459a0bf528SMauro Carvalho Chehab 	if ((temp_int != NULL) && (p_init->demod_mode == STV0900_DUAL)) {
13469a0bf528SMauro Carvalho Chehab 		state->internal = temp_int->internal;
13479a0bf528SMauro Carvalho Chehab 		(state->internal->dmds_used)++;
13489a0bf528SMauro Carvalho Chehab 		dprintk("%s: Find Internal Structure!\n", __func__);
13499a0bf528SMauro Carvalho Chehab 		return STV0900_NO_ERROR;
13509a0bf528SMauro Carvalho Chehab 	} else {
13519a0bf528SMauro Carvalho Chehab 		state->internal = kmalloc(sizeof(struct stv0900_internal),
13529a0bf528SMauro Carvalho Chehab 								GFP_KERNEL);
13539a0bf528SMauro Carvalho Chehab 		if (state->internal == NULL)
13549a0bf528SMauro Carvalho Chehab 			return STV0900_INVALID_HANDLE;
13559a0bf528SMauro Carvalho Chehab 		temp_int = append_internal(state->internal);
13569a0bf528SMauro Carvalho Chehab 		if (temp_int == NULL) {
13579a0bf528SMauro Carvalho Chehab 			kfree(state->internal);
13589a0bf528SMauro Carvalho Chehab 			state->internal = NULL;
13599a0bf528SMauro Carvalho Chehab 			return STV0900_INVALID_HANDLE;
13609a0bf528SMauro Carvalho Chehab 		}
13619a0bf528SMauro Carvalho Chehab 		state->internal->dmds_used = 1;
13629a0bf528SMauro Carvalho Chehab 		state->internal->i2c_adap = state->i2c_adap;
13639a0bf528SMauro Carvalho Chehab 		state->internal->i2c_addr = state->config->demod_address;
13649a0bf528SMauro Carvalho Chehab 		state->internal->clkmode = state->config->clkmode;
13659a0bf528SMauro Carvalho Chehab 		state->internal->errs = STV0900_NO_ERROR;
13669a0bf528SMauro Carvalho Chehab 		dprintk("%s: Create New Internal Structure!\n", __func__);
13679a0bf528SMauro Carvalho Chehab 	}
13689a0bf528SMauro Carvalho Chehab 
13699a0bf528SMauro Carvalho Chehab 	if (state->internal == NULL) {
13709a0bf528SMauro Carvalho Chehab 		error = STV0900_INVALID_HANDLE;
13719a0bf528SMauro Carvalho Chehab 		return error;
13729a0bf528SMauro Carvalho Chehab 	}
13739a0bf528SMauro Carvalho Chehab 
13749a0bf528SMauro Carvalho Chehab 	demodError = stv0900_initialize(state->internal);
13759a0bf528SMauro Carvalho Chehab 	if (demodError == STV0900_NO_ERROR) {
13769a0bf528SMauro Carvalho Chehab 			error = STV0900_NO_ERROR;
13779a0bf528SMauro Carvalho Chehab 	} else {
13789a0bf528SMauro Carvalho Chehab 		if (demodError == STV0900_INVALID_HANDLE)
13799a0bf528SMauro Carvalho Chehab 			error = STV0900_INVALID_HANDLE;
13809a0bf528SMauro Carvalho Chehab 		else
13819a0bf528SMauro Carvalho Chehab 			error = STV0900_I2C_ERROR;
13829a0bf528SMauro Carvalho Chehab 
13839a0bf528SMauro Carvalho Chehab 		return error;
13849a0bf528SMauro Carvalho Chehab 	}
13859a0bf528SMauro Carvalho Chehab 
13869a0bf528SMauro Carvalho Chehab 	intp = state->internal;
13879a0bf528SMauro Carvalho Chehab 
13889a0bf528SMauro Carvalho Chehab 	intp->demod_mode = p_init->demod_mode;
13899a0bf528SMauro Carvalho Chehab 	stv0900_st_dvbs2_single(intp, intp->demod_mode,	STV0900_DEMOD_1);
13909a0bf528SMauro Carvalho Chehab 	intp->chip_id = stv0900_read_reg(intp, R0900_MID);
13919a0bf528SMauro Carvalho Chehab 	intp->rolloff = p_init->rolloff;
13929a0bf528SMauro Carvalho Chehab 	intp->quartz = p_init->dmd_ref_clk;
13939a0bf528SMauro Carvalho Chehab 
13949a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P1_ROLLOFF_CONTROL, p_init->rolloff);
13959a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P2_ROLLOFF_CONTROL, p_init->rolloff);
13969a0bf528SMauro Carvalho Chehab 
13979a0bf528SMauro Carvalho Chehab 	intp->ts_config = p_init->ts_config;
13989a0bf528SMauro Carvalho Chehab 	if (intp->ts_config == NULL)
13999a0bf528SMauro Carvalho Chehab 		stv0900_set_ts_parallel_serial(intp,
14009a0bf528SMauro Carvalho Chehab 				p_init->path1_ts_clock,
14019a0bf528SMauro Carvalho Chehab 				p_init->path2_ts_clock);
14029a0bf528SMauro Carvalho Chehab 	else {
14039a0bf528SMauro Carvalho Chehab 		for (i = 0; intp->ts_config[i].addr != 0xffff; i++)
14049a0bf528SMauro Carvalho Chehab 			stv0900_write_reg(intp,
14059a0bf528SMauro Carvalho Chehab 					intp->ts_config[i].addr,
14069a0bf528SMauro Carvalho Chehab 					intp->ts_config[i].val);
14079a0bf528SMauro Carvalho Chehab 
14089a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_RST_HWARE, 1);
14099a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_RST_HWARE, 0);
14109a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_RST_HWARE, 1);
14119a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0);
14129a0bf528SMauro Carvalho Chehab 	}
14139a0bf528SMauro Carvalho Chehab 
14149a0bf528SMauro Carvalho Chehab 	intp->tuner_type[0] = p_init->tuner1_type;
14159a0bf528SMauro Carvalho Chehab 	intp->tuner_type[1] = p_init->tuner2_type;
14169a0bf528SMauro Carvalho Chehab 	/* tuner init */
14179a0bf528SMauro Carvalho Chehab 	switch (p_init->tuner1_type) {
14189a0bf528SMauro Carvalho Chehab 	case 3: /*FE_AUTO_STB6100:*/
14199a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x3c);
14209a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRCFG2, 0x86);
14219a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRCFG3, 0x18);
14229a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRXTAL, 27); /* 27MHz */
14239a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRSTEPS, 0x05);
14249a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRGAIN, 0x17);
14259a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRADJ, 0x1f);
14269a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P1_TNRCTL2, 0x0);
14279a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 3);
14289a0bf528SMauro Carvalho Chehab 		break;
14299a0bf528SMauro Carvalho Chehab 	/* case FE_SW_TUNER: */
14309a0bf528SMauro Carvalho Chehab 	default:
14319a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 6);
14329a0bf528SMauro Carvalho Chehab 		break;
14339a0bf528SMauro Carvalho Chehab 	}
14349a0bf528SMauro Carvalho Chehab 
14359a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress);
14369a0bf528SMauro Carvalho Chehab 	switch (p_init->tuner1_adc) {
14379a0bf528SMauro Carvalho Chehab 	case 1:
14389a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_TSTTNR1, 0x26);
14399a0bf528SMauro Carvalho Chehab 		break;
14409a0bf528SMauro Carvalho Chehab 	default:
14419a0bf528SMauro Carvalho Chehab 		break;
14429a0bf528SMauro Carvalho Chehab 	}
14439a0bf528SMauro Carvalho Chehab 
14449a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P1_TNRLD, 1); /* hw tuner */
14459a0bf528SMauro Carvalho Chehab 
14469a0bf528SMauro Carvalho Chehab 	/* tuner init */
14479a0bf528SMauro Carvalho Chehab 	switch (p_init->tuner2_type) {
14489a0bf528SMauro Carvalho Chehab 	case 3: /*FE_AUTO_STB6100:*/
14499a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x3c);
14509a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRCFG2, 0x86);
14519a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRCFG3, 0x18);
14529a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRXTAL, 27); /* 27MHz */
14539a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRSTEPS, 0x05);
14549a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRGAIN, 0x17);
14559a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRADJ, 0x1f);
14569a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_P2_TNRCTL2, 0x0);
14579a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 3);
14589a0bf528SMauro Carvalho Chehab 		break;
14599a0bf528SMauro Carvalho Chehab 	/* case FE_SW_TUNER: */
14609a0bf528SMauro Carvalho Chehab 	default:
14619a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 6);
14629a0bf528SMauro Carvalho Chehab 		break;
14639a0bf528SMauro Carvalho Chehab 	}
14649a0bf528SMauro Carvalho Chehab 
14659a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress);
14669a0bf528SMauro Carvalho Chehab 	switch (p_init->tuner2_adc) {
14679a0bf528SMauro Carvalho Chehab 	case 1:
14689a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_TSTTNR3, 0x26);
14699a0bf528SMauro Carvalho Chehab 		break;
14709a0bf528SMauro Carvalho Chehab 	default:
14719a0bf528SMauro Carvalho Chehab 		break;
14729a0bf528SMauro Carvalho Chehab 	}
14739a0bf528SMauro Carvalho Chehab 
14749a0bf528SMauro Carvalho Chehab 	stv0900_write_reg(intp, R0900_P2_TNRLD, 1); /* hw tuner */
14759a0bf528SMauro Carvalho Chehab 
14769a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv);
14779a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv);
14789a0bf528SMauro Carvalho Chehab 	stv0900_set_mclk(intp, 135000000);
14799a0bf528SMauro Carvalho Chehab 	msleep(3);
14809a0bf528SMauro Carvalho Chehab 
14819a0bf528SMauro Carvalho Chehab 	switch (intp->clkmode) {
14829a0bf528SMauro Carvalho Chehab 	case 0:
14839a0bf528SMauro Carvalho Chehab 	case 2:
14849a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | intp->clkmode);
14859a0bf528SMauro Carvalho Chehab 		break;
14869a0bf528SMauro Carvalho Chehab 	default:
14879a0bf528SMauro Carvalho Chehab 		selosci = 0x02 & stv0900_read_reg(intp, R0900_SYNTCTRL);
14889a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | selosci);
14899a0bf528SMauro Carvalho Chehab 		break;
14909a0bf528SMauro Carvalho Chehab 	}
14919a0bf528SMauro Carvalho Chehab 	msleep(3);
14929a0bf528SMauro Carvalho Chehab 
14939a0bf528SMauro Carvalho Chehab 	intp->mclk = stv0900_get_mclk_freq(intp, intp->quartz);
14949a0bf528SMauro Carvalho Chehab 	if (intp->errs)
14959a0bf528SMauro Carvalho Chehab 		error = STV0900_I2C_ERROR;
14969a0bf528SMauro Carvalho Chehab 
14979a0bf528SMauro Carvalho Chehab 	return error;
14989a0bf528SMauro Carvalho Chehab }
14999a0bf528SMauro Carvalho Chehab 
stv0900_status(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod)15009a0bf528SMauro Carvalho Chehab static int stv0900_status(struct stv0900_internal *intp,
15019a0bf528SMauro Carvalho Chehab 					enum fe_stv0900_demod_num demod)
15029a0bf528SMauro Carvalho Chehab {
15039a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_search_state demod_state;
15049a0bf528SMauro Carvalho Chehab 	int locked = FALSE;
15059a0bf528SMauro Carvalho Chehab 	u8 tsbitrate0_val, tsbitrate1_val;
15069a0bf528SMauro Carvalho Chehab 	s32 bitrate;
15079a0bf528SMauro Carvalho Chehab 
15089a0bf528SMauro Carvalho Chehab 	demod_state = stv0900_get_bits(intp, HEADER_MODE);
15099a0bf528SMauro Carvalho Chehab 	switch (demod_state) {
15109a0bf528SMauro Carvalho Chehab 	case STV0900_SEARCH:
15119a0bf528SMauro Carvalho Chehab 	case STV0900_PLH_DETECTED:
15129a0bf528SMauro Carvalho Chehab 	default:
15139a0bf528SMauro Carvalho Chehab 		locked = FALSE;
15149a0bf528SMauro Carvalho Chehab 		break;
15159a0bf528SMauro Carvalho Chehab 	case STV0900_DVBS2_FOUND:
15169a0bf528SMauro Carvalho Chehab 		locked = stv0900_get_bits(intp, LOCK_DEFINITIF) &&
15179a0bf528SMauro Carvalho Chehab 				stv0900_get_bits(intp, PKTDELIN_LOCK) &&
15189a0bf528SMauro Carvalho Chehab 				stv0900_get_bits(intp, TSFIFO_LINEOK);
15199a0bf528SMauro Carvalho Chehab 		break;
15209a0bf528SMauro Carvalho Chehab 	case STV0900_DVBS_FOUND:
15219a0bf528SMauro Carvalho Chehab 		locked = stv0900_get_bits(intp, LOCK_DEFINITIF) &&
15229a0bf528SMauro Carvalho Chehab 				stv0900_get_bits(intp, LOCKEDVIT) &&
15239a0bf528SMauro Carvalho Chehab 				stv0900_get_bits(intp, TSFIFO_LINEOK);
15249a0bf528SMauro Carvalho Chehab 		break;
15259a0bf528SMauro Carvalho Chehab 	}
15269a0bf528SMauro Carvalho Chehab 
15279a0bf528SMauro Carvalho Chehab 	dprintk("%s: locked = %d\n", __func__, locked);
15289a0bf528SMauro Carvalho Chehab 
15299a0bf528SMauro Carvalho Chehab 	if (stvdebug) {
15309a0bf528SMauro Carvalho Chehab 		/* Print TS bitrate */
15319a0bf528SMauro Carvalho Chehab 		tsbitrate0_val = stv0900_read_reg(intp, TSBITRATE0);
15329a0bf528SMauro Carvalho Chehab 		tsbitrate1_val = stv0900_read_reg(intp, TSBITRATE1);
15339a0bf528SMauro Carvalho Chehab 		/* Formula Bit rate = Mclk * px_tsfifo_bitrate / 16384 */
15349a0bf528SMauro Carvalho Chehab 		bitrate = (stv0900_get_mclk_freq(intp, intp->quartz)/1000000)
15359a0bf528SMauro Carvalho Chehab 			* (tsbitrate1_val << 8 | tsbitrate0_val);
15369a0bf528SMauro Carvalho Chehab 		bitrate /= 16384;
15379a0bf528SMauro Carvalho Chehab 		dprintk("TS bitrate = %d Mbit/sec\n", bitrate);
1538c2c1b415SPeter Senna Tschudin 	}
15399a0bf528SMauro Carvalho Chehab 
15409a0bf528SMauro Carvalho Chehab 	return locked;
15419a0bf528SMauro Carvalho Chehab }
15429a0bf528SMauro Carvalho Chehab 
stv0900_set_mis(struct stv0900_internal * intp,enum fe_stv0900_demod_num demod,int mis)154373ec66c0SEvgeny Plehov static int stv0900_set_mis(struct stv0900_internal *intp,
154473ec66c0SEvgeny Plehov 				enum fe_stv0900_demod_num demod, int mis)
154573ec66c0SEvgeny Plehov {
154673ec66c0SEvgeny Plehov 	dprintk("%s\n", __func__);
154773ec66c0SEvgeny Plehov 
154873ec66c0SEvgeny Plehov 	if (mis < 0 || mis > 255) {
154973ec66c0SEvgeny Plehov 		dprintk("Disable MIS filtering\n");
155073ec66c0SEvgeny Plehov 		stv0900_write_bits(intp, FILTER_EN, 0);
155173ec66c0SEvgeny Plehov 	} else {
155273ec66c0SEvgeny Plehov 		dprintk("Enable MIS filtering - %d\n", mis);
155373ec66c0SEvgeny Plehov 		stv0900_write_bits(intp, FILTER_EN, 1);
155473ec66c0SEvgeny Plehov 		stv0900_write_reg(intp, ISIENTRY, mis);
155573ec66c0SEvgeny Plehov 		stv0900_write_reg(intp, ISIBITENA, 0xff);
155673ec66c0SEvgeny Plehov 	}
155773ec66c0SEvgeny Plehov 
155849bc8962SMauro Carvalho Chehab 	return STV0900_NO_ERROR;
155973ec66c0SEvgeny Plehov }
156073ec66c0SEvgeny Plehov 
156173ec66c0SEvgeny Plehov 
stv0900_search(struct dvb_frontend * fe)15629a0bf528SMauro Carvalho Chehab static enum dvbfe_search stv0900_search(struct dvb_frontend *fe)
15639a0bf528SMauro Carvalho Chehab {
15649a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
15659a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
15669a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
15679a0bf528SMauro Carvalho Chehab 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
15689a0bf528SMauro Carvalho Chehab 
15699a0bf528SMauro Carvalho Chehab 	struct stv0900_search_params p_search;
15709a0bf528SMauro Carvalho Chehab 	struct stv0900_signal_info p_result = intp->result[demod];
15719a0bf528SMauro Carvalho Chehab 
15729a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_error error = STV0900_NO_ERROR;
15739a0bf528SMauro Carvalho Chehab 
15749a0bf528SMauro Carvalho Chehab 	dprintk("%s: ", __func__);
15759a0bf528SMauro Carvalho Chehab 
15769a0bf528SMauro Carvalho Chehab 	if (!(INRANGE(100000, c->symbol_rate, 70000000)))
15779a0bf528SMauro Carvalho Chehab 		return DVBFE_ALGO_SEARCH_FAILED;
15789a0bf528SMauro Carvalho Chehab 
15799a0bf528SMauro Carvalho Chehab 	if (state->config->set_ts_params)
15809a0bf528SMauro Carvalho Chehab 		state->config->set_ts_params(fe, 0);
15819a0bf528SMauro Carvalho Chehab 
158273ec66c0SEvgeny Plehov 	stv0900_set_mis(intp, demod, c->stream_id);
158373ec66c0SEvgeny Plehov 
15849a0bf528SMauro Carvalho Chehab 	p_result.locked = FALSE;
15859a0bf528SMauro Carvalho Chehab 	p_search.path = demod;
15869a0bf528SMauro Carvalho Chehab 	p_search.frequency = c->frequency;
15879a0bf528SMauro Carvalho Chehab 	p_search.symbol_rate = c->symbol_rate;
15889a0bf528SMauro Carvalho Chehab 	p_search.search_range = 10000000;
15899a0bf528SMauro Carvalho Chehab 	p_search.fec = STV0900_FEC_UNKNOWN;
15909a0bf528SMauro Carvalho Chehab 	p_search.standard = STV0900_AUTO_SEARCH;
15919a0bf528SMauro Carvalho Chehab 	p_search.iq_inversion = STV0900_IQ_AUTO;
15929a0bf528SMauro Carvalho Chehab 	p_search.search_algo = STV0900_BLIND_SEARCH;
15939a0bf528SMauro Carvalho Chehab 	/* Speeds up DVB-S searching */
15949a0bf528SMauro Carvalho Chehab 	if (c->delivery_system == SYS_DVBS)
15959a0bf528SMauro Carvalho Chehab 		p_search.standard = STV0900_SEARCH_DVBS1;
15969a0bf528SMauro Carvalho Chehab 
15979a0bf528SMauro Carvalho Chehab 	intp->srch_standard[demod] = p_search.standard;
15989a0bf528SMauro Carvalho Chehab 	intp->symbol_rate[demod] = p_search.symbol_rate;
15999a0bf528SMauro Carvalho Chehab 	intp->srch_range[demod] = p_search.search_range;
16009a0bf528SMauro Carvalho Chehab 	intp->freq[demod] = p_search.frequency;
16019a0bf528SMauro Carvalho Chehab 	intp->srch_algo[demod] = p_search.search_algo;
16029a0bf528SMauro Carvalho Chehab 	intp->srch_iq_inv[demod] = p_search.iq_inversion;
16039a0bf528SMauro Carvalho Chehab 	intp->fec[demod] = p_search.fec;
16049a0bf528SMauro Carvalho Chehab 	if ((stv0900_algo(fe) == STV0900_RANGEOK) &&
16059a0bf528SMauro Carvalho Chehab 				(intp->errs == STV0900_NO_ERROR)) {
16069a0bf528SMauro Carvalho Chehab 		p_result.locked = intp->result[demod].locked;
16079a0bf528SMauro Carvalho Chehab 		p_result.standard = intp->result[demod].standard;
16089a0bf528SMauro Carvalho Chehab 		p_result.frequency = intp->result[demod].frequency;
16099a0bf528SMauro Carvalho Chehab 		p_result.symbol_rate = intp->result[demod].symbol_rate;
16109a0bf528SMauro Carvalho Chehab 		p_result.fec = intp->result[demod].fec;
16119a0bf528SMauro Carvalho Chehab 		p_result.modcode = intp->result[demod].modcode;
16129a0bf528SMauro Carvalho Chehab 		p_result.pilot = intp->result[demod].pilot;
16139a0bf528SMauro Carvalho Chehab 		p_result.frame_len = intp->result[demod].frame_len;
16149a0bf528SMauro Carvalho Chehab 		p_result.spectrum = intp->result[demod].spectrum;
16159a0bf528SMauro Carvalho Chehab 		p_result.rolloff = intp->result[demod].rolloff;
16169a0bf528SMauro Carvalho Chehab 		p_result.modulation = intp->result[demod].modulation;
16179a0bf528SMauro Carvalho Chehab 	} else {
16189a0bf528SMauro Carvalho Chehab 		p_result.locked = FALSE;
16199a0bf528SMauro Carvalho Chehab 		switch (intp->err[demod]) {
16209a0bf528SMauro Carvalho Chehab 		case STV0900_I2C_ERROR:
16219a0bf528SMauro Carvalho Chehab 			error = STV0900_I2C_ERROR;
16229a0bf528SMauro Carvalho Chehab 			break;
16239a0bf528SMauro Carvalho Chehab 		case STV0900_NO_ERROR:
16249a0bf528SMauro Carvalho Chehab 		default:
16259a0bf528SMauro Carvalho Chehab 			error = STV0900_SEARCH_FAILED;
16269a0bf528SMauro Carvalho Chehab 			break;
16279a0bf528SMauro Carvalho Chehab 		}
16289a0bf528SMauro Carvalho Chehab 	}
16299a0bf528SMauro Carvalho Chehab 
16309a0bf528SMauro Carvalho Chehab 	if ((p_result.locked == TRUE) && (error == STV0900_NO_ERROR)) {
16319a0bf528SMauro Carvalho Chehab 		dprintk("Search Success\n");
16329a0bf528SMauro Carvalho Chehab 		return DVBFE_ALGO_SEARCH_SUCCESS;
16339a0bf528SMauro Carvalho Chehab 	} else {
16349a0bf528SMauro Carvalho Chehab 		dprintk("Search Fail\n");
16359a0bf528SMauro Carvalho Chehab 		return DVBFE_ALGO_SEARCH_FAILED;
16369a0bf528SMauro Carvalho Chehab 	}
16379a0bf528SMauro Carvalho Chehab 
16389a0bf528SMauro Carvalho Chehab }
16399a0bf528SMauro Carvalho Chehab 
stv0900_read_status(struct dvb_frontend * fe,enum fe_status * status)16409a0bf528SMauro Carvalho Chehab static int stv0900_read_status(struct dvb_frontend *fe, enum fe_status *status)
16419a0bf528SMauro Carvalho Chehab {
16429a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
16439a0bf528SMauro Carvalho Chehab 
16449a0bf528SMauro Carvalho Chehab 	dprintk("%s: ", __func__);
16459a0bf528SMauro Carvalho Chehab 
16469a0bf528SMauro Carvalho Chehab 	if ((stv0900_status(state->internal, state->demod)) == TRUE) {
16479a0bf528SMauro Carvalho Chehab 		dprintk("DEMOD LOCK OK\n");
16489a0bf528SMauro Carvalho Chehab 		*status = FE_HAS_CARRIER
16499a0bf528SMauro Carvalho Chehab 			| FE_HAS_VITERBI
16509a0bf528SMauro Carvalho Chehab 			| FE_HAS_SYNC
16519a0bf528SMauro Carvalho Chehab 			| FE_HAS_LOCK;
16529a0bf528SMauro Carvalho Chehab 		if (state->config->set_lock_led)
16539a0bf528SMauro Carvalho Chehab 			state->config->set_lock_led(fe, 1);
16549a0bf528SMauro Carvalho Chehab 	} else {
16559a0bf528SMauro Carvalho Chehab 		*status = 0;
16569a0bf528SMauro Carvalho Chehab 		if (state->config->set_lock_led)
16579a0bf528SMauro Carvalho Chehab 			state->config->set_lock_led(fe, 0);
16589a0bf528SMauro Carvalho Chehab 		dprintk("DEMOD LOCK FAIL\n");
16599a0bf528SMauro Carvalho Chehab 	}
16609a0bf528SMauro Carvalho Chehab 
16619a0bf528SMauro Carvalho Chehab 	return 0;
16629a0bf528SMauro Carvalho Chehab }
16639a0bf528SMauro Carvalho Chehab 
stv0900_stop_ts(struct dvb_frontend * fe,int stop_ts)16649a0bf528SMauro Carvalho Chehab static int stv0900_stop_ts(struct dvb_frontend *fe, int stop_ts)
16659a0bf528SMauro Carvalho Chehab {
16669a0bf528SMauro Carvalho Chehab 
16679a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
16689a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
16699a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
16709a0bf528SMauro Carvalho Chehab 
16719a0bf528SMauro Carvalho Chehab 	if (stop_ts == TRUE)
16729a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, RST_HWARE, 1);
16739a0bf528SMauro Carvalho Chehab 	else
16749a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, RST_HWARE, 0);
16759a0bf528SMauro Carvalho Chehab 
16769a0bf528SMauro Carvalho Chehab 	return 0;
16779a0bf528SMauro Carvalho Chehab }
16789a0bf528SMauro Carvalho Chehab 
stv0900_diseqc_init(struct dvb_frontend * fe)16799a0bf528SMauro Carvalho Chehab static int stv0900_diseqc_init(struct dvb_frontend *fe)
16809a0bf528SMauro Carvalho Chehab {
16819a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
16829a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
16839a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
16849a0bf528SMauro Carvalho Chehab 
16859a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DISTX_MODE, state->config->diseqc_mode);
16869a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DISEQC_RESET, 1);
16879a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DISEQC_RESET, 0);
16889a0bf528SMauro Carvalho Chehab 
16899a0bf528SMauro Carvalho Chehab 	return 0;
16909a0bf528SMauro Carvalho Chehab }
16919a0bf528SMauro Carvalho Chehab 
stv0900_init(struct dvb_frontend * fe)16929a0bf528SMauro Carvalho Chehab static int stv0900_init(struct dvb_frontend *fe)
16939a0bf528SMauro Carvalho Chehab {
16949a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
16959a0bf528SMauro Carvalho Chehab 
16969a0bf528SMauro Carvalho Chehab 	stv0900_stop_ts(fe, 1);
16979a0bf528SMauro Carvalho Chehab 	stv0900_diseqc_init(fe);
16989a0bf528SMauro Carvalho Chehab 
16999a0bf528SMauro Carvalho Chehab 	return 0;
17009a0bf528SMauro Carvalho Chehab }
17019a0bf528SMauro Carvalho Chehab 
stv0900_diseqc_send(struct stv0900_internal * intp,u8 * data,u32 NbData,enum fe_stv0900_demod_num demod)17029a0bf528SMauro Carvalho Chehab static int stv0900_diseqc_send(struct stv0900_internal *intp , u8 *data,
17039a0bf528SMauro Carvalho Chehab 				u32 NbData, enum fe_stv0900_demod_num demod)
17049a0bf528SMauro Carvalho Chehab {
17059a0bf528SMauro Carvalho Chehab 	s32 i = 0;
17069a0bf528SMauro Carvalho Chehab 
17079a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DIS_PRECHARGE, 1);
17089a0bf528SMauro Carvalho Chehab 	while (i < NbData) {
17099a0bf528SMauro Carvalho Chehab 		while (stv0900_get_bits(intp, FIFO_FULL))
17109a0bf528SMauro Carvalho Chehab 			;/* checkpatch complains */
17119a0bf528SMauro Carvalho Chehab 		stv0900_write_reg(intp, DISTXDATA, data[i]);
17129a0bf528SMauro Carvalho Chehab 		i++;
17139a0bf528SMauro Carvalho Chehab 	}
17149a0bf528SMauro Carvalho Chehab 
17159a0bf528SMauro Carvalho Chehab 	stv0900_write_bits(intp, DIS_PRECHARGE, 0);
17169a0bf528SMauro Carvalho Chehab 	i = 0;
17179a0bf528SMauro Carvalho Chehab 	while ((stv0900_get_bits(intp, TX_IDLE) != 1) && (i < 10)) {
17189a0bf528SMauro Carvalho Chehab 		msleep(10);
17199a0bf528SMauro Carvalho Chehab 		i++;
17209a0bf528SMauro Carvalho Chehab 	}
17219a0bf528SMauro Carvalho Chehab 
17229a0bf528SMauro Carvalho Chehab 	return 0;
17239a0bf528SMauro Carvalho Chehab }
17249a0bf528SMauro Carvalho Chehab 
stv0900_send_master_cmd(struct dvb_frontend * fe,struct dvb_diseqc_master_cmd * cmd)17259a0bf528SMauro Carvalho Chehab static int stv0900_send_master_cmd(struct dvb_frontend *fe,
17269a0bf528SMauro Carvalho Chehab 					struct dvb_diseqc_master_cmd *cmd)
17279a0bf528SMauro Carvalho Chehab {
17289a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
17299a0bf528SMauro Carvalho Chehab 
17309a0bf528SMauro Carvalho Chehab 	return stv0900_diseqc_send(state->internal,
17319a0bf528SMauro Carvalho Chehab 				cmd->msg,
17329a0bf528SMauro Carvalho Chehab 				cmd->msg_len,
17339a0bf528SMauro Carvalho Chehab 				state->demod);
17349a0bf528SMauro Carvalho Chehab }
17359a0bf528SMauro Carvalho Chehab 
stv0900_send_burst(struct dvb_frontend * fe,enum fe_sec_mini_cmd burst)17360df289a2SMauro Carvalho Chehab static int stv0900_send_burst(struct dvb_frontend *fe,
17370df289a2SMauro Carvalho Chehab 			      enum fe_sec_mini_cmd burst)
17389a0bf528SMauro Carvalho Chehab {
17399a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
17409a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
17419a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
17429a0bf528SMauro Carvalho Chehab 	u8 data;
17439a0bf528SMauro Carvalho Chehab 
17449a0bf528SMauro Carvalho Chehab 
17459a0bf528SMauro Carvalho Chehab 	switch (burst) {
17469a0bf528SMauro Carvalho Chehab 	case SEC_MINI_A:
17479a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISTX_MODE, 3);/* Unmodulated */
17489a0bf528SMauro Carvalho Chehab 		data = 0x00;
17499a0bf528SMauro Carvalho Chehab 		stv0900_diseqc_send(intp, &data, 1, state->demod);
17509a0bf528SMauro Carvalho Chehab 		break;
17519a0bf528SMauro Carvalho Chehab 	case SEC_MINI_B:
17529a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISTX_MODE, 2);/* Modulated */
17539a0bf528SMauro Carvalho Chehab 		data = 0xff;
17549a0bf528SMauro Carvalho Chehab 		stv0900_diseqc_send(intp, &data, 1, state->demod);
17559a0bf528SMauro Carvalho Chehab 		break;
17569a0bf528SMauro Carvalho Chehab 	}
17579a0bf528SMauro Carvalho Chehab 
17589a0bf528SMauro Carvalho Chehab 	return 0;
17599a0bf528SMauro Carvalho Chehab }
17609a0bf528SMauro Carvalho Chehab 
stv0900_recv_slave_reply(struct dvb_frontend * fe,struct dvb_diseqc_slave_reply * reply)17619a0bf528SMauro Carvalho Chehab static int stv0900_recv_slave_reply(struct dvb_frontend *fe,
17629a0bf528SMauro Carvalho Chehab 				struct dvb_diseqc_slave_reply *reply)
17639a0bf528SMauro Carvalho Chehab {
17649a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
17659a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
17669a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
17679a0bf528SMauro Carvalho Chehab 	s32 i = 0;
17689a0bf528SMauro Carvalho Chehab 
17699a0bf528SMauro Carvalho Chehab 	reply->msg_len = 0;
17709a0bf528SMauro Carvalho Chehab 
17719a0bf528SMauro Carvalho Chehab 	while ((stv0900_get_bits(intp, RX_END) != 1) && (i < 10)) {
17729a0bf528SMauro Carvalho Chehab 		msleep(10);
17739a0bf528SMauro Carvalho Chehab 		i++;
17749a0bf528SMauro Carvalho Chehab 	}
17759a0bf528SMauro Carvalho Chehab 
17769a0bf528SMauro Carvalho Chehab 	if (stv0900_get_bits(intp, RX_END)) {
17779a0bf528SMauro Carvalho Chehab 		reply->msg_len = stv0900_get_bits(intp, FIFO_BYTENBR);
17789a0bf528SMauro Carvalho Chehab 
17799a0bf528SMauro Carvalho Chehab 		for (i = 0; i < reply->msg_len; i++)
17809a0bf528SMauro Carvalho Chehab 			reply->msg[i] = stv0900_read_reg(intp, DISRXDATA);
17819a0bf528SMauro Carvalho Chehab 	}
17829a0bf528SMauro Carvalho Chehab 
17839a0bf528SMauro Carvalho Chehab 	return 0;
17849a0bf528SMauro Carvalho Chehab }
17859a0bf528SMauro Carvalho Chehab 
stv0900_set_tone(struct dvb_frontend * fe,enum fe_sec_tone_mode toneoff)17860df289a2SMauro Carvalho Chehab static int stv0900_set_tone(struct dvb_frontend *fe,
17870df289a2SMauro Carvalho Chehab 			    enum fe_sec_tone_mode toneoff)
17889a0bf528SMauro Carvalho Chehab {
17899a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
17909a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
17919a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
17929a0bf528SMauro Carvalho Chehab 
17939a0bf528SMauro Carvalho Chehab 	dprintk("%s: %s\n", __func__, ((toneoff == 0) ? "On" : "Off"));
17949a0bf528SMauro Carvalho Chehab 
17959a0bf528SMauro Carvalho Chehab 	switch (toneoff) {
17969a0bf528SMauro Carvalho Chehab 	case SEC_TONE_ON:
17979a0bf528SMauro Carvalho Chehab 		/*Set the DiseqC mode to 22Khz _continues_ tone*/
17989a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISTX_MODE, 0);
17999a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISEQC_RESET, 1);
18009a0bf528SMauro Carvalho Chehab 		/*release DiseqC reset to enable the 22KHz tone*/
18019a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISEQC_RESET, 0);
18029a0bf528SMauro Carvalho Chehab 		break;
18039a0bf528SMauro Carvalho Chehab 	case SEC_TONE_OFF:
18049a0bf528SMauro Carvalho Chehab 		/*return diseqc mode to config->diseqc_mode.
18059a0bf528SMauro Carvalho Chehab 		Usually it's without _continues_ tone */
18069a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISTX_MODE,
18079a0bf528SMauro Carvalho Chehab 				state->config->diseqc_mode);
18089a0bf528SMauro Carvalho Chehab 		/*maintain the DiseqC reset to disable the 22KHz tone*/
18099a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISEQC_RESET, 1);
18109a0bf528SMauro Carvalho Chehab 		stv0900_write_bits(intp, DISEQC_RESET, 0);
18119a0bf528SMauro Carvalho Chehab 		break;
18129a0bf528SMauro Carvalho Chehab 	default:
18139a0bf528SMauro Carvalho Chehab 		return -EINVAL;
18149a0bf528SMauro Carvalho Chehab 	}
18159a0bf528SMauro Carvalho Chehab 
18169a0bf528SMauro Carvalho Chehab 	return 0;
18179a0bf528SMauro Carvalho Chehab }
18189a0bf528SMauro Carvalho Chehab 
stv0900_release(struct dvb_frontend * fe)18199a0bf528SMauro Carvalho Chehab static void stv0900_release(struct dvb_frontend *fe)
18209a0bf528SMauro Carvalho Chehab {
18219a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
18229a0bf528SMauro Carvalho Chehab 
18239a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
18249a0bf528SMauro Carvalho Chehab 
18259a0bf528SMauro Carvalho Chehab 	if (state->config->set_lock_led)
18269a0bf528SMauro Carvalho Chehab 		state->config->set_lock_led(fe, 0);
18279a0bf528SMauro Carvalho Chehab 
18289a0bf528SMauro Carvalho Chehab 	if ((--(state->internal->dmds_used)) <= 0) {
18299a0bf528SMauro Carvalho Chehab 
18309a0bf528SMauro Carvalho Chehab 		dprintk("%s: Actually removing\n", __func__);
18319a0bf528SMauro Carvalho Chehab 
18329a0bf528SMauro Carvalho Chehab 		remove_inode(state->internal);
18339a0bf528SMauro Carvalho Chehab 		kfree(state->internal);
18349a0bf528SMauro Carvalho Chehab 	}
18359a0bf528SMauro Carvalho Chehab 
18369a0bf528SMauro Carvalho Chehab 	kfree(state);
18379a0bf528SMauro Carvalho Chehab }
18389a0bf528SMauro Carvalho Chehab 
stv0900_sleep(struct dvb_frontend * fe)18399a0bf528SMauro Carvalho Chehab static int stv0900_sleep(struct dvb_frontend *fe)
18409a0bf528SMauro Carvalho Chehab {
18419a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
18429a0bf528SMauro Carvalho Chehab 
18439a0bf528SMauro Carvalho Chehab 	dprintk("%s\n", __func__);
18449a0bf528SMauro Carvalho Chehab 
18459a0bf528SMauro Carvalho Chehab 	if (state->config->set_lock_led)
18469a0bf528SMauro Carvalho Chehab 		state->config->set_lock_led(fe, 0);
18479a0bf528SMauro Carvalho Chehab 
18489a0bf528SMauro Carvalho Chehab 	return 0;
18499a0bf528SMauro Carvalho Chehab }
18509a0bf528SMauro Carvalho Chehab 
stv0900_get_frontend(struct dvb_frontend * fe,struct dtv_frontend_properties * p)18517e3e68bcSMauro Carvalho Chehab static int stv0900_get_frontend(struct dvb_frontend *fe,
18527e3e68bcSMauro Carvalho Chehab 				struct dtv_frontend_properties *p)
18539a0bf528SMauro Carvalho Chehab {
18549a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = fe->demodulator_priv;
18559a0bf528SMauro Carvalho Chehab 	struct stv0900_internal *intp = state->internal;
18569a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_demod_num demod = state->demod;
18579a0bf528SMauro Carvalho Chehab 	struct stv0900_signal_info p_result = intp->result[demod];
18589a0bf528SMauro Carvalho Chehab 
18599a0bf528SMauro Carvalho Chehab 	p->frequency = p_result.locked ? p_result.frequency : 0;
18609a0bf528SMauro Carvalho Chehab 	p->symbol_rate = p_result.locked ? p_result.symbol_rate : 0;
18619a0bf528SMauro Carvalho Chehab 	return 0;
18629a0bf528SMauro Carvalho Chehab }
18639a0bf528SMauro Carvalho Chehab 
1864bd336e63SMax Kellermann static const struct dvb_frontend_ops stv0900_ops = {
18659a0bf528SMauro Carvalho Chehab 	.delsys = { SYS_DVBS, SYS_DVBS2, SYS_DSS },
18669a0bf528SMauro Carvalho Chehab 	.info = {
18679a0bf528SMauro Carvalho Chehab 		.name			= "STV0900 frontend",
1868f1b1eabfSMauro Carvalho Chehab 		.frequency_min_hz	=  950 * MHz,
1869f1b1eabfSMauro Carvalho Chehab 		.frequency_max_hz	= 2150 * MHz,
1870f1b1eabfSMauro Carvalho Chehab 		.frequency_stepsize_hz	=  125 * kHz,
18719a0bf528SMauro Carvalho Chehab 		.symbol_rate_min	= 1000000,
18729a0bf528SMauro Carvalho Chehab 		.symbol_rate_max	= 45000000,
18739a0bf528SMauro Carvalho Chehab 		.symbol_rate_tolerance	= 500,
18749a0bf528SMauro Carvalho Chehab 		.caps			= FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
18759a0bf528SMauro Carvalho Chehab 					  FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 |
18769a0bf528SMauro Carvalho Chehab 					  FE_CAN_FEC_7_8 | FE_CAN_QPSK    |
18779a0bf528SMauro Carvalho Chehab 					  FE_CAN_2G_MODULATION |
18789a0bf528SMauro Carvalho Chehab 					  FE_CAN_FEC_AUTO
18799a0bf528SMauro Carvalho Chehab 	},
18809a0bf528SMauro Carvalho Chehab 	.release			= stv0900_release,
18819a0bf528SMauro Carvalho Chehab 	.init				= stv0900_init,
18829a0bf528SMauro Carvalho Chehab 	.get_frontend                   = stv0900_get_frontend,
18839a0bf528SMauro Carvalho Chehab 	.sleep				= stv0900_sleep,
18849a0bf528SMauro Carvalho Chehab 	.get_frontend_algo		= stv0900_frontend_algo,
18859a0bf528SMauro Carvalho Chehab 	.i2c_gate_ctrl			= stv0900_i2c_gate_ctrl,
18869a0bf528SMauro Carvalho Chehab 	.diseqc_send_master_cmd		= stv0900_send_master_cmd,
18879a0bf528SMauro Carvalho Chehab 	.diseqc_send_burst		= stv0900_send_burst,
18889a0bf528SMauro Carvalho Chehab 	.diseqc_recv_slave_reply	= stv0900_recv_slave_reply,
18899a0bf528SMauro Carvalho Chehab 	.set_tone			= stv0900_set_tone,
18909a0bf528SMauro Carvalho Chehab 	.search				= stv0900_search,
18919a0bf528SMauro Carvalho Chehab 	.read_status			= stv0900_read_status,
18929a0bf528SMauro Carvalho Chehab 	.read_ber			= stv0900_read_ber,
18939a0bf528SMauro Carvalho Chehab 	.read_signal_strength		= stv0900_read_signal_strength,
18949a0bf528SMauro Carvalho Chehab 	.read_snr			= stv0900_read_snr,
18959a0bf528SMauro Carvalho Chehab 	.read_ucblocks                  = stv0900_read_ucblocks,
18969a0bf528SMauro Carvalho Chehab };
18979a0bf528SMauro Carvalho Chehab 
stv0900_attach(const struct stv0900_config * config,struct i2c_adapter * i2c,int demod)18989a0bf528SMauro Carvalho Chehab struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
18999a0bf528SMauro Carvalho Chehab 					struct i2c_adapter *i2c,
19009a0bf528SMauro Carvalho Chehab 					int demod)
19019a0bf528SMauro Carvalho Chehab {
19029a0bf528SMauro Carvalho Chehab 	struct stv0900_state *state = NULL;
19039a0bf528SMauro Carvalho Chehab 	struct stv0900_init_params init_params;
19049a0bf528SMauro Carvalho Chehab 	enum fe_stv0900_error err_stv0900;
19059a0bf528SMauro Carvalho Chehab 
19069a0bf528SMauro Carvalho Chehab 	state = kzalloc(sizeof(struct stv0900_state), GFP_KERNEL);
19079a0bf528SMauro Carvalho Chehab 	if (state == NULL)
19089a0bf528SMauro Carvalho Chehab 		goto error;
19099a0bf528SMauro Carvalho Chehab 
19109a0bf528SMauro Carvalho Chehab 	state->demod		= demod;
19119a0bf528SMauro Carvalho Chehab 	state->config		= config;
19129a0bf528SMauro Carvalho Chehab 	state->i2c_adap		= i2c;
19139a0bf528SMauro Carvalho Chehab 
19149a0bf528SMauro Carvalho Chehab 	memcpy(&state->frontend.ops, &stv0900_ops,
19159a0bf528SMauro Carvalho Chehab 			sizeof(struct dvb_frontend_ops));
19169a0bf528SMauro Carvalho Chehab 	state->frontend.demodulator_priv = state;
19179a0bf528SMauro Carvalho Chehab 
19189a0bf528SMauro Carvalho Chehab 	switch (demod) {
19199a0bf528SMauro Carvalho Chehab 	case 0:
19209a0bf528SMauro Carvalho Chehab 	case 1:
19219a0bf528SMauro Carvalho Chehab 		init_params.dmd_ref_clk		= config->xtal;
19229a0bf528SMauro Carvalho Chehab 		init_params.demod_mode		= config->demod_mode;
19239a0bf528SMauro Carvalho Chehab 		init_params.rolloff		= STV0900_35;
19249a0bf528SMauro Carvalho Chehab 		init_params.path1_ts_clock	= config->path1_mode;
19259a0bf528SMauro Carvalho Chehab 		init_params.tun1_maddress	= config->tun1_maddress;
19269a0bf528SMauro Carvalho Chehab 		init_params.tun1_iq_inv		= STV0900_IQ_NORMAL;
19279a0bf528SMauro Carvalho Chehab 		init_params.tuner1_adc		= config->tun1_adc;
19289a0bf528SMauro Carvalho Chehab 		init_params.tuner1_type		= config->tun1_type;
19299a0bf528SMauro Carvalho Chehab 		init_params.path2_ts_clock	= config->path2_mode;
19309a0bf528SMauro Carvalho Chehab 		init_params.ts_config		= config->ts_config_regs;
19319a0bf528SMauro Carvalho Chehab 		init_params.tun2_maddress	= config->tun2_maddress;
19329a0bf528SMauro Carvalho Chehab 		init_params.tuner2_adc		= config->tun2_adc;
19339a0bf528SMauro Carvalho Chehab 		init_params.tuner2_type		= config->tun2_type;
19349a0bf528SMauro Carvalho Chehab 		init_params.tun2_iq_inv		= STV0900_IQ_SWAPPED;
19359a0bf528SMauro Carvalho Chehab 
19369a0bf528SMauro Carvalho Chehab 		err_stv0900 = stv0900_init_internal(&state->frontend,
19379a0bf528SMauro Carvalho Chehab 							&init_params);
19389a0bf528SMauro Carvalho Chehab 
19399a0bf528SMauro Carvalho Chehab 		if (err_stv0900)
19409a0bf528SMauro Carvalho Chehab 			goto error;
19419a0bf528SMauro Carvalho Chehab 
194273ec66c0SEvgeny Plehov 		if (state->internal->chip_id >= 0x30)
194373ec66c0SEvgeny Plehov 			state->frontend.ops.info.caps |= FE_CAN_MULTISTREAM;
194473ec66c0SEvgeny Plehov 
19459a0bf528SMauro Carvalho Chehab 		break;
19469a0bf528SMauro Carvalho Chehab 	default:
19479a0bf528SMauro Carvalho Chehab 		goto error;
19489a0bf528SMauro Carvalho Chehab 		break;
19499a0bf528SMauro Carvalho Chehab 	}
19509a0bf528SMauro Carvalho Chehab 
19519a0bf528SMauro Carvalho Chehab 	dprintk("%s: Attaching STV0900 demodulator(%d) \n", __func__, demod);
19529a0bf528SMauro Carvalho Chehab 	return &state->frontend;
19539a0bf528SMauro Carvalho Chehab 
19549a0bf528SMauro Carvalho Chehab error:
19559a0bf528SMauro Carvalho Chehab 	dprintk("%s: Failed to attach STV0900 demodulator(%d) \n",
19569a0bf528SMauro Carvalho Chehab 		__func__, demod);
19579a0bf528SMauro Carvalho Chehab 	kfree(state);
19589a0bf528SMauro Carvalho Chehab 	return NULL;
19599a0bf528SMauro Carvalho Chehab }
1960*86495af1SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(stv0900_attach);
19619a0bf528SMauro Carvalho Chehab 
19629a0bf528SMauro Carvalho Chehab MODULE_PARM_DESC(debug, "Set debug");
19639a0bf528SMauro Carvalho Chehab 
19649a0bf528SMauro Carvalho Chehab MODULE_AUTHOR("Igor M. Liplianin");
19659a0bf528SMauro Carvalho Chehab MODULE_DESCRIPTION("ST STV0900 frontend");
19669a0bf528SMauro Carvalho Chehab MODULE_LICENSE("GPL");
1967