2 * $Id: saa7134-dvb.c,v 1.12 2005/02/18 12:28:29 kraxel Exp $
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/init.h>
22 #include <linux/list.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/delay.h>
27 #include <linux/kthread.h>
28 #include <linux/suspend.h>
30 #include "saa7134-reg.h"
35 #include "mt352_priv.h" /* FIXME */
38 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
39 MODULE_LICENSE("GPL");
41 static unsigned int antenna_pwr
= 0;
42 module_param(antenna_pwr
, int, 0444);
43 MODULE_PARM_DESC(antenna_pwr
,"enable antenna power (Pinnacle 300i)");
45 /* ------------------------------------------------------------------ */
47 static int pinnacle_antenna_pwr(struct saa7134_dev
*dev
, int on
)
52 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
53 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
57 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 26));
58 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
61 saa_setl(SAA7134_GPIO_GPMODE0
>> 2, (1 << 28));
62 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
64 saa_setl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 28));
66 ok
= saa_readl(SAA7134_GPIO_GPSTATUS0
) & (1 << 27);
67 printk("%s: %s %s\n", dev
->name
, __FUNCTION__
,
71 saa_clearl(SAA7134_GPIO_GPSTATUS0
>> 2, (1 << 26));
75 static int mt352_pinnacle_init(struct dvb_frontend
* fe
)
77 static u8 clock_config
[] = { CLOCK_CTL
, 0x3d, 0x28 };
78 static u8 reset
[] = { RESET
, 0x80 };
79 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
80 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0xa0 };
81 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x31 };
82 static u8 fsm_ctl_cfg
[] = { 0x7b, 0x04 };
83 static u8 gpp_ctl_cfg
[] = { GPP_CTL
, 0x0f };
84 static u8 scan_ctl_cfg
[] = { SCAN_CTL
, 0x0d };
85 static u8 irq_cfg
[] = { INTERRUPT_EN_0
, 0x00, 0x00, 0x00, 0x00 };
86 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
88 printk("%s: %s called\n",dev
->name
,__FUNCTION__
);
90 mt352_write(fe
, clock_config
, sizeof(clock_config
));
92 mt352_write(fe
, reset
, sizeof(reset
));
93 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
94 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
95 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
96 mt352_write(fe
, gpp_ctl_cfg
, sizeof(gpp_ctl_cfg
));
98 mt352_write(fe
, fsm_ctl_cfg
, sizeof(fsm_ctl_cfg
));
99 mt352_write(fe
, scan_ctl_cfg
, sizeof(scan_ctl_cfg
));
100 mt352_write(fe
, irq_cfg
, sizeof(irq_cfg
));
104 static int mt352_pinnacle_pll_set(struct dvb_frontend
* fe
,
105 struct dvb_frontend_parameters
* params
,
108 static int on
= TDA9887_PRESENT
| TDA9887_PORT2_INACTIVE
;
109 static int off
= TDA9887_PRESENT
| TDA9887_PORT2_ACTIVE
;
110 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
111 struct v4l2_frequency f
;
113 /* set frequency (mt2050) */
115 f
.type
= V4L2_TUNER_DIGITAL_TV
;
116 f
.frequency
= params
->frequency
/ 1000 * 16 / 1000;
117 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&on
);
118 saa7134_i2c_call_clients(dev
,VIDIOC_S_FREQUENCY
,&f
);
119 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&off
);
121 pinnacle_antenna_pwr(dev
, antenna_pwr
);
124 mt352_pinnacle_init(fe
);
133 static struct mt352_config pinnacle_300i
= {
134 .demod_address
= 0x3c >> 1,
138 .demod_init
= mt352_pinnacle_init
,
139 .pll_set
= mt352_pinnacle_pll_set
,
142 /* ------------------------------------------------------------------ */
144 static int medion_cardbus_init(struct dvb_frontend
* fe
)
146 /* anything to do here ??? */
150 static int medion_cardbus_pll_set(struct dvb_frontend
* fe
,
151 struct dvb_frontend_parameters
* params
)
153 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
154 struct v4l2_frequency f
;
157 * this instructs tuner.o to set the frequency, the call will
158 * end up in tuner_command(), VIDIOC_S_FREQUENCY switch.
159 * tda9887.o will see that as well.
162 f
.type
= V4L2_TUNER_DIGITAL_TV
;
163 f
.frequency
= params
->frequency
/ 1000 * 16 / 1000;
164 saa7134_i2c_call_clients(dev
,VIDIOC_S_FREQUENCY
,&f
);
168 static int fe_request_firmware(struct dvb_frontend
* fe
,
169 const struct firmware
**fw
, char* name
)
171 struct saa7134_dev
*dev
= fe
->dvb
->priv
;
172 return request_firmware(fw
, name
, &dev
->pci
->dev
);
175 static struct tda1004x_config medion_cardbus
= {
176 .demod_address
= 0x08, /* not sure this is correct */
179 .pll_init
= medion_cardbus_init
,
180 .pll_set
= medion_cardbus_pll_set
,
181 .request_firmware
= fe_request_firmware
,
184 /* ------------------------------------------------------------------ */
186 static int dvb_init(struct saa7134_dev
*dev
)
188 /* init struct videobuf_dvb */
189 dev
->ts
.nr_bufs
= 32;
190 dev
->ts
.nr_packets
= 32*4;
191 dev
->dvb
.name
= dev
->name
;
192 videobuf_queue_init(&dev
->dvb
.dvbq
, &saa7134_ts_qops
,
193 dev
->pci
, &dev
->slock
,
194 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
195 V4L2_FIELD_ALTERNATE
,
196 sizeof(struct saa7134_buf
),
199 switch (dev
->board
) {
200 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
201 printk("%s: pinnacle 300i dvb setup\n",dev
->name
);
202 dev
->dvb
.frontend
= mt352_attach(&pinnacle_300i
,
205 case SAA7134_BOARD_MD7134
:
206 dev
->dvb
.frontend
= tda10046_attach(&medion_cardbus
,
208 if (NULL
== dev
->dvb
.frontend
)
209 printk("%s: Hmm, looks like this is the old MD7134 "
210 "version without DVB-T support\n",dev
->name
);
213 printk("%s: Huh? unknown DVB card?\n",dev
->name
);
217 if (NULL
== dev
->dvb
.frontend
) {
218 printk("%s: frontend initialization failed\n",dev
->name
);
222 /* register everything else */
223 return videobuf_dvb_register(&dev
->dvb
, THIS_MODULE
, dev
);
226 static int dvb_fini(struct saa7134_dev
*dev
)
228 static int on
= TDA9887_PRESENT
| TDA9887_PORT2_INACTIVE
;
230 printk("%s: %s\n",dev
->name
,__FUNCTION__
);
232 switch (dev
->board
) {
233 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL
:
234 /* otherwise we don't detect the tuner on next insmod */
235 saa7134_i2c_call_clients(dev
,TDA9887_SET_CONFIG
,&on
);
238 videobuf_dvb_unregister(&dev
->dvb
);
242 static struct saa7134_mpeg_ops dvb_ops
= {
243 .type
= SAA7134_MPEG_DVB
,
248 static int __init
dvb_register(void)
250 return saa7134_ts_register(&dvb_ops
);
253 static void __exit
dvb_unregister(void)
255 saa7134_ts_unregister(&dvb_ops
);
258 module_init(dvb_register
);
259 module_exit(dvb_unregister
);
261 /* ------------------------------------------------------------------ */