summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/saa7134/saa7134-dvb.c
blob: 325631fd0b5758b40cc6cd11c597fde0f3da5278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * $Id: saa7134-dvb.c,v 1.7 2005/01/04 16:31:20 kraxel Exp $
 *
 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/init.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/suspend.h>

#include "saa7134-reg.h"
#include "saa7134.h"

#include "dvb-pll.h"
#include "mt352.h"
#include "mt352_priv.h" /* FIXME */

MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
MODULE_LICENSE("GPL");

/* ------------------------------------------------------------------ */

static int mt352_pinnacle_init(struct dvb_frontend* fe)
{
	static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x39 };
	static u8 reset []         = { RESET,      0x80 };
	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
	static u8 agc_cfg []       = { AGC_TARGET, 0x20, 0x20 };
	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
#if 0
	// general purpose port pins
	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
#endif
	struct saa7134_dev *dev= fe->dvb->priv;

	printk("%s: %s called\n",dev->name,__FUNCTION__);

	mt352_write(fe, clock_config,   sizeof(clock_config));
	udelay(200);
	mt352_write(fe, reset,          sizeof(reset));
	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));

#if 0
	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
#endif
	return 0;
}

static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
				  struct dvb_frontend_parameters* params,
				  u8* pllbuf)
{
	static u8 buf[][3] = {
		/* set bandwidth (ADC frequency is 20.333 MHz) */
		[ BANDWIDTH_6_MHZ ] = { TRL_NOMINAL_RATE_1, 0x56, 0x55 },
		[ BANDWIDTH_7_MHZ ] = { TRL_NOMINAL_RATE_1, 0x64, 0xB8 },
		[ BANDWIDTH_8_MHZ ] = { TRL_NOMINAL_RATE_1, 0x73, 0x1C },
	};
	struct saa7134_dev *dev= fe->dvb->priv;
	struct v4l2_frequency f;
	int bw = params->u.ofdm.bandwidth;

	printk("%s: %s called (freq=%d,bw=%d)\n",dev->name,__FUNCTION__,
	       params->frequency,bw);

	/* set frequency */
	f.tuner     = 0;
	f.type      = V4L2_TUNER_ANALOG_TV; /* FIXME */
	f.frequency = params->frequency / 1000 * 16 / 1000;
	saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
	memset(pllbuf,0,5);

	if (bw < ARRAY_SIZE(buf) && NULL != buf[bw]) {
#if 1
		/* dirty hack time -- fixup mt352 buffer which has
		 * adc freq 20.48 MHz values hardcoded */
		pllbuf[-4] = buf[bw][1];
		pllbuf[-3] = buf[bw][2];
		pllbuf[-2] = 0x31; /* if 36.1667 + adc 20.333 */
		pllbuf[-1] = 0xD9;
#else
		mt352_write(fe, buf[bw], 3);
#endif
	}
		
	return 0;
}

static struct mt352_config pinnacle_300i = {
	.demod_address = 0x3c >> 1,
	.demod_init    = mt352_pinnacle_init,
	.pll_set       = mt352_pinnacle_pll_set,
};

/* ------------------------------------------------------------------ */

static int dvb_init(struct saa7134_dev *dev)
{
	/* init struct videobuf_dvb */
	dev->dvb.name = dev->name;
	videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
			    dev->pci, &dev->slock,
			    V4L2_BUF_TYPE_VIDEO_CAPTURE,
			    V4L2_FIELD_TOP,
			    sizeof(struct saa7134_buf),
			    dev);

	switch (dev->board) {
	case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
		printk("%s: pinnacle 300i dvb setup\n",dev->name);
		dev->dvb.frontend = mt352_attach(&pinnacle_300i,
						 &dev->i2c_adap);
		break;
	default:
		printk("%s: Huh? unknown DVB card?\n",dev->name);
		break;
	}

	if (NULL == dev->dvb.frontend) {
		printk("%s: frontend initialization failed\n",dev->name);
		return -1;
	}

	/* register everything else */
	return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
}

static int dvb_fini(struct saa7134_dev *dev)
{
	printk("%s: %s\n",dev->name,__FUNCTION__);
	videobuf_dvb_unregister(&dev->dvb);
	return 0;
}

static struct saa7134_mpeg_ops dvb_ops = {
	.type          = SAA7134_MPEG_DVB,
	.init          = dvb_init,
	.fini          = dvb_fini,
};

static int __init dvb_register(void)
{
	return saa7134_ts_register(&dvb_ops);
}

static void __exit dvb_unregister(void)
{
	saa7134_ts_unregister(&dvb_ops);
}

module_init(dvb_register);
module_exit(dvb_unregister);

/* ------------------------------------------------------------------ */
/*
 * Local variables:
 * c-basic-offset: 8
 * compile-command: "make DVB=1"
 * End:
 */