18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * budget.c: driver for the SAA7146 based Budget DVB cards
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Compiled from various sources by Michael Hunold <michael@mihu.de>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 1999-2002 Ralph  Metzler
108c2ecf20Sopenharmony_ci *                       & Marcus Metzler for convergence integrated media GmbH
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * 26feb2004 Support for FS Activy Card (Grundig tuner) by
138c2ecf20Sopenharmony_ci *           Michael Dreher <michael@5dot1.de>,
148c2ecf20Sopenharmony_ci *           Oliver Endriss <o.endriss@gmx.de> and
158c2ecf20Sopenharmony_ci *           Andreas 'randy' Weinberger
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * the project's page is at https://linuxtv.org
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "budget.h"
218c2ecf20Sopenharmony_ci#include "stv0299.h"
228c2ecf20Sopenharmony_ci#include "ves1x93.h"
238c2ecf20Sopenharmony_ci#include "ves1820.h"
248c2ecf20Sopenharmony_ci#include "l64781.h"
258c2ecf20Sopenharmony_ci#include "tda8083.h"
268c2ecf20Sopenharmony_ci#include "s5h1420.h"
278c2ecf20Sopenharmony_ci#include "tda10086.h"
288c2ecf20Sopenharmony_ci#include "tda826x.h"
298c2ecf20Sopenharmony_ci#include "lnbp21.h"
308c2ecf20Sopenharmony_ci#include "bsru6.h"
318c2ecf20Sopenharmony_ci#include "bsbe1.h"
328c2ecf20Sopenharmony_ci#include "tdhd1.h"
338c2ecf20Sopenharmony_ci#include "stv6110x.h"
348c2ecf20Sopenharmony_ci#include "stv090x.h"
358c2ecf20Sopenharmony_ci#include "isl6423.h"
368c2ecf20Sopenharmony_ci#include "lnbh24.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic int diseqc_method;
408c2ecf20Sopenharmony_cimodule_param(diseqc_method, int, 0444);
418c2ecf20Sopenharmony_ciMODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciDVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic void Set22K (struct budget *budget, int state)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	struct saa7146_dev *dev=budget->dev;
488c2ecf20Sopenharmony_ci	dprintk(2, "budget: %p\n", budget);
498c2ecf20Sopenharmony_ci	saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* Diseqc functions only for TT Budget card */
538c2ecf20Sopenharmony_ci/* taken from the Skyvision DVB driver by
548c2ecf20Sopenharmony_ci   Ralph Metzler <rjkm@metzlerbros.de> */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic void DiseqcSendBit (struct budget *budget, int data)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	struct saa7146_dev *dev=budget->dev;
598c2ecf20Sopenharmony_ci	dprintk(2, "budget: %p\n", budget);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
628c2ecf20Sopenharmony_ci	udelay(data ? 500 : 1000);
638c2ecf20Sopenharmony_ci	saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
648c2ecf20Sopenharmony_ci	udelay(data ? 1000 : 500);
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic void DiseqcSendByte (struct budget *budget, int data)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	int i, par=1, d;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	dprintk(2, "budget: %p\n", budget);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	for (i=7; i>=0; i--) {
748c2ecf20Sopenharmony_ci		d = (data>>i)&1;
758c2ecf20Sopenharmony_ci		par ^= d;
768c2ecf20Sopenharmony_ci		DiseqcSendBit(budget, d);
778c2ecf20Sopenharmony_ci	}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	DiseqcSendBit(budget, par);
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	struct saa7146_dev *dev=budget->dev;
858c2ecf20Sopenharmony_ci	int i;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	dprintk(2, "budget: %p\n", budget);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
908c2ecf20Sopenharmony_ci	mdelay(16);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	for (i=0; i<len; i++)
938c2ecf20Sopenharmony_ci		DiseqcSendByte(budget, msg[i]);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	mdelay(16);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	if (burst!=-1) {
988c2ecf20Sopenharmony_ci		if (burst)
998c2ecf20Sopenharmony_ci			DiseqcSendByte(budget, 0xff);
1008c2ecf20Sopenharmony_ci		else {
1018c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
1028c2ecf20Sopenharmony_ci			mdelay(12);
1038c2ecf20Sopenharmony_ci			udelay(500);
1048c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
1058c2ecf20Sopenharmony_ci		}
1068c2ecf20Sopenharmony_ci		msleep(20);
1078c2ecf20Sopenharmony_ci	}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	return 0;
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci *   Routines for the Fujitsu Siemens Activy budget card
1148c2ecf20Sopenharmony_ci *   22 kHz tone and DiSEqC are handled by the frontend.
1158c2ecf20Sopenharmony_ci *   Voltage must be set here.
1168c2ecf20Sopenharmony_ci *   GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_cistatic int SetVoltage_Activy(struct budget *budget,
1198c2ecf20Sopenharmony_ci			     enum fe_sec_voltage voltage)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	struct saa7146_dev *dev=budget->dev;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	dprintk(2, "budget: %p\n", budget);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	switch (voltage) {
1268c2ecf20Sopenharmony_ci		case SEC_VOLTAGE_13:
1278c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
1288c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
1298c2ecf20Sopenharmony_ci			break;
1308c2ecf20Sopenharmony_ci		case SEC_VOLTAGE_18:
1318c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
1328c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
1338c2ecf20Sopenharmony_ci			break;
1348c2ecf20Sopenharmony_ci		case SEC_VOLTAGE_OFF:
1358c2ecf20Sopenharmony_ci			saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
1368c2ecf20Sopenharmony_ci			break;
1378c2ecf20Sopenharmony_ci		default:
1388c2ecf20Sopenharmony_ci			return -EINVAL;
1398c2ecf20Sopenharmony_ci	}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	return 0;
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic int siemens_budget_set_voltage(struct dvb_frontend *fe,
1458c2ecf20Sopenharmony_ci				      enum fe_sec_voltage voltage)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	return SetVoltage_Activy (budget, voltage);
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cistatic int budget_set_tone(struct dvb_frontend *fe,
1538c2ecf20Sopenharmony_ci			   enum fe_sec_tone_mode tone)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	switch (tone) {
1588c2ecf20Sopenharmony_ci	case SEC_TONE_ON:
1598c2ecf20Sopenharmony_ci		Set22K (budget, 1);
1608c2ecf20Sopenharmony_ci		break;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	case SEC_TONE_OFF:
1638c2ecf20Sopenharmony_ci		Set22K (budget, 0);
1648c2ecf20Sopenharmony_ci		break;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	default:
1678c2ecf20Sopenharmony_ci		return -EINVAL;
1688c2ecf20Sopenharmony_ci	}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	return 0;
1718c2ecf20Sopenharmony_ci}
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	return 0;
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic int budget_diseqc_send_burst(struct dvb_frontend *fe,
1838c2ecf20Sopenharmony_ci				    enum fe_sec_mini_cmd minicmd)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	SendDiSEqCMsg (budget, 0, NULL, minicmd);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	return 0;
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1958c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
1968c2ecf20Sopenharmony_ci	u8 pwr = 0;
1978c2ecf20Sopenharmony_ci	u8 buf[4];
1988c2ecf20Sopenharmony_ci	struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
1998c2ecf20Sopenharmony_ci	u32 div = (c->frequency + 479500) / 125;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	if (c->frequency > 2000000)
2028c2ecf20Sopenharmony_ci		pwr = 3;
2038c2ecf20Sopenharmony_ci	else if (c->frequency > 1800000)
2048c2ecf20Sopenharmony_ci		pwr = 2;
2058c2ecf20Sopenharmony_ci	else if (c->frequency > 1600000)
2068c2ecf20Sopenharmony_ci		pwr = 1;
2078c2ecf20Sopenharmony_ci	else if (c->frequency > 1200000)
2088c2ecf20Sopenharmony_ci		pwr = 0;
2098c2ecf20Sopenharmony_ci	else if (c->frequency >= 1100000)
2108c2ecf20Sopenharmony_ci		pwr = 1;
2118c2ecf20Sopenharmony_ci	else pwr = 2;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	buf[0] = (div >> 8) & 0x7f;
2148c2ecf20Sopenharmony_ci	buf[1] = div & 0xff;
2158c2ecf20Sopenharmony_ci	buf[2] = ((div & 0x18000) >> 10) | 0x95;
2168c2ecf20Sopenharmony_ci	buf[3] = (pwr << 6) | 0x30;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	// NOTE: since we're using a prescaler of 2, we set the
2198c2ecf20Sopenharmony_ci	// divisor frequency to 62.5kHz and divide by 125 above
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2228c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1);
2238c2ecf20Sopenharmony_ci	if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
2248c2ecf20Sopenharmony_ci	return 0;
2258c2ecf20Sopenharmony_ci}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistatic struct ves1x93_config alps_bsrv2_config =
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	.demod_address = 0x08,
2308c2ecf20Sopenharmony_ci	.xin = 90100000UL,
2318c2ecf20Sopenharmony_ci	.invert_pwm = 0,
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic int alps_tdbe2_tuner_set_params(struct dvb_frontend *fe)
2358c2ecf20Sopenharmony_ci{
2368c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2378c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
2388c2ecf20Sopenharmony_ci	u32 div;
2398c2ecf20Sopenharmony_ci	u8 data[4];
2408c2ecf20Sopenharmony_ci	struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	div = (c->frequency + 35937500 + 31250) / 62500;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	data[0] = (div >> 8) & 0x7f;
2458c2ecf20Sopenharmony_ci	data[1] = div & 0xff;
2468c2ecf20Sopenharmony_ci	data[2] = 0x85 | ((div >> 10) & 0x60);
2478c2ecf20Sopenharmony_ci	data[3] = (c->frequency < 174000000 ? 0x88 : c->frequency < 470000000 ? 0x84 : 0x81);
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2508c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1);
2518c2ecf20Sopenharmony_ci	if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
2528c2ecf20Sopenharmony_ci	return 0;
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic struct ves1820_config alps_tdbe2_config = {
2568c2ecf20Sopenharmony_ci	.demod_address = 0x09,
2578c2ecf20Sopenharmony_ci	.xin = 57840000UL,
2588c2ecf20Sopenharmony_ci	.invert = 1,
2598c2ecf20Sopenharmony_ci	.selagc = VES1820_SELAGC_SIGNAMPERR,
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic int grundig_29504_401_tuner_set_params(struct dvb_frontend *fe)
2638c2ecf20Sopenharmony_ci{
2648c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2658c2ecf20Sopenharmony_ci	struct budget *budget = fe->dvb->priv;
2668c2ecf20Sopenharmony_ci	u8 *tuner_addr = fe->tuner_priv;
2678c2ecf20Sopenharmony_ci	u32 div;
2688c2ecf20Sopenharmony_ci	u8 cfg, cpump, band_select;
2698c2ecf20Sopenharmony_ci	u8 data[4];
2708c2ecf20Sopenharmony_ci	struct i2c_msg msg = { .flags = 0, .buf = data, .len = sizeof(data) };
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	if (tuner_addr)
2738c2ecf20Sopenharmony_ci		msg.addr = *tuner_addr;
2748c2ecf20Sopenharmony_ci	else
2758c2ecf20Sopenharmony_ci		msg.addr = 0x61;
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	div = (36125000 + c->frequency) / 166666;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	cfg = 0x88;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	if (c->frequency < 175000000)
2828c2ecf20Sopenharmony_ci		cpump = 2;
2838c2ecf20Sopenharmony_ci	else if (c->frequency < 390000000)
2848c2ecf20Sopenharmony_ci		cpump = 1;
2858c2ecf20Sopenharmony_ci	else if (c->frequency < 470000000)
2868c2ecf20Sopenharmony_ci		cpump = 2;
2878c2ecf20Sopenharmony_ci	else if (c->frequency < 750000000)
2888c2ecf20Sopenharmony_ci		cpump = 1;
2898c2ecf20Sopenharmony_ci	else
2908c2ecf20Sopenharmony_ci		cpump = 3;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	if (c->frequency < 175000000)
2938c2ecf20Sopenharmony_ci		band_select = 0x0e;
2948c2ecf20Sopenharmony_ci	else if (c->frequency < 470000000)
2958c2ecf20Sopenharmony_ci		band_select = 0x05;
2968c2ecf20Sopenharmony_ci	else
2978c2ecf20Sopenharmony_ci		band_select = 0x03;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	data[0] = (div >> 8) & 0x7f;
3008c2ecf20Sopenharmony_ci	data[1] = div & 0xff;
3018c2ecf20Sopenharmony_ci	data[2] = ((div >> 10) & 0x60) | cfg;
3028c2ecf20Sopenharmony_ci	data[3] = (cpump << 6) | band_select;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
3058c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1);
3068c2ecf20Sopenharmony_ci	if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
3078c2ecf20Sopenharmony_ci	return 0;
3088c2ecf20Sopenharmony_ci}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cistatic struct l64781_config grundig_29504_401_config = {
3118c2ecf20Sopenharmony_ci	.demod_address = 0x55,
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic struct l64781_config grundig_29504_401_config_activy = {
3158c2ecf20Sopenharmony_ci	.demod_address = 0x54,
3168c2ecf20Sopenharmony_ci};
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_cistatic u8 tuner_address_grundig_29504_401_activy = 0x60;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
3238c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
3248c2ecf20Sopenharmony_ci	u32 div;
3258c2ecf20Sopenharmony_ci	u8 data[4];
3268c2ecf20Sopenharmony_ci	struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	div = c->frequency / 125;
3298c2ecf20Sopenharmony_ci	data[0] = (div >> 8) & 0x7f;
3308c2ecf20Sopenharmony_ci	data[1] = div & 0xff;
3318c2ecf20Sopenharmony_ci	data[2] = 0x8e;
3328c2ecf20Sopenharmony_ci	data[3] = 0x00;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
3358c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1);
3368c2ecf20Sopenharmony_ci	if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
3378c2ecf20Sopenharmony_ci	return 0;
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic struct tda8083_config grundig_29504_451_config = {
3418c2ecf20Sopenharmony_ci	.demod_address = 0x68,
3428c2ecf20Sopenharmony_ci};
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cistatic int s5h1420_tuner_set_params(struct dvb_frontend *fe)
3458c2ecf20Sopenharmony_ci{
3468c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
3478c2ecf20Sopenharmony_ci	struct budget* budget = (struct budget*) fe->dvb->priv;
3488c2ecf20Sopenharmony_ci	u32 div;
3498c2ecf20Sopenharmony_ci	u8 data[4];
3508c2ecf20Sopenharmony_ci	struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	div = c->frequency / 1000;
3538c2ecf20Sopenharmony_ci	data[0] = (div >> 8) & 0x7f;
3548c2ecf20Sopenharmony_ci	data[1] = div & 0xff;
3558c2ecf20Sopenharmony_ci	data[2] = 0xc2;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	if (div < 1450)
3588c2ecf20Sopenharmony_ci		data[3] = 0x00;
3598c2ecf20Sopenharmony_ci	else if (div < 1850)
3608c2ecf20Sopenharmony_ci		data[3] = 0x40;
3618c2ecf20Sopenharmony_ci	else if (div < 2000)
3628c2ecf20Sopenharmony_ci		data[3] = 0x80;
3638c2ecf20Sopenharmony_ci	else
3648c2ecf20Sopenharmony_ci		data[3] = 0xc0;
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
3678c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1);
3688c2ecf20Sopenharmony_ci	if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	return 0;
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic struct s5h1420_config s5h1420_config = {
3748c2ecf20Sopenharmony_ci	.demod_address = 0x53,
3758c2ecf20Sopenharmony_ci	.invert = 1,
3768c2ecf20Sopenharmony_ci	.cdclk_polarity = 1,
3778c2ecf20Sopenharmony_ci};
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistatic struct tda10086_config tda10086_config = {
3808c2ecf20Sopenharmony_ci	.demod_address = 0x0e,
3818c2ecf20Sopenharmony_ci	.invert = 0,
3828c2ecf20Sopenharmony_ci	.diseqc_tone = 1,
3838c2ecf20Sopenharmony_ci	.xtal_freq = TDA10086_XTAL_16M,
3848c2ecf20Sopenharmony_ci};
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_cistatic const struct stv0299_config alps_bsru6_config_activy = {
3878c2ecf20Sopenharmony_ci	.demod_address = 0x68,
3888c2ecf20Sopenharmony_ci	.inittab = alps_bsru6_inittab,
3898c2ecf20Sopenharmony_ci	.mclk = 88000000UL,
3908c2ecf20Sopenharmony_ci	.invert = 1,
3918c2ecf20Sopenharmony_ci	.op0_off = 1,
3928c2ecf20Sopenharmony_ci	.min_delay_ms = 100,
3938c2ecf20Sopenharmony_ci	.set_symbol_rate = alps_bsru6_set_symbol_rate,
3948c2ecf20Sopenharmony_ci};
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_cistatic const struct stv0299_config alps_bsbe1_config_activy = {
3978c2ecf20Sopenharmony_ci	.demod_address = 0x68,
3988c2ecf20Sopenharmony_ci	.inittab = alps_bsbe1_inittab,
3998c2ecf20Sopenharmony_ci	.mclk = 88000000UL,
4008c2ecf20Sopenharmony_ci	.invert = 1,
4018c2ecf20Sopenharmony_ci	.op0_off = 1,
4028c2ecf20Sopenharmony_ci	.min_delay_ms = 100,
4038c2ecf20Sopenharmony_ci	.set_symbol_rate = alps_bsbe1_set_symbol_rate,
4048c2ecf20Sopenharmony_ci};
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
4078c2ecf20Sopenharmony_ci{
4088c2ecf20Sopenharmony_ci	struct budget *budget = (struct budget *)fe->dvb->priv;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	return request_firmware(fw, name, &budget->dev->pci->dev);
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	u8 val;
4178c2ecf20Sopenharmony_ci	struct i2c_msg msg[] = {
4188c2ecf20Sopenharmony_ci		{ .addr = adr, .flags = 0, .buf = &reg, .len = 1 },
4198c2ecf20Sopenharmony_ci		{ .addr = adr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
4208c2ecf20Sopenharmony_ci	};
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	return (i2c_transfer(i2c, msg, 2) != 2) ? -EIO : val;
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic u8 read_pwm(struct budget* budget)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	u8 b = 0xff;
4288c2ecf20Sopenharmony_ci	u8 pwm;
4298c2ecf20Sopenharmony_ci	struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
4308c2ecf20Sopenharmony_ci				 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
4338c2ecf20Sopenharmony_ci		pwm = 0x48;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	return pwm;
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cistatic struct stv090x_config tt1600_stv090x_config = {
4398c2ecf20Sopenharmony_ci	.device			= STV0903,
4408c2ecf20Sopenharmony_ci	.demod_mode		= STV090x_SINGLE,
4418c2ecf20Sopenharmony_ci	.clk_mode		= STV090x_CLK_EXT,
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	.xtal			= 13500000,
4448c2ecf20Sopenharmony_ci	.address		= 0x68,
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	.ts1_mode		= STV090x_TSMODE_DVBCI,
4478c2ecf20Sopenharmony_ci	.ts2_mode		= STV090x_TSMODE_SERIAL_CONTINUOUS,
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	.repeater_level		= STV090x_RPTLEVEL_16,
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	.tuner_init		= NULL,
4528c2ecf20Sopenharmony_ci	.tuner_sleep		= NULL,
4538c2ecf20Sopenharmony_ci	.tuner_set_mode		= NULL,
4548c2ecf20Sopenharmony_ci	.tuner_set_frequency	= NULL,
4558c2ecf20Sopenharmony_ci	.tuner_get_frequency	= NULL,
4568c2ecf20Sopenharmony_ci	.tuner_set_bandwidth	= NULL,
4578c2ecf20Sopenharmony_ci	.tuner_get_bandwidth	= NULL,
4588c2ecf20Sopenharmony_ci	.tuner_set_bbgain	= NULL,
4598c2ecf20Sopenharmony_ci	.tuner_get_bbgain	= NULL,
4608c2ecf20Sopenharmony_ci	.tuner_set_refclk	= NULL,
4618c2ecf20Sopenharmony_ci	.tuner_get_status	= NULL,
4628c2ecf20Sopenharmony_ci};
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_cistatic struct stv6110x_config tt1600_stv6110x_config = {
4658c2ecf20Sopenharmony_ci	.addr			= 0x60,
4668c2ecf20Sopenharmony_ci	.refclk			= 27000000,
4678c2ecf20Sopenharmony_ci	.clk_div		= 2,
4688c2ecf20Sopenharmony_ci};
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_cistatic struct isl6423_config tt1600_isl6423_config = {
4718c2ecf20Sopenharmony_ci	.current_max		= SEC_CURRENT_515m,
4728c2ecf20Sopenharmony_ci	.curlim			= SEC_CURRENT_LIM_ON,
4738c2ecf20Sopenharmony_ci	.mod_extern		= 1,
4748c2ecf20Sopenharmony_ci	.addr			= 0x08,
4758c2ecf20Sopenharmony_ci};
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_cistatic void frontend_init(struct budget *budget)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci	(void)alps_bsbe1_config; /* avoid warning */
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci	switch(budget->dev->pci->subsystem_device) {
4828c2ecf20Sopenharmony_ci	case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
4838c2ecf20Sopenharmony_ci	case 0x1013:
4848c2ecf20Sopenharmony_ci		// try the ALPS BSRV2 first of all
4858c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
4868c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
4878c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
4888c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
4898c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
4908c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.set_tone = budget_set_tone;
4918c2ecf20Sopenharmony_ci			break;
4928c2ecf20Sopenharmony_ci		}
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci		// try the ALPS BSRU6 now
4958c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
4968c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
4978c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
4988c2ecf20Sopenharmony_ci			budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
4998c2ecf20Sopenharmony_ci			if (budget->dev->pci->subsystem_device == 0x1003 && diseqc_method == 0) {
5008c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
5018c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
5028c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.set_tone = budget_set_tone;
5038c2ecf20Sopenharmony_ci			}
5048c2ecf20Sopenharmony_ci			break;
5058c2ecf20Sopenharmony_ci		}
5068c2ecf20Sopenharmony_ci		break;
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
5118c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5128c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
5138c2ecf20Sopenharmony_ci			break;
5148c2ecf20Sopenharmony_ci		}
5158c2ecf20Sopenharmony_ci		break;
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
5208c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5218c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
5228c2ecf20Sopenharmony_ci			budget->dvb_frontend->tuner_priv = NULL;
5238c2ecf20Sopenharmony_ci			break;
5248c2ecf20Sopenharmony_ci		}
5258c2ecf20Sopenharmony_ci		break;
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	case 0x4f52: /* Cards based on Philips Semi Sylt PCI ref. design */
5288c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
5298c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5308c2ecf20Sopenharmony_ci			printk(KERN_INFO "budget: tuner ALPS BSRU6 in Philips Semi. Sylt detected\n");
5318c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
5328c2ecf20Sopenharmony_ci			budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
5338c2ecf20Sopenharmony_ci			break;
5348c2ecf20Sopenharmony_ci		}
5358c2ecf20Sopenharmony_ci		break;
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
5388c2ecf20Sopenharmony_ci	{
5398c2ecf20Sopenharmony_ci		int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci		if (subtype < 0)
5428c2ecf20Sopenharmony_ci			break;
5438c2ecf20Sopenharmony_ci		/* fixme: find a better way to identify the card */
5448c2ecf20Sopenharmony_ci		if (subtype < 0x36) {
5458c2ecf20Sopenharmony_ci			/* assume ALPS BSRU6 */
5468c2ecf20Sopenharmony_ci			budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config_activy, &budget->i2c_adap);
5478c2ecf20Sopenharmony_ci			if (budget->dvb_frontend) {
5488c2ecf20Sopenharmony_ci				printk(KERN_INFO "budget: tuner ALPS BSRU6 detected\n");
5498c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
5508c2ecf20Sopenharmony_ci				budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
5518c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
5528c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
5538c2ecf20Sopenharmony_ci				break;
5548c2ecf20Sopenharmony_ci			}
5558c2ecf20Sopenharmony_ci		} else {
5568c2ecf20Sopenharmony_ci			/* assume ALPS BSBE1 */
5578c2ecf20Sopenharmony_ci			/* reset tuner */
5588c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTLO);
5598c2ecf20Sopenharmony_ci			msleep(50);
5608c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTHI);
5618c2ecf20Sopenharmony_ci			msleep(250);
5628c2ecf20Sopenharmony_ci			budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config_activy, &budget->i2c_adap);
5638c2ecf20Sopenharmony_ci			if (budget->dvb_frontend) {
5648c2ecf20Sopenharmony_ci				printk(KERN_INFO "budget: tuner ALPS BSBE1 detected\n");
5658c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
5668c2ecf20Sopenharmony_ci				budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
5678c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
5688c2ecf20Sopenharmony_ci				budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
5698c2ecf20Sopenharmony_ci				break;
5708c2ecf20Sopenharmony_ci			}
5718c2ecf20Sopenharmony_ci		}
5728c2ecf20Sopenharmony_ci		break;
5738c2ecf20Sopenharmony_ci	}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci	case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
5768c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
5778c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5788c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
5798c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
5808c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
5818c2ecf20Sopenharmony_ci		}
5828c2ecf20Sopenharmony_ci		break;
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci	case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
5858c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
5868c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5878c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
5888c2ecf20Sopenharmony_ci			budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
5898c2ecf20Sopenharmony_ci		}
5908c2ecf20Sopenharmony_ci		break;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
5938c2ecf20Sopenharmony_ci		budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
5948c2ecf20Sopenharmony_ci		if (budget->dvb_frontend) {
5958c2ecf20Sopenharmony_ci			budget->dvb_frontend->tuner_priv = &tuner_address_grundig_29504_401_activy;
5968c2ecf20Sopenharmony_ci			budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
5978c2ecf20Sopenharmony_ci		}
5988c2ecf20Sopenharmony_ci		break;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
6018c2ecf20Sopenharmony_ci	{
6028c2ecf20Sopenharmony_ci		struct dvb_frontend *fe;
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ci		fe = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
6058c2ecf20Sopenharmony_ci		if (fe) {
6068c2ecf20Sopenharmony_ci			fe->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
6078c2ecf20Sopenharmony_ci			budget->dvb_frontend = fe;
6088c2ecf20Sopenharmony_ci			if (dvb_attach(lnbp21_attach, fe, &budget->i2c_adap,
6098c2ecf20Sopenharmony_ci				       0, 0) == NULL) {
6108c2ecf20Sopenharmony_ci				printk("%s: No LNBP21 found!\n", __func__);
6118c2ecf20Sopenharmony_ci				goto error_out;
6128c2ecf20Sopenharmony_ci			}
6138c2ecf20Sopenharmony_ci			break;
6148c2ecf20Sopenharmony_ci		}
6158c2ecf20Sopenharmony_ci	}
6168c2ecf20Sopenharmony_ci		fallthrough;
6178c2ecf20Sopenharmony_ci	case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
6188c2ecf20Sopenharmony_ci	{
6198c2ecf20Sopenharmony_ci		struct dvb_frontend *fe;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci		// gpio2 is connected to CLB - reset it + leave it high
6228c2ecf20Sopenharmony_ci		saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
6238c2ecf20Sopenharmony_ci		msleep(1);
6248c2ecf20Sopenharmony_ci		saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
6258c2ecf20Sopenharmony_ci		msleep(1);
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci		fe = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
6288c2ecf20Sopenharmony_ci		if (fe) {
6298c2ecf20Sopenharmony_ci			budget->dvb_frontend = fe;
6308c2ecf20Sopenharmony_ci			if (dvb_attach(tda826x_attach, fe, 0x60,
6318c2ecf20Sopenharmony_ci				       &budget->i2c_adap, 0) == NULL)
6328c2ecf20Sopenharmony_ci				printk("%s: No tda826x found!\n", __func__);
6338c2ecf20Sopenharmony_ci			if (dvb_attach(lnbp21_attach, fe,
6348c2ecf20Sopenharmony_ci				       &budget->i2c_adap, 0, 0) == NULL) {
6358c2ecf20Sopenharmony_ci				printk("%s: No LNBP21 found!\n", __func__);
6368c2ecf20Sopenharmony_ci				goto error_out;
6378c2ecf20Sopenharmony_ci			}
6388c2ecf20Sopenharmony_ci			break;
6398c2ecf20Sopenharmony_ci		}
6408c2ecf20Sopenharmony_ci	}
6418c2ecf20Sopenharmony_ci		fallthrough;
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	case 0x101c: { /* TT S2-1600 */
6448c2ecf20Sopenharmony_ci			const struct stv6110x_devctl *ctl;
6458c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
6468c2ecf20Sopenharmony_ci			msleep(50);
6478c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
6488c2ecf20Sopenharmony_ci			msleep(250);
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci			budget->dvb_frontend = dvb_attach(stv090x_attach,
6518c2ecf20Sopenharmony_ci							  &tt1600_stv090x_config,
6528c2ecf20Sopenharmony_ci							  &budget->i2c_adap,
6538c2ecf20Sopenharmony_ci							  STV090x_DEMODULATOR_0);
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci			if (budget->dvb_frontend) {
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci				ctl = dvb_attach(stv6110x_attach,
6588c2ecf20Sopenharmony_ci						 budget->dvb_frontend,
6598c2ecf20Sopenharmony_ci						 &tt1600_stv6110x_config,
6608c2ecf20Sopenharmony_ci						 &budget->i2c_adap);
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci				if (ctl) {
6638c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_init	  = ctl->tuner_init;
6648c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_sleep	  = ctl->tuner_sleep;
6658c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_mode	  = ctl->tuner_set_mode;
6668c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
6678c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
6688c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
6698c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
6708c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_bbgain	  = ctl->tuner_set_bbgain;
6718c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_bbgain	  = ctl->tuner_get_bbgain;
6728c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_refclk	  = ctl->tuner_set_refclk;
6738c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_status	  = ctl->tuner_get_status;
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci					/* call the init function once to initialize
6768c2ecf20Sopenharmony_ci					   tuner's clock output divider and demod's
6778c2ecf20Sopenharmony_ci					   master clock */
6788c2ecf20Sopenharmony_ci					if (budget->dvb_frontend->ops.init)
6798c2ecf20Sopenharmony_ci						budget->dvb_frontend->ops.init(budget->dvb_frontend);
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci					if (dvb_attach(isl6423_attach,
6828c2ecf20Sopenharmony_ci						       budget->dvb_frontend,
6838c2ecf20Sopenharmony_ci						       &budget->i2c_adap,
6848c2ecf20Sopenharmony_ci						       &tt1600_isl6423_config) == NULL) {
6858c2ecf20Sopenharmony_ci						printk(KERN_ERR "%s: No Intersil ISL6423 found!\n", __func__);
6868c2ecf20Sopenharmony_ci						goto error_out;
6878c2ecf20Sopenharmony_ci					}
6888c2ecf20Sopenharmony_ci				} else {
6898c2ecf20Sopenharmony_ci					printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
6908c2ecf20Sopenharmony_ci					goto error_out;
6918c2ecf20Sopenharmony_ci				}
6928c2ecf20Sopenharmony_ci			}
6938c2ecf20Sopenharmony_ci		}
6948c2ecf20Sopenharmony_ci		break;
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	case 0x1020: { /* Omicom S2 */
6978c2ecf20Sopenharmony_ci			const struct stv6110x_devctl *ctl;
6988c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
6998c2ecf20Sopenharmony_ci			msleep(50);
7008c2ecf20Sopenharmony_ci			saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
7018c2ecf20Sopenharmony_ci			msleep(250);
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci			budget->dvb_frontend = dvb_attach(stv090x_attach,
7048c2ecf20Sopenharmony_ci							  &tt1600_stv090x_config,
7058c2ecf20Sopenharmony_ci							  &budget->i2c_adap,
7068c2ecf20Sopenharmony_ci							  STV090x_DEMODULATOR_0);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci			if (budget->dvb_frontend) {
7098c2ecf20Sopenharmony_ci				printk(KERN_INFO "budget: Omicom S2 detected\n");
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci				ctl = dvb_attach(stv6110x_attach,
7128c2ecf20Sopenharmony_ci						 budget->dvb_frontend,
7138c2ecf20Sopenharmony_ci						 &tt1600_stv6110x_config,
7148c2ecf20Sopenharmony_ci						 &budget->i2c_adap);
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci				if (ctl) {
7178c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_init	  = ctl->tuner_init;
7188c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_sleep	  = ctl->tuner_sleep;
7198c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_mode	  = ctl->tuner_set_mode;
7208c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
7218c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
7228c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
7238c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
7248c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_bbgain	  = ctl->tuner_set_bbgain;
7258c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_bbgain	  = ctl->tuner_get_bbgain;
7268c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_set_refclk	  = ctl->tuner_set_refclk;
7278c2ecf20Sopenharmony_ci					tt1600_stv090x_config.tuner_get_status	  = ctl->tuner_get_status;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci					/* call the init function once to initialize
7308c2ecf20Sopenharmony_ci					   tuner's clock output divider and demod's
7318c2ecf20Sopenharmony_ci					   master clock */
7328c2ecf20Sopenharmony_ci					if (budget->dvb_frontend->ops.init)
7338c2ecf20Sopenharmony_ci						budget->dvb_frontend->ops.init(budget->dvb_frontend);
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci					if (dvb_attach(lnbh24_attach,
7368c2ecf20Sopenharmony_ci							budget->dvb_frontend,
7378c2ecf20Sopenharmony_ci							&budget->i2c_adap,
7388c2ecf20Sopenharmony_ci							LNBH24_PCL | LNBH24_TTX,
7398c2ecf20Sopenharmony_ci							LNBH24_TEN, 0x14>>1) == NULL) {
7408c2ecf20Sopenharmony_ci						printk(KERN_ERR
7418c2ecf20Sopenharmony_ci						"No LNBH24 found!\n");
7428c2ecf20Sopenharmony_ci						goto error_out;
7438c2ecf20Sopenharmony_ci					}
7448c2ecf20Sopenharmony_ci				} else {
7458c2ecf20Sopenharmony_ci					printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
7468c2ecf20Sopenharmony_ci					goto error_out;
7478c2ecf20Sopenharmony_ci				}
7488c2ecf20Sopenharmony_ci			}
7498c2ecf20Sopenharmony_ci		}
7508c2ecf20Sopenharmony_ci		break;
7518c2ecf20Sopenharmony_ci	}
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	if (budget->dvb_frontend == NULL) {
7548c2ecf20Sopenharmony_ci		printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
7558c2ecf20Sopenharmony_ci		       budget->dev->pci->vendor,
7568c2ecf20Sopenharmony_ci		       budget->dev->pci->device,
7578c2ecf20Sopenharmony_ci		       budget->dev->pci->subsystem_vendor,
7588c2ecf20Sopenharmony_ci		       budget->dev->pci->subsystem_device);
7598c2ecf20Sopenharmony_ci	} else {
7608c2ecf20Sopenharmony_ci		if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
7618c2ecf20Sopenharmony_ci			goto error_out;
7628c2ecf20Sopenharmony_ci	}
7638c2ecf20Sopenharmony_ci	return;
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cierror_out:
7668c2ecf20Sopenharmony_ci	printk("budget: Frontend registration failed!\n");
7678c2ecf20Sopenharmony_ci	dvb_frontend_detach(budget->dvb_frontend);
7688c2ecf20Sopenharmony_ci	budget->dvb_frontend = NULL;
7698c2ecf20Sopenharmony_ci	return;
7708c2ecf20Sopenharmony_ci}
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_cistatic int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
7738c2ecf20Sopenharmony_ci{
7748c2ecf20Sopenharmony_ci	struct budget *budget = NULL;
7758c2ecf20Sopenharmony_ci	int err;
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
7788c2ecf20Sopenharmony_ci	if( NULL == budget ) {
7798c2ecf20Sopenharmony_ci		return -ENOMEM;
7808c2ecf20Sopenharmony_ci	}
7818c2ecf20Sopenharmony_ci
7828c2ecf20Sopenharmony_ci	dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci	dev->ext_priv = budget;
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
7878c2ecf20Sopenharmony_ci	if (err) {
7888c2ecf20Sopenharmony_ci		printk("==> failed\n");
7898c2ecf20Sopenharmony_ci		kfree (budget);
7908c2ecf20Sopenharmony_ci		return err;
7918c2ecf20Sopenharmony_ci	}
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	budget->dvb_adapter.priv = budget;
7948c2ecf20Sopenharmony_ci	frontend_init(budget);
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci	ttpci_budget_init_hooks(budget);
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	return 0;
7998c2ecf20Sopenharmony_ci}
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_cistatic int budget_detach (struct saa7146_dev* dev)
8028c2ecf20Sopenharmony_ci{
8038c2ecf20Sopenharmony_ci	struct budget *budget = (struct budget*) dev->ext_priv;
8048c2ecf20Sopenharmony_ci	int err;
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	if (budget->dvb_frontend) {
8078c2ecf20Sopenharmony_ci		dvb_unregister_frontend(budget->dvb_frontend);
8088c2ecf20Sopenharmony_ci		dvb_frontend_detach(budget->dvb_frontend);
8098c2ecf20Sopenharmony_ci	}
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_ci	err = ttpci_budget_deinit (budget);
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	kfree (budget);
8148c2ecf20Sopenharmony_ci	dev->ext_priv = NULL;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	return err;
8178c2ecf20Sopenharmony_ci}
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_cistatic struct saa7146_extension budget_extension;
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(ttbs,	"TT-Budget/WinTV-NOVA-S  PCI",	BUDGET_TT);
8228c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(ttbc,	"TT-Budget/WinTV-NOVA-C  PCI",	BUDGET_TT);
8238c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(ttbt,	"TT-Budget/WinTV-NOVA-T  PCI",	BUDGET_TT);
8248c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(satel,	"SATELCO Multimedia PCI",	BUDGET_TT_HW_DISEQC);
8258c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
8268c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(tt1600, "TT-Budget S2-1600 PCI", BUDGET_TT);
8278c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
8288c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
8298c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(fsact,	 "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
8308c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
8318c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(omicom, "Omicom S2 PCI", BUDGET_TT);
8328c2ecf20Sopenharmony_ciMAKE_BUDGET_INFO(sylt,   "Philips Semi Sylt PCI", BUDGET_TT_HW_DISEQC);
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_cistatic const struct pci_device_id pci_tbl[] = {
8358c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1003),
8368c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(ttbc,  0x13c2, 0x1004),
8378c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(ttbt,  0x13c2, 0x1005),
8388c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
8398c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1016),
8408c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
8418c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(tt1600, 0x13c2, 0x101c),
8428c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
8438c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
8448c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
8458c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
8468c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(omicom, 0x14c4, 0x1020),
8478c2ecf20Sopenharmony_ci	MAKE_EXTENSION_PCI(sylt, 0x1131, 0x4f52),
8488c2ecf20Sopenharmony_ci	{
8498c2ecf20Sopenharmony_ci		.vendor    = 0,
8508c2ecf20Sopenharmony_ci	}
8518c2ecf20Sopenharmony_ci};
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, pci_tbl);
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_cistatic struct saa7146_extension budget_extension = {
8568c2ecf20Sopenharmony_ci	.name		= "budget dvb",
8578c2ecf20Sopenharmony_ci	.flags		= SAA7146_USE_I2C_IRQ,
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci	.module		= THIS_MODULE,
8608c2ecf20Sopenharmony_ci	.pci_tbl	= pci_tbl,
8618c2ecf20Sopenharmony_ci	.attach		= budget_attach,
8628c2ecf20Sopenharmony_ci	.detach		= budget_detach,
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci	.irq_mask	= MASK_10,
8658c2ecf20Sopenharmony_ci	.irq_func	= ttpci_budget_irq10_handler,
8668c2ecf20Sopenharmony_ci};
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_cistatic int __init budget_init(void)
8698c2ecf20Sopenharmony_ci{
8708c2ecf20Sopenharmony_ci	return saa7146_register_extension(&budget_extension);
8718c2ecf20Sopenharmony_ci}
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_cistatic void __exit budget_exit(void)
8748c2ecf20Sopenharmony_ci{
8758c2ecf20Sopenharmony_ci	saa7146_unregister_extension(&budget_extension);
8768c2ecf20Sopenharmony_ci}
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_cimodule_init(budget_init);
8798c2ecf20Sopenharmony_cimodule_exit(budget_exit);
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
8828c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
8838c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("driver for the SAA7146 based so-called budget PCI DVB cards by Siemens, Technotrend, Hauppauge");
884