aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/ttpci
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/ttpci')
-rw-r--r--drivers/media/dvb/ttpci/Kconfig159
-rw-r--r--drivers/media/dvb/ttpci/Makefile21
-rw-r--r--drivers/media/dvb/ttpci/av7110.c2939
-rw-r--r--drivers/media/dvb/ttpci/av7110.h314
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c1626
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.h30
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c387
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.h14
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c1208
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.h495
-rw-r--r--drivers/media/dvb/ttpci/av7110_ipack.c403
-rw-r--r--drivers/media/dvb/ttpci/av7110_ipack.h12
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c415
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c966
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c1640
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c1591
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c602
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c680
-rw-r--r--drivers/media/dvb/ttpci/budget.c871
-rw-r--r--drivers/media/dvb/ttpci/budget.h124
-rw-r--r--drivers/media/dvb/ttpci/ttpci-eeprom.c176
-rw-r--r--drivers/media/dvb/ttpci/ttpci-eeprom.h34
22 files changed, 0 insertions, 14707 deletions
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
deleted file mode 100644
index 9d83ced69dd6..000000000000
--- a/drivers/media/dvb/ttpci/Kconfig
+++ /dev/null
@@ -1,159 +0,0 @@
1config TTPCI_EEPROM
2 tristate
3 depends on I2C
4 default n
5
6config DVB_AV7110
7 tristate "AV7110 cards"
8 depends on DVB_CORE && PCI && I2C
9 select TTPCI_EEPROM
10 select VIDEO_SAA7146_VV
11 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
12 select DVB_VES1820 if !DVB_FE_CUSTOMISE
13 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
14 select DVB_STV0299 if !DVB_FE_CUSTOMISE
15 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
16 select DVB_SP8870 if !DVB_FE_CUSTOMISE
17 select DVB_STV0297 if !DVB_FE_CUSTOMISE
18 select DVB_L64781 if !DVB_FE_CUSTOMISE
19 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
20 help
21 Support for SAA7146 and AV7110 based DVB cards as produced
22 by Fujitsu-Siemens, Technotrend, Hauppauge and others.
23
24 This driver only supports the fullfeatured cards with
25 onboard MPEG2 decoder.
26
27 This driver needs an external firmware. Please use the script
28 "<kerneldir>/Documentation/dvb/get_dvb_firmware av7110" to
29 download/extract it, and then copy it to /usr/lib/hotplug/firmware
30 or /lib/firmware (depending on configuration of firmware hotplug).
31
32 Alternatively, you can download the file and use the kernel's
33 EXTRA_FIRMWARE configuration option to build it into your
34 kernel image by adding the filename to the EXTRA_FIRMWARE
35 configuration option string.
36
37 Say Y if you own such a card and want to use it.
38
39config DVB_AV7110_OSD
40 bool "AV7110 OSD support"
41 depends on DVB_AV7110
42 default y if DVB_AV7110=y || DVB_AV7110=m
43 help
44 The AV7110 firmware provides some code to generate an OnScreenDisplay
45 on the video output. This is kind of nonstandard and not guaranteed to
46 be maintained.
47
48 Anyway, some popular DVB software like VDR uses this OSD to render
49 its menus, so say Y if you want to use this software.
50
51 All other people say N.
52
53config DVB_BUDGET_CORE
54 tristate "SAA7146 DVB cards (aka Budget, Nova-PCI)"
55 depends on DVB_CORE && PCI && I2C
56 select VIDEO_SAA7146
57 select TTPCI_EEPROM
58 help
59 Support for simple SAA7146 based DVB cards
60 (so called Budget- or Nova-PCI cards) without onboard
61 MPEG2 decoder.
62
63config DVB_BUDGET
64 tristate "Budget cards"
65 depends on DVB_BUDGET_CORE && I2C
66 select DVB_STV0299 if !DVB_FE_CUSTOMISE
67 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
68 select DVB_VES1820 if !DVB_FE_CUSTOMISE
69 select DVB_L64781 if !DVB_FE_CUSTOMISE
70 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
71 select DVB_S5H1420 if !DVB_FE_CUSTOMISE
72 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
73 select DVB_TDA826X if !DVB_FE_CUSTOMISE
74 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
75 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
76 select DVB_ISL6423 if !DVB_FE_CUSTOMISE
77 select DVB_STV090x if !DVB_FE_CUSTOMISE
78 select DVB_STV6110x if !DVB_FE_CUSTOMISE
79 help
80 Support for simple SAA7146 based DVB cards (so called Budget-
81 or Nova-PCI cards) without onboard MPEG2 decoder, and without
82 analog inputs or an onboard Common Interface connector.
83
84 Say Y if you own such a card and want to use it.
85
86 To compile this driver as a module, choose M here: the
87 module will be called budget.
88
89config DVB_BUDGET_CI
90 tristate "Budget cards with onboard CI connector"
91 depends on DVB_BUDGET_CORE && I2C
92 select DVB_STV0297 if !DVB_FE_CUSTOMISE
93 select DVB_STV0299 if !DVB_FE_CUSTOMISE
94 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
95 select DVB_STB0899 if !DVB_FE_CUSTOMISE
96 select DVB_STB6100 if !DVB_FE_CUSTOMISE
97 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
98 select DVB_STV0288 if !DVB_FE_CUSTOMISE
99 select DVB_STB6000 if !DVB_FE_CUSTOMISE
100 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
101 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
102 depends on RC_CORE
103 help
104 Support for simple SAA7146 based DVB cards
105 (so called Budget- or Nova-PCI cards) without onboard
106 MPEG2 decoder, but with onboard Common Interface connector.
107
108 Note: The Common Interface is not yet supported by this driver
109 due to lack of information from the vendor.
110
111 Say Y if you own such a card and want to use it.
112
113 To compile this driver as a module, choose M here: the
114 module will be called budget-ci.
115
116config DVB_BUDGET_AV
117 tristate "Budget cards with analog video inputs"
118 depends on DVB_BUDGET_CORE && I2C
119 select VIDEO_SAA7146_VV
120 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
121 select DVB_PLL if !DVB_FE_CUSTOMISE
122 select DVB_STV0299 if !DVB_FE_CUSTOMISE
123 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
124 select DVB_TDA10021 if !DVB_FE_CUSTOMISE
125 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
126 select DVB_STB0899 if !DVB_FE_CUSTOMISE
127 select DVB_TDA8261 if !DVB_FE_CUSTOMISE
128 select DVB_TUA6100 if !DVB_FE_CUSTOMISE
129 help
130 Support for simple SAA7146 based DVB cards
131 (so called Budget- or Nova-PCI cards) without onboard
132 MPEG2 decoder, but with one or more analog video inputs.
133
134 Say Y if you own such a card and want to use it.
135
136 To compile this driver as a module, choose M here: the
137 module will be called budget-av.
138
139config DVB_BUDGET_PATCH
140 tristate "AV7110 cards with Budget Patch"
141 depends on DVB_BUDGET_CORE && I2C
142 depends on DVB_AV7110
143 select DVB_STV0299 if !DVB_FE_CUSTOMISE
144 select DVB_VES1X93 if !DVB_FE_CUSTOMISE
145 select DVB_TDA8083 if !DVB_FE_CUSTOMISE
146 help
147 Support for Budget Patch (full TS) modification on
148 SAA7146+AV7110 based cards (DVB-S cards). This
149 driver doesn't use onboard MPEG2 decoder. The
150 card is driven in Budget-only mode. Card is
151 required to have loaded firmware to tune properly.
152 Firmware can be loaded by insertion and removal of
153 standard AV7110 driver prior to loading this
154 driver.
155
156 Say Y if you own such a card and want to use it.
157
158 To compile this driver as a module, choose M here: the
159 module will be called budget-patch.
diff --git a/drivers/media/dvb/ttpci/Makefile b/drivers/media/dvb/ttpci/Makefile
deleted file mode 100644
index 22a235f3cc48..000000000000
--- a/drivers/media/dvb/ttpci/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
1#
2# Makefile for the kernel SAA7146 FULL TS DVB device driver
3# and the AV7110 DVB device driver
4#
5
6dvb-ttpci-objs := av7110_hw.o av7110_v4l.o av7110_av.o av7110_ca.o av7110.o av7110_ipack.o
7
8ifdef CONFIG_INPUT_EVDEV
9dvb-ttpci-objs += av7110_ir.o
10endif
11
12obj-$(CONFIG_TTPCI_EEPROM) += ttpci-eeprom.o
13obj-$(CONFIG_DVB_BUDGET_CORE) += budget-core.o
14obj-$(CONFIG_DVB_BUDGET) += budget.o
15obj-$(CONFIG_DVB_BUDGET_AV) += budget-av.o
16obj-$(CONFIG_DVB_BUDGET_CI) += budget-ci.o
17obj-$(CONFIG_DVB_BUDGET_PATCH) += budget-patch.o
18obj-$(CONFIG_DVB_AV7110) += dvb-ttpci.o
19
20ccflags-y += -Idrivers/media/dvb-core/ -Idrivers/media/dvb-frontends/
21ccflags-y += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
deleted file mode 100644
index 4bd8bd56befc..000000000000
--- a/drivers/media/dvb/ttpci/av7110.c
+++ /dev/null
@@ -1,2939 +0,0 @@
1/*
2 * driver for the SAA7146 based AV110 cards (like the Fujitsu-Siemens DVB)
3 * av7110.c: initialization and demux stuff
4 *
5 * Copyright (C) 1999-2002 Ralph Metzler
6 * & Marcus Metzler for convergence integrated media GmbH
7 *
8 * originally based on code by:
9 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 *
28 *
29 * the project's page is at http://www.linuxtv.org/
30 */
31
32
33#include <linux/module.h>
34#include <linux/kmod.h>
35#include <linux/delay.h>
36#include <linux/fs.h>
37#include <linux/timer.h>
38#include <linux/poll.h>
39
40#include <linux/kernel.h>
41#include <linux/sched.h>
42#include <linux/types.h>
43#include <linux/fcntl.h>
44#include <linux/interrupt.h>
45#include <linux/string.h>
46#include <linux/pci.h>
47#include <linux/vmalloc.h>
48#include <linux/firmware.h>
49#include <linux/crc32.h>
50#include <linux/i2c.h>
51#include <linux/kthread.h>
52#include <linux/slab.h>
53#include <asm/unaligned.h>
54#include <asm/byteorder.h>
55
56
57#include <linux/dvb/frontend.h>
58
59#include "dvb_frontend.h"
60
61#include "ttpci-eeprom.h"
62#include "av7110.h"
63#include "av7110_hw.h"
64#include "av7110_av.h"
65#include "av7110_ca.h"
66#include "av7110_ipack.h"
67
68#include "bsbe1.h"
69#include "lnbp21.h"
70#include "bsru6.h"
71
72#define TS_WIDTH 376
73#define TS_HEIGHT 512
74#define TS_BUFLEN (TS_WIDTH*TS_HEIGHT)
75#define TS_MAX_PACKETS (TS_BUFLEN/TS_SIZE)
76
77
78int av7110_debug;
79
80static int vidmode = CVBS_RGB_OUT;
81static int pids_off;
82static int adac = DVB_ADAC_TI;
83static int hw_sections;
84static int rgb_on;
85static int volume = 255;
86static int budgetpatch;
87static int wss_cfg_4_3 = 0x4008;
88static int wss_cfg_16_9 = 0x0007;
89static int tv_standard;
90static int full_ts;
91
92module_param_named(debug, av7110_debug, int, 0644);
93MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)");
94module_param(vidmode, int, 0444);
95MODULE_PARM_DESC(vidmode,"analog video out: 0 off, 1 CVBS+RGB (default), 2 CVBS+YC, 3 YC");
96module_param(pids_off, int, 0444);
97MODULE_PARM_DESC(pids_off,"clear video/audio/PCR PID filters when demux is closed");
98module_param(adac, int, 0444);
99MODULE_PARM_DESC(adac,"audio DAC type: 0 TI, 1 CRYSTAL, 2 MSP (use if autodetection fails)");
100module_param(hw_sections, int, 0444);
101MODULE_PARM_DESC(hw_sections, "0 use software section filter, 1 use hardware");
102module_param(rgb_on, int, 0444);
103MODULE_PARM_DESC(rgb_on, "For Siemens DVB-C cards only: Enable RGB control"
104 " signal on SCART pin 16 to switch SCART video mode from CVBS to RGB");
105module_param(volume, int, 0444);
106MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)");
107module_param(budgetpatch, int, 0444);
108MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)");
109module_param(full_ts, int, 0444);
110MODULE_PARM_DESC(full_ts, "enable code for full-ts hardware modification: 0 disable (default), 1 enable");
111module_param(wss_cfg_4_3, int, 0444);
112MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data");
113module_param(wss_cfg_16_9, int, 0444);
114MODULE_PARM_DESC(wss_cfg_16_9, "WSS 16:9 - default 0x0007 - bit 15: disable, 14: burst mode, 13..0: wss data");
115module_param(tv_standard, int, 0444);
116MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC");
117
118DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
119
120static void restart_feeds(struct av7110 *av7110);
121static int budget_start_feed(struct dvb_demux_feed *feed);
122static int budget_stop_feed(struct dvb_demux_feed *feed);
123
124static int av7110_num;
125
126#define FE_FUNC_OVERRIDE(fe_func, av7110_copy, av7110_func) \
127{\
128 if (fe_func != NULL) { \
129 av7110_copy = fe_func; \
130 fe_func = av7110_func; \
131 } \
132}
133
134
135static void init_av7110_av(struct av7110 *av7110)
136{
137 int ret;
138 struct saa7146_dev *dev = av7110->dev;
139
140 /* set internal volume control to maximum */
141 av7110->adac_type = DVB_ADAC_TI;
142 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right);
143 if (ret < 0)
144 printk("dvb-ttpci:cannot set internal volume to maximum:%d\n",ret);
145
146 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetMonitorType,
147 1, (u16) av7110->display_ar);
148 if (ret < 0)
149 printk("dvb-ttpci: unable to set aspect ratio\n");
150 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
151 1, av7110->display_panscan);
152 if (ret < 0)
153 printk("dvb-ttpci: unable to set pan scan\n");
154
155 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 2, wss_cfg_4_3);
156 if (ret < 0)
157 printk("dvb-ttpci: unable to configure 4:3 wss\n");
158 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 3, wss_cfg_16_9);
159 if (ret < 0)
160 printk("dvb-ttpci: unable to configure 16:9 wss\n");
161
162 ret = av7710_set_video_mode(av7110, vidmode);
163 if (ret < 0)
164 printk("dvb-ttpci:cannot set video mode:%d\n",ret);
165
166 /* handle different card types */
167 /* remaining inits according to card and frontend type */
168 av7110->analog_tuner_flags = 0;
169 av7110->current_input = 0;
170 if (dev->pci->subsystem_vendor == 0x13c2 && dev->pci->subsystem_device == 0x000a)
171 av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, 0); // SPDIF on
172 if (i2c_writereg(av7110, 0x20, 0x00, 0x00) == 1) {
173 printk ("dvb-ttpci: Crystal audio DAC @ card %d detected\n",
174 av7110->dvb_adapter.num);
175 av7110->adac_type = DVB_ADAC_CRYSTAL;
176 i2c_writereg(av7110, 0x20, 0x01, 0xd2);
177 i2c_writereg(av7110, 0x20, 0x02, 0x49);
178 i2c_writereg(av7110, 0x20, 0x03, 0x00);
179 i2c_writereg(av7110, 0x20, 0x04, 0x00);
180
181 /**
182 * some special handling for the Siemens DVB-C cards...
183 */
184 } else if (0 == av7110_init_analog_module(av7110)) {
185 /* done. */
186 }
187 else if (dev->pci->subsystem_vendor == 0x110a) {
188 printk("dvb-ttpci: DVB-C w/o analog module @ card %d detected\n",
189 av7110->dvb_adapter.num);
190 av7110->adac_type = DVB_ADAC_NONE;
191 }
192 else {
193 av7110->adac_type = adac;
194 printk("dvb-ttpci: adac type set to %d @ card %d\n",
195 av7110->adac_type, av7110->dvb_adapter.num);
196 }
197
198 if (av7110->adac_type == DVB_ADAC_NONE || av7110->adac_type == DVB_ADAC_MSP34x0) {
199 // switch DVB SCART on
200 ret = av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, MainSwitch, 1, 0);
201 if (ret < 0)
202 printk("dvb-ttpci:cannot switch on SCART(Main):%d\n",ret);
203 ret = av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, 1);
204 if (ret < 0)
205 printk("dvb-ttpci:cannot switch on SCART(AD):%d\n",ret);
206 if (rgb_on &&
207 ((av7110->dev->pci->subsystem_vendor == 0x110a) ||
208 (av7110->dev->pci->subsystem_vendor == 0x13c2)) &&
209 (av7110->dev->pci->subsystem_device == 0x0000)) {
210 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // RGB on, SCART pin 16
211 //saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // SCARTpin 8
212 }
213 }
214
215 if (dev->pci->subsystem_vendor == 0x13c2 && dev->pci->subsystem_device == 0x000e)
216 av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, SpdifSwitch, 1, 0); // SPDIF on
217
218 ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right);
219 if (ret < 0)
220 printk("dvb-ttpci:cannot set volume :%d\n",ret);
221}
222
223static void recover_arm(struct av7110 *av7110)
224{
225 dprintk(4, "%p\n",av7110);
226
227 av7110_bootarm(av7110);
228 msleep(100);
229
230 init_av7110_av(av7110);
231
232 /* card-specific recovery */
233 if (av7110->recover)
234 av7110->recover(av7110);
235
236 restart_feeds(av7110);
237
238#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
239 av7110_check_ir_config(av7110, true);
240#endif
241}
242
243static void av7110_arm_sync(struct av7110 *av7110)
244{
245 if (av7110->arm_thread)
246 kthread_stop(av7110->arm_thread);
247
248 av7110->arm_thread = NULL;
249}
250
251static int arm_thread(void *data)
252{
253 struct av7110 *av7110 = data;
254 u16 newloops = 0;
255 int timeout;
256
257 dprintk(4, "%p\n",av7110);
258
259 for (;;) {
260 timeout = wait_event_interruptible_timeout(av7110->arm_wait,
261 kthread_should_stop(), 5 * HZ);
262
263 if (-ERESTARTSYS == timeout || kthread_should_stop()) {
264 /* got signal or told to quit*/
265 break;
266 }
267
268 if (!av7110->arm_ready)
269 continue;
270
271#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
272 av7110_check_ir_config(av7110, false);
273#endif
274
275 if (mutex_lock_interruptible(&av7110->dcomlock))
276 break;
277 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2);
278 mutex_unlock(&av7110->dcomlock);
279
280 if (newloops == av7110->arm_loops || av7110->arm_errors > 3) {
281 printk(KERN_ERR "dvb-ttpci: ARM crashed @ card %d\n",
282 av7110->dvb_adapter.num);
283
284 recover_arm(av7110);
285
286 if (mutex_lock_interruptible(&av7110->dcomlock))
287 break;
288 newloops = rdebi(av7110, DEBINOSWAP, STATUS_LOOPS, 0, 2) - 1;
289 mutex_unlock(&av7110->dcomlock);
290 }
291 av7110->arm_loops = newloops;
292 av7110->arm_errors = 0;
293 }
294
295 return 0;
296}
297
298
299/****************************************************************************
300 * IRQ handling
301 ****************************************************************************/
302
303static int DvbDmxFilterCallback(u8 *buffer1, size_t buffer1_len,
304 u8 *buffer2, size_t buffer2_len,
305 struct dvb_demux_filter *dvbdmxfilter,
306 enum dmx_success success,
307 struct av7110 *av7110)
308{
309 if (!dvbdmxfilter->feed->demux->dmx.frontend)
310 return 0;
311 if (dvbdmxfilter->feed->demux->dmx.frontend->source == DMX_MEMORY_FE)
312 return 0;
313
314 switch (dvbdmxfilter->type) {
315 case DMX_TYPE_SEC:
316 if ((((buffer1[1] << 8) | buffer1[2]) & 0xfff) + 3 != buffer1_len)
317 return 0;
318 if (dvbdmxfilter->doneq) {
319 struct dmx_section_filter *filter = &dvbdmxfilter->filter;
320 int i;
321 u8 xor, neq = 0;
322
323 for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
324 xor = filter->filter_value[i] ^ buffer1[i];
325 neq |= dvbdmxfilter->maskandnotmode[i] & xor;
326 }
327 if (!neq)
328 return 0;
329 }
330 return dvbdmxfilter->feed->cb.sec(buffer1, buffer1_len,
331 buffer2, buffer2_len,
332 &dvbdmxfilter->filter,
333 DMX_OK);
334 case DMX_TYPE_TS:
335 if (!(dvbdmxfilter->feed->ts_type & TS_PACKET))
336 return 0;
337 if (dvbdmxfilter->feed->ts_type & TS_PAYLOAD_ONLY)
338 return dvbdmxfilter->feed->cb.ts(buffer1, buffer1_len,
339 buffer2, buffer2_len,
340 &dvbdmxfilter->feed->feed.ts,
341 DMX_OK);
342 else
343 av7110_p2t_write(buffer1, buffer1_len,
344 dvbdmxfilter->feed->pid,
345 &av7110->p2t_filter[dvbdmxfilter->index]);
346 default:
347 return 0;
348 }
349}
350
351
352//#define DEBUG_TIMING
353static inline void print_time(char *s)
354{
355#ifdef DEBUG_TIMING
356 struct timeval tv;
357 do_gettimeofday(&tv);
358 printk("%s: %d.%d\n", s, (int)tv.tv_sec, (int)tv.tv_usec);
359#endif
360}
361
362#define DEBI_READ 0
363#define DEBI_WRITE 1
364static inline void start_debi_dma(struct av7110 *av7110, int dir,
365 unsigned long addr, unsigned int len)
366{
367 dprintk(8, "%c %08lx %u\n", dir == DEBI_READ ? 'R' : 'W', addr, len);
368 if (saa7146_wait_for_debi_done(av7110->dev, 0)) {
369 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __func__);
370 return;
371 }
372
373 SAA7146_ISR_CLEAR(av7110->dev, MASK_19); /* for good measure */
374 SAA7146_IER_ENABLE(av7110->dev, MASK_19);
375 if (len < 5)
376 len = 5; /* we want a real DEBI DMA */
377 if (dir == DEBI_WRITE)
378 iwdebi(av7110, DEBISWAB, addr, 0, (len + 3) & ~3);
379 else
380 irdebi(av7110, DEBISWAB, addr, 0, len);
381}
382
383static void debiirq(unsigned long cookie)
384{
385 struct av7110 *av7110 = (struct av7110 *)cookie;
386 int type = av7110->debitype;
387 int handle = (type >> 8) & 0x1f;
388 unsigned int xfer = 0;
389
390 print_time("debi");
391 dprintk(4, "type 0x%04x\n", type);
392
393 if (type == -1) {
394 printk("DEBI irq oops @ %ld, psr:0x%08x, ssr:0x%08x\n",
395 jiffies, saa7146_read(av7110->dev, PSR),
396 saa7146_read(av7110->dev, SSR));
397 goto debi_done;
398 }
399 av7110->debitype = -1;
400
401 switch (type & 0xff) {
402
403 case DATA_TS_RECORD:
404 dvb_dmx_swfilter_packets(&av7110->demux,
405 (const u8 *) av7110->debi_virt,
406 av7110->debilen / 188);
407 xfer = RX_BUFF;
408 break;
409
410 case DATA_PES_RECORD:
411 if (av7110->demux.recording)
412 av7110_record_cb(&av7110->p2t[handle],
413 (u8 *) av7110->debi_virt,
414 av7110->debilen);
415 xfer = RX_BUFF;
416 break;
417
418 case DATA_IPMPE:
419 case DATA_FSECTION:
420 case DATA_PIPING:
421 if (av7110->handle2filter[handle])
422 DvbDmxFilterCallback((u8 *)av7110->debi_virt,
423 av7110->debilen, NULL, 0,
424 av7110->handle2filter[handle],
425 DMX_OK, av7110);
426 xfer = RX_BUFF;
427 break;
428
429 case DATA_CI_GET:
430 {
431 u8 *data = av7110->debi_virt;
432
433 if ((data[0] < 2) && data[2] == 0xff) {
434 int flags = 0;
435 if (data[5] > 0)
436 flags |= CA_CI_MODULE_PRESENT;
437 if (data[5] > 5)
438 flags |= CA_CI_MODULE_READY;
439 av7110->ci_slot[data[0]].flags = flags;
440 } else
441 ci_get_data(&av7110->ci_rbuffer,
442 av7110->debi_virt,
443 av7110->debilen);
444 xfer = RX_BUFF;
445 break;
446 }
447
448 case DATA_COMMON_INTERFACE:
449 CI_handle(av7110, (u8 *)av7110->debi_virt, av7110->debilen);
450#if 0
451 {
452 int i;
453
454 printk("av7110%d: ", av7110->num);
455 printk("%02x ", *(u8 *)av7110->debi_virt);
456 printk("%02x ", *(1+(u8 *)av7110->debi_virt));
457 for (i = 2; i < av7110->debilen; i++)
458 printk("%02x ", (*(i+(unsigned char *)av7110->debi_virt)));
459 for (i = 2; i < av7110->debilen; i++)
460 printk("%c", chtrans(*(i+(unsigned char *)av7110->debi_virt)));
461
462 printk("\n");
463 }
464#endif
465 xfer = RX_BUFF;
466 break;
467
468 case DATA_DEBUG_MESSAGE:
469 ((s8*)av7110->debi_virt)[Reserved_SIZE - 1] = 0;
470 printk("%s\n", (s8 *) av7110->debi_virt);
471 xfer = RX_BUFF;
472 break;
473
474 case DATA_CI_PUT:
475 dprintk(4, "debi DATA_CI_PUT\n");
476 case DATA_MPEG_PLAY:
477 dprintk(4, "debi DATA_MPEG_PLAY\n");
478 case DATA_BMP_LOAD:
479 dprintk(4, "debi DATA_BMP_LOAD\n");
480 xfer = TX_BUFF;
481 break;
482 default:
483 break;
484 }
485debi_done:
486 spin_lock(&av7110->debilock);
487 if (xfer)
488 iwdebi(av7110, DEBINOSWAP, xfer, 0, 2);
489 ARM_ClearMailBox(av7110);
490 spin_unlock(&av7110->debilock);
491}
492
493/* irq from av7110 firmware writing the mailbox register in the DPRAM */
494static void gpioirq(unsigned long cookie)
495{
496 struct av7110 *av7110 = (struct av7110 *)cookie;
497 u32 rxbuf, txbuf;
498 int len;
499
500 if (av7110->debitype != -1)
501 /* we shouldn't get any irq while a debi xfer is running */
502 printk("dvb-ttpci: GPIO0 irq oops @ %ld, psr:0x%08x, ssr:0x%08x\n",
503 jiffies, saa7146_read(av7110->dev, PSR),
504 saa7146_read(av7110->dev, SSR));
505
506 if (saa7146_wait_for_debi_done(av7110->dev, 0)) {
507 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __func__);
508 BUG(); /* maybe we should try resetting the debi? */
509 }
510
511 spin_lock(&av7110->debilock);
512 ARM_ClearIrq(av7110);
513
514 /* see what the av7110 wants */
515 av7110->debitype = irdebi(av7110, DEBINOSWAP, IRQ_STATE, 0, 2);
516 av7110->debilen = irdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
517 rxbuf = irdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
518 txbuf = irdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
519 len = (av7110->debilen + 3) & ~3;
520
521 print_time("gpio");
522 dprintk(8, "GPIO0 irq 0x%04x %d\n", av7110->debitype, av7110->debilen);
523
524 switch (av7110->debitype & 0xff) {
525
526 case DATA_TS_PLAY:
527 case DATA_PES_PLAY:
528 break;
529
530 case DATA_MPEG_VIDEO_EVENT:
531 {
532 u32 h_ar;
533 struct video_event event;
534
535 av7110->video_size.w = irdebi(av7110, DEBINOSWAP, STATUS_MPEG_WIDTH, 0, 2);
536 h_ar = irdebi(av7110, DEBINOSWAP, STATUS_MPEG_HEIGHT_AR, 0, 2);
537
538 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
539 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
540
541 av7110->video_size.h = h_ar & 0xfff;
542
543 event.type = VIDEO_EVENT_SIZE_CHANGED;
544 event.u.size.w = av7110->video_size.w;
545 event.u.size.h = av7110->video_size.h;
546 switch ((h_ar >> 12) & 0xf)
547 {
548 case 3:
549 av7110->video_size.aspect_ratio = VIDEO_FORMAT_16_9;
550 event.u.size.aspect_ratio = VIDEO_FORMAT_16_9;
551 av7110->videostate.video_format = VIDEO_FORMAT_16_9;
552 break;
553 case 4:
554 av7110->video_size.aspect_ratio = VIDEO_FORMAT_221_1;
555 event.u.size.aspect_ratio = VIDEO_FORMAT_221_1;
556 av7110->videostate.video_format = VIDEO_FORMAT_221_1;
557 break;
558 default:
559 av7110->video_size.aspect_ratio = VIDEO_FORMAT_4_3;
560 event.u.size.aspect_ratio = VIDEO_FORMAT_4_3;
561 av7110->videostate.video_format = VIDEO_FORMAT_4_3;
562 }
563
564 dprintk(8, "GPIO0 irq: DATA_MPEG_VIDEO_EVENT: w/h/ar = %u/%u/%u\n",
565 av7110->video_size.w, av7110->video_size.h,
566 av7110->video_size.aspect_ratio);
567
568 dvb_video_add_event(av7110, &event);
569 break;
570 }
571
572 case DATA_CI_PUT:
573 {
574 int avail;
575 struct dvb_ringbuffer *cibuf = &av7110->ci_wbuffer;
576
577 avail = dvb_ringbuffer_avail(cibuf);
578 if (avail <= 2) {
579 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
580 iwdebi(av7110, DEBINOSWAP, TX_LEN, 0, 2);
581 iwdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
582 break;
583 }
584 len = DVB_RINGBUFFER_PEEK(cibuf, 0) << 8;
585 len |= DVB_RINGBUFFER_PEEK(cibuf, 1);
586 if (avail < len + 2) {
587 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
588 iwdebi(av7110, DEBINOSWAP, TX_LEN, 0, 2);
589 iwdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
590 break;
591 }
592 DVB_RINGBUFFER_SKIP(cibuf, 2);
593
594 dvb_ringbuffer_read(cibuf, av7110->debi_virt, len);
595
596 iwdebi(av7110, DEBINOSWAP, TX_LEN, len, 2);
597 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, len, 2);
598 dprintk(8, "DMA: CI\n");
599 start_debi_dma(av7110, DEBI_WRITE, DPRAM_BASE + txbuf, len);
600 spin_unlock(&av7110->debilock);
601 wake_up(&cibuf->queue);
602 return;
603 }
604
605 case DATA_MPEG_PLAY:
606 if (!av7110->playing) {
607 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
608 iwdebi(av7110, DEBINOSWAP, TX_LEN, 0, 2);
609 iwdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
610 break;
611 }
612 len = 0;
613 if (av7110->debitype & 0x100) {
614 spin_lock(&av7110->aout.lock);
615 len = av7110_pes_play(av7110->debi_virt, &av7110->aout, 2048);
616 spin_unlock(&av7110->aout.lock);
617 }
618 if (len <= 0 && (av7110->debitype & 0x200)
619 &&av7110->videostate.play_state != VIDEO_FREEZED) {
620 spin_lock(&av7110->avout.lock);
621 len = av7110_pes_play(av7110->debi_virt, &av7110->avout, 2048);
622 spin_unlock(&av7110->avout.lock);
623 }
624 if (len <= 0) {
625 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
626 iwdebi(av7110, DEBINOSWAP, TX_LEN, 0, 2);
627 iwdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
628 break;
629 }
630 dprintk(8, "GPIO0 PES_PLAY len=%04x\n", len);
631 iwdebi(av7110, DEBINOSWAP, TX_LEN, len, 2);
632 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, len, 2);
633 dprintk(8, "DMA: MPEG_PLAY\n");
634 start_debi_dma(av7110, DEBI_WRITE, DPRAM_BASE + txbuf, len);
635 spin_unlock(&av7110->debilock);
636 return;
637
638 case DATA_BMP_LOAD:
639 len = av7110->debilen;
640 dprintk(8, "gpio DATA_BMP_LOAD len %d\n", len);
641 if (!len) {
642 av7110->bmp_state = BMP_LOADED;
643 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, 0, 2);
644 iwdebi(av7110, DEBINOSWAP, TX_LEN, 0, 2);
645 iwdebi(av7110, DEBINOSWAP, TX_BUFF, 0, 2);
646 wake_up(&av7110->bmpq);
647 dprintk(8, "gpio DATA_BMP_LOAD done\n");
648 break;
649 }
650 if (len > av7110->bmplen)
651 len = av7110->bmplen;
652 if (len > 2 * 1024)
653 len = 2 * 1024;
654 iwdebi(av7110, DEBINOSWAP, TX_LEN, len, 2);
655 iwdebi(av7110, DEBINOSWAP, IRQ_STATE_EXT, len, 2);
656 memcpy(av7110->debi_virt, av7110->bmpbuf+av7110->bmpp, len);
657 av7110->bmpp += len;
658 av7110->bmplen -= len;
659 dprintk(8, "gpio DATA_BMP_LOAD DMA len %d\n", len);
660 start_debi_dma(av7110, DEBI_WRITE, DPRAM_BASE+txbuf, len);
661 spin_unlock(&av7110->debilock);
662 return;
663
664 case DATA_CI_GET:
665 case DATA_COMMON_INTERFACE:
666 case DATA_FSECTION:
667 case DATA_IPMPE:
668 case DATA_PIPING:
669 if (!len || len > 4 * 1024) {
670 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
671 break;
672 }
673 /* fall through */
674
675 case DATA_TS_RECORD:
676 case DATA_PES_RECORD:
677 dprintk(8, "DMA: TS_REC etc.\n");
678 start_debi_dma(av7110, DEBI_READ, DPRAM_BASE+rxbuf, len);
679 spin_unlock(&av7110->debilock);
680 return;
681
682 case DATA_DEBUG_MESSAGE:
683 if (!len || len > 0xff) {
684 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
685 break;
686 }
687 start_debi_dma(av7110, DEBI_READ, Reserved, len);
688 spin_unlock(&av7110->debilock);
689 return;
690
691 case DATA_IRCOMMAND:
692 if (av7110->ir.ir_handler)
693 av7110->ir.ir_handler(av7110,
694 swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4)));
695 iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2);
696 break;
697
698 default:
699 printk("dvb-ttpci: gpioirq unknown type=%d len=%d\n",
700 av7110->debitype, av7110->debilen);
701 break;
702 }
703 av7110->debitype = -1;
704 ARM_ClearMailBox(av7110);
705 spin_unlock(&av7110->debilock);
706}
707
708
709#ifdef CONFIG_DVB_AV7110_OSD
710static int dvb_osd_ioctl(struct file *file,
711 unsigned int cmd, void *parg)
712{
713 struct dvb_device *dvbdev = file->private_data;
714 struct av7110 *av7110 = dvbdev->priv;
715
716 dprintk(4, "%p\n", av7110);
717
718 if (cmd == OSD_SEND_CMD)
719 return av7110_osd_cmd(av7110, (osd_cmd_t *) parg);
720 if (cmd == OSD_GET_CAPABILITY)
721 return av7110_osd_capability(av7110, (osd_cap_t *) parg);
722
723 return -EINVAL;
724}
725
726
727static const struct file_operations dvb_osd_fops = {
728 .owner = THIS_MODULE,
729 .unlocked_ioctl = dvb_generic_ioctl,
730 .open = dvb_generic_open,
731 .release = dvb_generic_release,
732 .llseek = noop_llseek,
733};
734
735static struct dvb_device dvbdev_osd = {
736 .priv = NULL,
737 .users = 1,
738 .writers = 1,
739 .fops = &dvb_osd_fops,
740 .kernel_ioctl = dvb_osd_ioctl,
741};
742#endif /* CONFIG_DVB_AV7110_OSD */
743
744
745static inline int SetPIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
746 u16 subpid, u16 pcrpid)
747{
748 u16 aflags = 0;
749
750 dprintk(4, "%p\n", av7110);
751
752 if (vpid == 0x1fff || apid == 0x1fff ||
753 ttpid == 0x1fff || subpid == 0x1fff || pcrpid == 0x1fff) {
754 vpid = apid = ttpid = subpid = pcrpid = 0;
755 av7110->pids[DMX_PES_VIDEO] = 0;
756 av7110->pids[DMX_PES_AUDIO] = 0;
757 av7110->pids[DMX_PES_TELETEXT] = 0;
758 av7110->pids[DMX_PES_PCR] = 0;
759 }
760
761 if (av7110->audiostate.bypass_mode)
762 aflags |= 0x8000;
763
764 return av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, MultiPID, 6,
765 pcrpid, vpid, apid, ttpid, subpid, aflags);
766}
767
768int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
769 u16 subpid, u16 pcrpid)
770{
771 int ret = 0;
772 dprintk(4, "%p\n", av7110);
773
774 if (mutex_lock_interruptible(&av7110->pid_mutex))
775 return -ERESTARTSYS;
776
777 if (!(vpid & 0x8000))
778 av7110->pids[DMX_PES_VIDEO] = vpid;
779 if (!(apid & 0x8000))
780 av7110->pids[DMX_PES_AUDIO] = apid;
781 if (!(ttpid & 0x8000))
782 av7110->pids[DMX_PES_TELETEXT] = ttpid;
783 if (!(pcrpid & 0x8000))
784 av7110->pids[DMX_PES_PCR] = pcrpid;
785
786 av7110->pids[DMX_PES_SUBTITLE] = 0;
787
788 if (av7110->fe_synced) {
789 pcrpid = av7110->pids[DMX_PES_PCR];
790 ret = SetPIDs(av7110, vpid, apid, ttpid, subpid, pcrpid);
791 }
792
793 mutex_unlock(&av7110->pid_mutex);
794 return ret;
795}
796
797
798/******************************************************************************
799 * hardware filter functions
800 ******************************************************************************/
801
802static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
803{
804 struct dvb_demux_feed *dvbdmxfeed = dvbdmxfilter->feed;
805 struct av7110 *av7110 = dvbdmxfeed->demux->priv;
806 u16 buf[20];
807 int ret, i;
808 u16 handle;
809// u16 mode = 0x0320;
810 u16 mode = 0xb96a;
811
812 dprintk(4, "%p\n", av7110);
813
814 if (av7110->full_ts)
815 return 0;
816
817 if (dvbdmxfilter->type == DMX_TYPE_SEC) {
818 if (hw_sections) {
819 buf[4] = (dvbdmxfilter->filter.filter_value[0] << 8) |
820 dvbdmxfilter->maskandmode[0];
821 for (i = 3; i < 18; i++)
822 buf[i + 4 - 2] =
823 (dvbdmxfilter->filter.filter_value[i] << 8) |
824 dvbdmxfilter->maskandmode[i];
825 mode = 4;
826 }
827 } else if ((dvbdmxfeed->ts_type & TS_PACKET) &&
828 !(dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)) {
829 av7110_p2t_init(&av7110->p2t_filter[dvbdmxfilter->index], dvbdmxfeed);
830 }
831
832 buf[0] = (COMTYPE_PID_FILTER << 8) + AddPIDFilter;
833 buf[1] = 16;
834 buf[2] = dvbdmxfeed->pid;
835 buf[3] = mode;
836
837 ret = av7110_fw_request(av7110, buf, 20, &handle, 1);
838 if (ret != 0 || handle >= 32) {
839 printk("dvb-ttpci: %s error buf %04x %04x %04x %04x "
840 "ret %d handle %04x\n",
841 __func__, buf[0], buf[1], buf[2], buf[3],
842 ret, handle);
843 dvbdmxfilter->hw_handle = 0xffff;
844 if (!ret)
845 ret = -1;
846 return ret;
847 }
848
849 av7110->handle2filter[handle] = dvbdmxfilter;
850 dvbdmxfilter->hw_handle = handle;
851
852 return ret;
853}
854
855static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
856{
857 struct av7110 *av7110 = dvbdmxfilter->feed->demux->priv;
858 u16 buf[3];
859 u16 answ[2];
860 int ret;
861 u16 handle;
862
863 dprintk(4, "%p\n", av7110);
864
865 if (av7110->full_ts)
866 return 0;
867
868 handle = dvbdmxfilter->hw_handle;
869 if (handle >= 32) {
870 printk("%s tried to stop invalid filter %04x, filter type = %x\n",
871 __func__, handle, dvbdmxfilter->type);
872 return -EINVAL;
873 }
874
875 av7110->handle2filter[handle] = NULL;
876
877 buf[0] = (COMTYPE_PID_FILTER << 8) + DelPIDFilter;
878 buf[1] = 1;
879 buf[2] = handle;
880 ret = av7110_fw_request(av7110, buf, 3, answ, 2);
881 if (ret != 0 || answ[1] != handle) {
882 printk("dvb-ttpci: %s error cmd %04x %04x %04x ret %x "
883 "resp %04x %04x pid %d\n",
884 __func__, buf[0], buf[1], buf[2], ret,
885 answ[0], answ[1], dvbdmxfilter->feed->pid);
886 if (!ret)
887 ret = -1;
888 }
889 return ret;
890}
891
892
893static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
894{
895 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
896 struct av7110 *av7110 = dvbdmx->priv;
897 u16 *pid = dvbdmx->pids, npids[5];
898 int i;
899 int ret = 0;
900
901 dprintk(4, "%p\n", av7110);
902
903 npids[0] = npids[1] = npids[2] = npids[3] = npids[4] = 0xffff;
904 i = dvbdmxfeed->pes_type;
905 npids[i] = (pid[i]&0x8000) ? 0 : pid[i];
906 if ((i == 2) && npids[i] && (dvbdmxfeed->ts_type & TS_PACKET)) {
907 npids[i] = 0;
908 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
909 if (!ret)
910 ret = StartHWFilter(dvbdmxfeed->filter);
911 return ret;
912 }
913 if (dvbdmxfeed->pes_type <= 2 || dvbdmxfeed->pes_type == 4) {
914 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
915 if (ret)
916 return ret;
917 }
918
919 if (dvbdmxfeed->pes_type < 2 && npids[0])
920 if (av7110->fe_synced)
921 {
922 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
923 if (ret)
924 return ret;
925 }
926
927 if ((dvbdmxfeed->ts_type & TS_PACKET) && !av7110->full_ts) {
928 if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000))
929 ret = av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed);
930 if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000))
931 ret = av7110_av_start_record(av7110, RP_VIDEO, dvbdmxfeed);
932 }
933 return ret;
934}
935
936static int dvb_feed_stop_pid(struct dvb_demux_feed *dvbdmxfeed)
937{
938 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
939 struct av7110 *av7110 = dvbdmx->priv;
940 u16 *pid = dvbdmx->pids, npids[5];
941 int i;
942
943 int ret = 0;
944
945 dprintk(4, "%p\n", av7110);
946
947 if (dvbdmxfeed->pes_type <= 1) {
948 ret = av7110_av_stop(av7110, dvbdmxfeed->pes_type ? RP_VIDEO : RP_AUDIO);
949 if (ret)
950 return ret;
951 if (!av7110->rec_mode)
952 dvbdmx->recording = 0;
953 if (!av7110->playing)
954 dvbdmx->playing = 0;
955 }
956 npids[0] = npids[1] = npids[2] = npids[3] = npids[4] = 0xffff;
957 i = dvbdmxfeed->pes_type;
958 switch (i) {
959 case 2: //teletext
960 if (dvbdmxfeed->ts_type & TS_PACKET)
961 ret = StopHWFilter(dvbdmxfeed->filter);
962 npids[2] = 0;
963 break;
964 case 0:
965 case 1:
966 case 4:
967 if (!pids_off)
968 return 0;
969 npids[i] = (pid[i]&0x8000) ? 0 : pid[i];
970 break;
971 }
972 if (!ret)
973 ret = ChangePIDs(av7110, npids[1], npids[0], npids[2], npids[3], npids[4]);
974 return ret;
975}
976
977static int av7110_start_feed(struct dvb_demux_feed *feed)
978{
979 struct dvb_demux *demux = feed->demux;
980 struct av7110 *av7110 = demux->priv;
981 int ret = 0;
982
983 dprintk(4, "%p\n", av7110);
984
985 if (!demux->dmx.frontend)
986 return -EINVAL;
987
988 if (!av7110->full_ts && feed->pid > 0x1fff)
989 return -EINVAL;
990
991 if (feed->type == DMX_TYPE_TS) {
992 if ((feed->ts_type & TS_DECODER) &&
993 (feed->pes_type <= DMX_TS_PES_PCR)) {
994 switch (demux->dmx.frontend->source) {
995 case DMX_MEMORY_FE:
996 if (feed->ts_type & TS_DECODER)
997 if (feed->pes_type < 2 &&
998 !(demux->pids[0] & 0x8000) &&
999 !(demux->pids[1] & 0x8000)) {
1000 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1001 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1002 ret = av7110_av_start_play(av7110,RP_AV);
1003 if (!ret)
1004 demux->playing = 1;
1005 }
1006 break;
1007 default:
1008 ret = dvb_feed_start_pid(feed);
1009 break;
1010 }
1011 } else if ((feed->ts_type & TS_PACKET) &&
1012 (demux->dmx.frontend->source != DMX_MEMORY_FE)) {
1013 ret = StartHWFilter(feed->filter);
1014 }
1015 }
1016
1017 if (av7110->full_ts) {
1018 budget_start_feed(feed);
1019 return ret;
1020 }
1021
1022 if (feed->type == DMX_TYPE_SEC) {
1023 int i;
1024
1025 for (i = 0; i < demux->filternum; i++) {
1026 if (demux->filter[i].state != DMX_STATE_READY)
1027 continue;
1028 if (demux->filter[i].type != DMX_TYPE_SEC)
1029 continue;
1030 if (demux->filter[i].filter.parent != &feed->feed.sec)
1031 continue;
1032 demux->filter[i].state = DMX_STATE_GO;
1033 if (demux->dmx.frontend->source != DMX_MEMORY_FE) {
1034 ret = StartHWFilter(&demux->filter[i]);
1035 if (ret)
1036 break;
1037 }
1038 }
1039 }
1040
1041 return ret;
1042}
1043
1044
1045static int av7110_stop_feed(struct dvb_demux_feed *feed)
1046{
1047 struct dvb_demux *demux = feed->demux;
1048 struct av7110 *av7110 = demux->priv;
1049 int i, rc, ret = 0;
1050 dprintk(4, "%p\n", av7110);
1051
1052 if (feed->type == DMX_TYPE_TS) {
1053 if (feed->ts_type & TS_DECODER) {
1054 if (feed->pes_type >= DMX_TS_PES_OTHER ||
1055 !demux->pesfilter[feed->pes_type])
1056 return -EINVAL;
1057 demux->pids[feed->pes_type] |= 0x8000;
1058 demux->pesfilter[feed->pes_type] = NULL;
1059 }
1060 if (feed->ts_type & TS_DECODER &&
1061 feed->pes_type < DMX_TS_PES_OTHER) {
1062 ret = dvb_feed_stop_pid(feed);
1063 } else
1064 if ((feed->ts_type & TS_PACKET) &&
1065 (demux->dmx.frontend->source != DMX_MEMORY_FE))
1066 ret = StopHWFilter(feed->filter);
1067 }
1068
1069 if (av7110->full_ts) {
1070 budget_stop_feed(feed);
1071 return ret;
1072 }
1073
1074 if (feed->type == DMX_TYPE_SEC) {
1075 for (i = 0; i<demux->filternum; i++) {
1076 if (demux->filter[i].state == DMX_STATE_GO &&
1077 demux->filter[i].filter.parent == &feed->feed.sec) {
1078 demux->filter[i].state = DMX_STATE_READY;
1079 if (demux->dmx.frontend->source != DMX_MEMORY_FE) {
1080 rc = StopHWFilter(&demux->filter[i]);
1081 if (!ret)
1082 ret = rc;
1083 /* keep going, stop as many filters as possible */
1084 }
1085 }
1086 }
1087 }
1088
1089 return ret;
1090}
1091
1092
1093static void restart_feeds(struct av7110 *av7110)
1094{
1095 struct dvb_demux *dvbdmx = &av7110->demux;
1096 struct dvb_demux_feed *feed;
1097 int mode;
1098 int feeding;
1099 int i, j;
1100
1101 dprintk(4, "%p\n", av7110);
1102
1103 mode = av7110->playing;
1104 av7110->playing = 0;
1105 av7110->rec_mode = 0;
1106
1107 feeding = av7110->feeding1; /* full_ts mod */
1108
1109 for (i = 0; i < dvbdmx->feednum; i++) {
1110 feed = &dvbdmx->feed[i];
1111 if (feed->state == DMX_STATE_GO) {
1112 if (feed->type == DMX_TYPE_SEC) {
1113 for (j = 0; j < dvbdmx->filternum; j++) {
1114 if (dvbdmx->filter[j].type != DMX_TYPE_SEC)
1115 continue;
1116 if (dvbdmx->filter[j].filter.parent != &feed->feed.sec)
1117 continue;
1118 if (dvbdmx->filter[j].state == DMX_STATE_GO)
1119 dvbdmx->filter[j].state = DMX_STATE_READY;
1120 }
1121 }
1122 av7110_start_feed(feed);
1123 }
1124 }
1125
1126 av7110->feeding1 = feeding; /* full_ts mod */
1127
1128 if (mode)
1129 av7110_av_start_play(av7110, mode);
1130}
1131
1132static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1133 uint64_t *stc, unsigned int *base)
1134{
1135 int ret;
1136 u16 fwstc[4];
1137 u16 tag = ((COMTYPE_REQUEST << 8) + ReqSTC);
1138 struct dvb_demux *dvbdemux;
1139 struct av7110 *av7110;
1140
1141 /* pointer casting paranoia... */
1142 BUG_ON(!demux);
1143 dvbdemux = demux->priv;
1144 BUG_ON(!dvbdemux);
1145 av7110 = dvbdemux->priv;
1146
1147 dprintk(4, "%p\n", av7110);
1148
1149 if (num != 0)
1150 return -EINVAL;
1151
1152 ret = av7110_fw_request(av7110, &tag, 0, fwstc, 4);
1153 if (ret) {
1154 printk(KERN_ERR "%s: av7110_fw_request error\n", __func__);
1155 return ret;
1156 }
1157 dprintk(2, "fwstc = %04hx %04hx %04hx %04hx\n",
1158 fwstc[0], fwstc[1], fwstc[2], fwstc[3]);
1159
1160 *stc = (((uint64_t) ((fwstc[3] & 0x8000) >> 15)) << 32) |
1161 (((uint64_t) fwstc[1]) << 16) | ((uint64_t) fwstc[0]);
1162 *base = 1;
1163
1164 dprintk(4, "stc = %lu\n", (unsigned long)*stc);
1165
1166 return 0;
1167}
1168
1169
1170/******************************************************************************
1171 * SEC device file operations
1172 ******************************************************************************/
1173
1174
1175static int av7110_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
1176{
1177 struct av7110* av7110 = fe->dvb->priv;
1178
1179 switch (tone) {
1180 case SEC_TONE_ON:
1181 return Set22K(av7110, 1);
1182
1183 case SEC_TONE_OFF:
1184 return Set22K(av7110, 0);
1185
1186 default:
1187 return -EINVAL;
1188 }
1189}
1190
1191static int av7110_diseqc_send_master_cmd(struct dvb_frontend* fe,
1192 struct dvb_diseqc_master_cmd* cmd)
1193{
1194 struct av7110* av7110 = fe->dvb->priv;
1195
1196 return av7110_diseqc_send(av7110, cmd->msg_len, cmd->msg, -1);
1197}
1198
1199static int av7110_diseqc_send_burst(struct dvb_frontend* fe,
1200 fe_sec_mini_cmd_t minicmd)
1201{
1202 struct av7110* av7110 = fe->dvb->priv;
1203
1204 return av7110_diseqc_send(av7110, 0, NULL, minicmd);
1205}
1206
1207/* simplified code from budget-core.c */
1208static int stop_ts_capture(struct av7110 *budget)
1209{
1210 dprintk(2, "budget: %p\n", budget);
1211
1212 if (--budget->feeding1)
1213 return budget->feeding1;
1214 saa7146_write(budget->dev, MC1, MASK_20); /* DMA3 off */
1215 SAA7146_IER_DISABLE(budget->dev, MASK_10);
1216 SAA7146_ISR_CLEAR(budget->dev, MASK_10);
1217 return 0;
1218}
1219
1220static int start_ts_capture(struct av7110 *budget)
1221{
1222 dprintk(2, "budget: %p\n", budget);
1223
1224 if (budget->feeding1)
1225 return ++budget->feeding1;
1226 memset(budget->grabbing, 0x00, TS_BUFLEN);
1227 budget->ttbp = 0;
1228 SAA7146_ISR_CLEAR(budget->dev, MASK_10); /* VPE */
1229 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
1230 saa7146_write(budget->dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */
1231 return ++budget->feeding1;
1232}
1233
1234static int budget_start_feed(struct dvb_demux_feed *feed)
1235{
1236 struct dvb_demux *demux = feed->demux;
1237 struct av7110 *budget = demux->priv;
1238 int status;
1239
1240 dprintk(2, "av7110: %p\n", budget);
1241
1242 spin_lock(&budget->feedlock1);
1243 feed->pusi_seen = 0; /* have a clean section start */
1244 status = start_ts_capture(budget);
1245 spin_unlock(&budget->feedlock1);
1246 return status;
1247}
1248
1249static int budget_stop_feed(struct dvb_demux_feed *feed)
1250{
1251 struct dvb_demux *demux = feed->demux;
1252 struct av7110 *budget = demux->priv;
1253 int status;
1254
1255 dprintk(2, "budget: %p\n", budget);
1256
1257 spin_lock(&budget->feedlock1);
1258 status = stop_ts_capture(budget);
1259 spin_unlock(&budget->feedlock1);
1260 return status;
1261}
1262
1263static void vpeirq(unsigned long cookie)
1264{
1265 struct av7110 *budget = (struct av7110 *)cookie;
1266 u8 *mem = (u8 *) (budget->grabbing);
1267 u32 olddma = budget->ttbp;
1268 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
1269 struct dvb_demux *demux = budget->full_ts ? &budget->demux : &budget->demux1;
1270
1271 /* nearest lower position divisible by 188 */
1272 newdma -= newdma % 188;
1273
1274 if (newdma >= TS_BUFLEN)
1275 return;
1276
1277 budget->ttbp = newdma;
1278
1279 if (!budget->feeding1 || (newdma == olddma))
1280 return;
1281
1282 /* Ensure streamed PCI data is synced to CPU */
1283 pci_dma_sync_sg_for_cpu(budget->dev->pci, budget->pt.slist, budget->pt.nents, PCI_DMA_FROMDEVICE);
1284
1285#if 0
1286 /* track rps1 activity */
1287 printk("vpeirq: %02x Event Counter 1 0x%04x\n",
1288 mem[olddma],
1289 saa7146_read(budget->dev, EC1R) & 0x3fff);
1290#endif
1291
1292 if (newdma > olddma)
1293 /* no wraparound, dump olddma..newdma */
1294 dvb_dmx_swfilter_packets(demux, mem + olddma, (newdma - olddma) / 188);
1295 else {
1296 /* wraparound, dump olddma..buflen and 0..newdma */
1297 dvb_dmx_swfilter_packets(demux, mem + olddma, (TS_BUFLEN - olddma) / 188);
1298 dvb_dmx_swfilter_packets(demux, mem, newdma / 188);
1299 }
1300}
1301
1302static int av7110_register(struct av7110 *av7110)
1303{
1304 int ret, i;
1305 struct dvb_demux *dvbdemux = &av7110->demux;
1306 struct dvb_demux *dvbdemux1 = &av7110->demux1;
1307
1308 dprintk(4, "%p\n", av7110);
1309
1310 if (av7110->registered)
1311 return -1;
1312
1313 av7110->registered = 1;
1314
1315 dvbdemux->priv = (void *) av7110;
1316
1317 for (i = 0; i < 32; i++)
1318 av7110->handle2filter[i] = NULL;
1319
1320 dvbdemux->filternum = (av7110->full_ts) ? 256 : 32;
1321 dvbdemux->feednum = (av7110->full_ts) ? 256 : 32;
1322 dvbdemux->start_feed = av7110_start_feed;
1323 dvbdemux->stop_feed = av7110_stop_feed;
1324 dvbdemux->write_to_decoder = av7110_write_to_decoder;
1325 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1326 DMX_MEMORY_BASED_FILTERING);
1327
1328 dvb_dmx_init(&av7110->demux);
1329 av7110->demux.dmx.get_stc = dvb_get_stc;
1330
1331 av7110->dmxdev.filternum = (av7110->full_ts) ? 256 : 32;
1332 av7110->dmxdev.demux = &dvbdemux->dmx;
1333 av7110->dmxdev.capabilities = 0;
1334
1335 dvb_dmxdev_init(&av7110->dmxdev, &av7110->dvb_adapter);
1336
1337 av7110->hw_frontend.source = DMX_FRONTEND_0;
1338
1339 ret = dvbdemux->dmx.add_frontend(&dvbdemux->dmx, &av7110->hw_frontend);
1340
1341 if (ret < 0)
1342 return ret;
1343
1344 av7110->mem_frontend.source = DMX_MEMORY_FE;
1345
1346 ret = dvbdemux->dmx.add_frontend(&dvbdemux->dmx, &av7110->mem_frontend);
1347
1348 if (ret < 0)
1349 return ret;
1350
1351 ret = dvbdemux->dmx.connect_frontend(&dvbdemux->dmx,
1352 &av7110->hw_frontend);
1353 if (ret < 0)
1354 return ret;
1355
1356 av7110_av_register(av7110);
1357 av7110_ca_register(av7110);
1358
1359#ifdef CONFIG_DVB_AV7110_OSD
1360 dvb_register_device(&av7110->dvb_adapter, &av7110->osd_dev,
1361 &dvbdev_osd, av7110, DVB_DEVICE_OSD);
1362#endif
1363
1364 dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net, &dvbdemux->dmx);
1365
1366 if (budgetpatch) {
1367 /* initialize software demux1 without its own frontend
1368 * demux1 hardware is connected to frontend0 of demux0
1369 */
1370 dvbdemux1->priv = (void *) av7110;
1371
1372 dvbdemux1->filternum = 256;
1373 dvbdemux1->feednum = 256;
1374 dvbdemux1->start_feed = budget_start_feed;
1375 dvbdemux1->stop_feed = budget_stop_feed;
1376 dvbdemux1->write_to_decoder = NULL;
1377
1378 dvbdemux1->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1379 DMX_MEMORY_BASED_FILTERING);
1380
1381 dvb_dmx_init(&av7110->demux1);
1382
1383 av7110->dmxdev1.filternum = 256;
1384 av7110->dmxdev1.demux = &dvbdemux1->dmx;
1385 av7110->dmxdev1.capabilities = 0;
1386
1387 dvb_dmxdev_init(&av7110->dmxdev1, &av7110->dvb_adapter);
1388
1389 dvb_net_init(&av7110->dvb_adapter, &av7110->dvb_net1, &dvbdemux1->dmx);
1390 printk("dvb-ttpci: additional demux1 for budget-patch registered\n");
1391 }
1392 return 0;
1393}
1394
1395
1396static void dvb_unregister(struct av7110 *av7110)
1397{
1398 struct dvb_demux *dvbdemux = &av7110->demux;
1399 struct dvb_demux *dvbdemux1 = &av7110->demux1;
1400
1401 dprintk(4, "%p\n", av7110);
1402
1403 if (!av7110->registered)
1404 return;
1405
1406 if (budgetpatch) {
1407 dvb_net_release(&av7110->dvb_net1);
1408 dvbdemux->dmx.close(&dvbdemux1->dmx);
1409 dvb_dmxdev_release(&av7110->dmxdev1);
1410 dvb_dmx_release(&av7110->demux1);
1411 }
1412
1413 dvb_net_release(&av7110->dvb_net);
1414
1415 dvbdemux->dmx.close(&dvbdemux->dmx);
1416 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &av7110->hw_frontend);
1417 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &av7110->mem_frontend);
1418
1419 dvb_dmxdev_release(&av7110->dmxdev);
1420 dvb_dmx_release(&av7110->demux);
1421
1422 if (av7110->fe != NULL) {
1423 dvb_unregister_frontend(av7110->fe);
1424 dvb_frontend_detach(av7110->fe);
1425 }
1426 dvb_unregister_device(av7110->osd_dev);
1427 av7110_av_unregister(av7110);
1428 av7110_ca_unregister(av7110);
1429}
1430
1431
1432/****************************************************************************
1433 * I2C client commands
1434 ****************************************************************************/
1435
1436int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val)
1437{
1438 u8 msg[2] = { reg, val };
1439 struct i2c_msg msgs;
1440
1441 msgs.flags = 0;
1442 msgs.addr = id / 2;
1443 msgs.len = 2;
1444 msgs.buf = msg;
1445 return i2c_transfer(&av7110->i2c_adap, &msgs, 1);
1446}
1447
1448u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg)
1449{
1450 u8 mm1[] = {0x00};
1451 u8 mm2[] = {0x00};
1452 struct i2c_msg msgs[2];
1453
1454 msgs[0].flags = 0;
1455 msgs[1].flags = I2C_M_RD;
1456 msgs[0].addr = msgs[1].addr = id / 2;
1457 mm1[0] = reg;
1458 msgs[0].len = 1; msgs[1].len = 1;
1459 msgs[0].buf = mm1; msgs[1].buf = mm2;
1460 i2c_transfer(&av7110->i2c_adap, msgs, 2);
1461
1462 return mm2[0];
1463}
1464
1465/****************************************************************************
1466 * INITIALIZATION
1467 ****************************************************************************/
1468
1469
1470static int check_firmware(struct av7110* av7110)
1471{
1472 u32 crc = 0, len = 0;
1473 unsigned char *ptr;
1474
1475 /* check for firmware magic */
1476 ptr = av7110->bin_fw;
1477 if (ptr[0] != 'A' || ptr[1] != 'V' ||
1478 ptr[2] != 'F' || ptr[3] != 'W') {
1479 printk("dvb-ttpci: this is not an av7110 firmware\n");
1480 return -EINVAL;
1481 }
1482 ptr += 4;
1483
1484 /* check dpram file */
1485 crc = get_unaligned_be32(ptr);
1486 ptr += 4;
1487 len = get_unaligned_be32(ptr);
1488 ptr += 4;
1489 if (len >= 512) {
1490 printk("dvb-ttpci: dpram file is way too big.\n");
1491 return -EINVAL;
1492 }
1493 if (crc != crc32_le(0, ptr, len)) {
1494 printk("dvb-ttpci: crc32 of dpram file does not match.\n");
1495 return -EINVAL;
1496 }
1497 av7110->bin_dpram = ptr;
1498 av7110->size_dpram = len;
1499 ptr += len;
1500
1501 /* check root file */
1502 crc = get_unaligned_be32(ptr);
1503 ptr += 4;
1504 len = get_unaligned_be32(ptr);
1505 ptr += 4;
1506
1507 if (len <= 200000 || len >= 300000 ||
1508 len > ((av7110->bin_fw + av7110->size_fw) - ptr)) {
1509 printk("dvb-ttpci: root file has strange size (%d). aborting.\n", len);
1510 return -EINVAL;
1511 }
1512 if( crc != crc32_le(0, ptr, len)) {
1513 printk("dvb-ttpci: crc32 of root file does not match.\n");
1514 return -EINVAL;
1515 }
1516 av7110->bin_root = ptr;
1517 av7110->size_root = len;
1518 return 0;
1519}
1520
1521static void put_firmware(struct av7110* av7110)
1522{
1523 vfree(av7110->bin_fw);
1524}
1525
1526static int get_firmware(struct av7110* av7110)
1527{
1528 int ret;
1529 const struct firmware *fw;
1530
1531 /* request the av7110 firmware, this will block until someone uploads it */
1532 ret = request_firmware(&fw, "dvb-ttpci-01.fw", &av7110->dev->pci->dev);
1533 if (ret) {
1534 if (ret == -ENOENT) {
1535 printk(KERN_ERR "dvb-ttpci: could not load firmware,"
1536 " file not found: dvb-ttpci-01.fw\n");
1537 printk(KERN_ERR "dvb-ttpci: usually this should be in "
1538 "/usr/lib/hotplug/firmware or /lib/firmware\n");
1539 printk(KERN_ERR "dvb-ttpci: and can be downloaded from"
1540 " http://www.linuxtv.org/download/dvb/firmware/\n");
1541 } else
1542 printk(KERN_ERR "dvb-ttpci: cannot request firmware"
1543 " (error %i)\n", ret);
1544 return -EINVAL;
1545 }
1546
1547 if (fw->size <= 200000) {
1548 printk("dvb-ttpci: this firmware is way too small.\n");
1549 release_firmware(fw);
1550 return -EINVAL;
1551 }
1552
1553 /* check if the firmware is available */
1554 av7110->bin_fw = vmalloc(fw->size);
1555 if (NULL == av7110->bin_fw) {
1556 dprintk(1, "out of memory\n");
1557 release_firmware(fw);
1558 return -ENOMEM;
1559 }
1560
1561 memcpy(av7110->bin_fw, fw->data, fw->size);
1562 av7110->size_fw = fw->size;
1563 if ((ret = check_firmware(av7110)))
1564 vfree(av7110->bin_fw);
1565
1566 release_firmware(fw);
1567 return ret;
1568}
1569
1570static int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe)
1571{
1572 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1573 struct av7110* av7110 = fe->dvb->priv;
1574 u8 pwr = 0;
1575 u8 buf[4];
1576 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
1577 u32 div = (p->frequency + 479500) / 125;
1578
1579 if (p->frequency > 2000000)
1580 pwr = 3;
1581 else if (p->frequency > 1800000)
1582 pwr = 2;
1583 else if (p->frequency > 1600000)
1584 pwr = 1;
1585 else if (p->frequency > 1200000)
1586 pwr = 0;
1587 else if (p->frequency >= 1100000)
1588 pwr = 1;
1589 else
1590 pwr = 2;
1591
1592 buf[0] = (div >> 8) & 0x7f;
1593 buf[1] = div & 0xff;
1594 buf[2] = ((div & 0x18000) >> 10) | 0x95;
1595 buf[3] = (pwr << 6) | 0x30;
1596
1597 // NOTE: since we're using a prescaler of 2, we set the
1598 // divisor frequency to 62.5kHz and divide by 125 above
1599
1600 if (fe->ops.i2c_gate_ctrl)
1601 fe->ops.i2c_gate_ctrl(fe, 1);
1602 if (i2c_transfer (&av7110->i2c_adap, &msg, 1) != 1)
1603 return -EIO;
1604 return 0;
1605}
1606
1607static struct ves1x93_config alps_bsrv2_config = {
1608 .demod_address = 0x08,
1609 .xin = 90100000UL,
1610 .invert_pwm = 0,
1611};
1612
1613static int alps_tdbe2_tuner_set_params(struct dvb_frontend *fe)
1614{
1615 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1616 struct av7110* av7110 = fe->dvb->priv;
1617 u32 div;
1618 u8 data[4];
1619 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
1620
1621 div = (p->frequency + 35937500 + 31250) / 62500;
1622
1623 data[0] = (div >> 8) & 0x7f;
1624 data[1] = div & 0xff;
1625 data[2] = 0x85 | ((div >> 10) & 0x60);
1626 data[3] = (p->frequency < 174000000 ? 0x88 : p->frequency < 470000000 ? 0x84 : 0x81);
1627
1628 if (fe->ops.i2c_gate_ctrl)
1629 fe->ops.i2c_gate_ctrl(fe, 1);
1630 if (i2c_transfer(&av7110->i2c_adap, &msg, 1) != 1)
1631 return -EIO;
1632 return 0;
1633}
1634
1635static struct ves1820_config alps_tdbe2_config = {
1636 .demod_address = 0x09,
1637 .xin = 57840000UL,
1638 .invert = 1,
1639 .selagc = VES1820_SELAGC_SIGNAMPERR,
1640};
1641
1642
1643
1644
1645static int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe)
1646{
1647 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1648 struct av7110* av7110 = fe->dvb->priv;
1649 u32 div;
1650 u8 data[4];
1651 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1652
1653 div = p->frequency / 125;
1654 data[0] = (div >> 8) & 0x7f;
1655 data[1] = div & 0xff;
1656 data[2] = 0x8e;
1657 data[3] = 0x00;
1658
1659 if (fe->ops.i2c_gate_ctrl)
1660 fe->ops.i2c_gate_ctrl(fe, 1);
1661 if (i2c_transfer(&av7110->i2c_adap, &msg, 1) != 1)
1662 return -EIO;
1663 return 0;
1664}
1665
1666static struct tda8083_config grundig_29504_451_config = {
1667 .demod_address = 0x68,
1668};
1669
1670
1671
1672static int philips_cd1516_tuner_set_params(struct dvb_frontend *fe)
1673{
1674 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1675 struct av7110* av7110 = fe->dvb->priv;
1676 u32 div;
1677 u32 f = p->frequency;
1678 u8 data[4];
1679 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1680
1681 div = (f + 36125000 + 31250) / 62500;
1682
1683 data[0] = (div >> 8) & 0x7f;
1684 data[1] = div & 0xff;
1685 data[2] = 0x8e;
1686 data[3] = (f < 174000000 ? 0xa1 : f < 470000000 ? 0x92 : 0x34);
1687
1688 if (fe->ops.i2c_gate_ctrl)
1689 fe->ops.i2c_gate_ctrl(fe, 1);
1690 if (i2c_transfer(&av7110->i2c_adap, &msg, 1) != 1)
1691 return -EIO;
1692 return 0;
1693}
1694
1695static struct ves1820_config philips_cd1516_config = {
1696 .demod_address = 0x09,
1697 .xin = 57840000UL,
1698 .invert = 1,
1699 .selagc = VES1820_SELAGC_SIGNAMPERR,
1700};
1701
1702
1703
1704static int alps_tdlb7_tuner_set_params(struct dvb_frontend *fe)
1705{
1706 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1707 struct av7110* av7110 = fe->dvb->priv;
1708 u32 div, pwr;
1709 u8 data[4];
1710 struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = sizeof(data) };
1711
1712 div = (p->frequency + 36200000) / 166666;
1713
1714 if (p->frequency <= 782000000)
1715 pwr = 1;
1716 else
1717 pwr = 2;
1718
1719 data[0] = (div >> 8) & 0x7f;
1720 data[1] = div & 0xff;
1721 data[2] = 0x85;
1722 data[3] = pwr << 6;
1723
1724 if (fe->ops.i2c_gate_ctrl)
1725 fe->ops.i2c_gate_ctrl(fe, 1);
1726 if (i2c_transfer(&av7110->i2c_adap, &msg, 1) != 1)
1727 return -EIO;
1728 return 0;
1729}
1730
1731static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
1732{
1733#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE)
1734 struct av7110* av7110 = fe->dvb->priv;
1735
1736 return request_firmware(fw, name, &av7110->dev->pci->dev);
1737#else
1738 return -EINVAL;
1739#endif
1740}
1741
1742static struct sp8870_config alps_tdlb7_config = {
1743
1744 .demod_address = 0x71,
1745 .request_firmware = alps_tdlb7_request_firmware,
1746};
1747
1748
1749static u8 nexusca_stv0297_inittab[] = {
1750 0x80, 0x01,
1751 0x80, 0x00,
1752 0x81, 0x01,
1753 0x81, 0x00,
1754 0x00, 0x09,
1755 0x01, 0x69,
1756 0x03, 0x00,
1757 0x04, 0x00,
1758 0x07, 0x00,
1759 0x08, 0x00,
1760 0x20, 0x00,
1761 0x21, 0x40,
1762 0x22, 0x00,
1763 0x23, 0x00,
1764 0x24, 0x40,
1765 0x25, 0x88,
1766 0x30, 0xff,
1767 0x31, 0x00,
1768 0x32, 0xff,
1769 0x33, 0x00,
1770 0x34, 0x50,
1771 0x35, 0x7f,
1772 0x36, 0x00,
1773 0x37, 0x20,
1774 0x38, 0x00,
1775 0x40, 0x1c,
1776 0x41, 0xff,
1777 0x42, 0x29,
1778 0x43, 0x00,
1779 0x44, 0xff,
1780 0x45, 0x00,
1781 0x46, 0x00,
1782 0x49, 0x04,
1783 0x4a, 0x00,
1784 0x4b, 0x7b,
1785 0x52, 0x30,
1786 0x55, 0xae,
1787 0x56, 0x47,
1788 0x57, 0xe1,
1789 0x58, 0x3a,
1790 0x5a, 0x1e,
1791 0x5b, 0x34,
1792 0x60, 0x00,
1793 0x63, 0x00,
1794 0x64, 0x00,
1795 0x65, 0x00,
1796 0x66, 0x00,
1797 0x67, 0x00,
1798 0x68, 0x00,
1799 0x69, 0x00,
1800 0x6a, 0x02,
1801 0x6b, 0x00,
1802 0x70, 0xff,
1803 0x71, 0x00,
1804 0x72, 0x00,
1805 0x73, 0x00,
1806 0x74, 0x0c,
1807 0x80, 0x00,
1808 0x81, 0x00,
1809 0x82, 0x00,
1810 0x83, 0x00,
1811 0x84, 0x04,
1812 0x85, 0x80,
1813 0x86, 0x24,
1814 0x87, 0x78,
1815 0x88, 0x10,
1816 0x89, 0x00,
1817 0x90, 0x01,
1818 0x91, 0x01,
1819 0xa0, 0x04,
1820 0xa1, 0x00,
1821 0xa2, 0x00,
1822 0xb0, 0x91,
1823 0xb1, 0x0b,
1824 0xc0, 0x53,
1825 0xc1, 0x70,
1826 0xc2, 0x12,
1827 0xd0, 0x00,
1828 0xd1, 0x00,
1829 0xd2, 0x00,
1830 0xd3, 0x00,
1831 0xd4, 0x00,
1832 0xd5, 0x00,
1833 0xde, 0x00,
1834 0xdf, 0x00,
1835 0x61, 0x49,
1836 0x62, 0x0b,
1837 0x53, 0x08,
1838 0x59, 0x08,
1839 0xff, 0xff,
1840};
1841
1842static int nexusca_stv0297_tuner_set_params(struct dvb_frontend *fe)
1843{
1844 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1845 struct av7110* av7110 = fe->dvb->priv;
1846 u32 div;
1847 u8 data[4];
1848 struct i2c_msg msg = { .addr = 0x63, .flags = 0, .buf = data, .len = sizeof(data) };
1849 struct i2c_msg readmsg = { .addr = 0x63, .flags = I2C_M_RD, .buf = data, .len = 1 };
1850 int i;
1851
1852 div = (p->frequency + 36150000 + 31250) / 62500;
1853
1854 data[0] = (div >> 8) & 0x7f;
1855 data[1] = div & 0xff;
1856 data[2] = 0xce;
1857
1858 if (p->frequency < 45000000)
1859 return -EINVAL;
1860 else if (p->frequency < 137000000)
1861 data[3] = 0x01;
1862 else if (p->frequency < 403000000)
1863 data[3] = 0x02;
1864 else if (p->frequency < 860000000)
1865 data[3] = 0x04;
1866 else
1867 return -EINVAL;
1868
1869 if (fe->ops.i2c_gate_ctrl)
1870 fe->ops.i2c_gate_ctrl(fe, 1);
1871 if (i2c_transfer(&av7110->i2c_adap, &msg, 1) != 1) {
1872 printk("nexusca: pll transfer failed!\n");
1873 return -EIO;
1874 }
1875
1876 // wait for PLL lock
1877 for(i = 0; i < 20; i++) {
1878 if (fe->ops.i2c_gate_ctrl)
1879 fe->ops.i2c_gate_ctrl(fe, 1);
1880 if (i2c_transfer(&av7110->i2c_adap, &readmsg, 1) == 1)
1881 if (data[0] & 0x40) break;
1882 msleep(10);
1883 }
1884
1885 return 0;
1886}
1887
1888static struct stv0297_config nexusca_stv0297_config = {
1889
1890 .demod_address = 0x1C,
1891 .inittab = nexusca_stv0297_inittab,
1892 .invert = 1,
1893 .stop_during_read = 1,
1894};
1895
1896
1897
1898static int grundig_29504_401_tuner_set_params(struct dvb_frontend *fe)
1899{
1900 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1901 struct av7110* av7110 = fe->dvb->priv;
1902 u32 div;
1903 u8 cfg, cpump, band_select;
1904 u8 data[4];
1905 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
1906
1907 div = (36125000 + p->frequency) / 166666;
1908
1909 cfg = 0x88;
1910
1911 if (p->frequency < 175000000)
1912 cpump = 2;
1913 else if (p->frequency < 390000000)
1914 cpump = 1;
1915 else if (p->frequency < 470000000)
1916 cpump = 2;
1917 else if (p->frequency < 750000000)
1918 cpump = 1;
1919 else
1920 cpump = 3;
1921
1922 if (p->frequency < 175000000)
1923 band_select = 0x0e;
1924 else if (p->frequency < 470000000)
1925 band_select = 0x05;
1926 else
1927 band_select = 0x03;
1928
1929 data[0] = (div >> 8) & 0x7f;
1930 data[1] = div & 0xff;
1931 data[2] = ((div >> 10) & 0x60) | cfg;
1932 data[3] = (cpump << 6) | band_select;
1933
1934 if (fe->ops.i2c_gate_ctrl)
1935 fe->ops.i2c_gate_ctrl(fe, 1);
1936 if (i2c_transfer (&av7110->i2c_adap, &msg, 1) != 1) return -EIO;
1937 return 0;
1938}
1939
1940static struct l64781_config grundig_29504_401_config = {
1941 .demod_address = 0x55,
1942};
1943
1944
1945
1946static int av7110_fe_lock_fix(struct av7110* av7110, fe_status_t status)
1947{
1948 int ret = 0;
1949 int synced = (status & FE_HAS_LOCK) ? 1 : 0;
1950
1951 av7110->fe_status = status;
1952
1953 if (av7110->fe_synced == synced)
1954 return 0;
1955
1956 if (av7110->playing) {
1957 av7110->fe_synced = synced;
1958 return 0;
1959 }
1960
1961 if (mutex_lock_interruptible(&av7110->pid_mutex))
1962 return -ERESTARTSYS;
1963
1964 if (synced) {
1965 ret = SetPIDs(av7110, av7110->pids[DMX_PES_VIDEO],
1966 av7110->pids[DMX_PES_AUDIO],
1967 av7110->pids[DMX_PES_TELETEXT], 0,
1968 av7110->pids[DMX_PES_PCR]);
1969 if (!ret)
1970 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
1971 } else {
1972 ret = SetPIDs(av7110, 0, 0, 0, 0, 0);
1973 if (!ret) {
1974 ret = av7110_fw_cmd(av7110, COMTYPE_PID_FILTER, FlushTSQueue, 0);
1975 if (!ret)
1976 ret = av7110_wait_msgstate(av7110, GPMQBusy);
1977 }
1978 }
1979
1980 if (!ret)
1981 av7110->fe_synced = synced;
1982
1983 mutex_unlock(&av7110->pid_mutex);
1984 return ret;
1985}
1986
1987static int av7110_fe_set_frontend(struct dvb_frontend *fe)
1988{
1989 struct av7110* av7110 = fe->dvb->priv;
1990
1991 int ret = av7110_fe_lock_fix(av7110, 0);
1992 if (!ret)
1993 ret = av7110->fe_set_frontend(fe);
1994
1995 return ret;
1996}
1997
1998static int av7110_fe_init(struct dvb_frontend* fe)
1999{
2000 struct av7110* av7110 = fe->dvb->priv;
2001
2002 int ret = av7110_fe_lock_fix(av7110, 0);
2003 if (!ret)
2004 ret = av7110->fe_init(fe);
2005 return ret;
2006}
2007
2008static int av7110_fe_read_status(struct dvb_frontend* fe, fe_status_t* status)
2009{
2010 struct av7110* av7110 = fe->dvb->priv;
2011
2012 /* call the real implementation */
2013 int ret = av7110->fe_read_status(fe, status);
2014 if (!ret)
2015 if (((*status ^ av7110->fe_status) & FE_HAS_LOCK) && (*status & FE_HAS_LOCK))
2016 ret = av7110_fe_lock_fix(av7110, *status);
2017 return ret;
2018}
2019
2020static int av7110_fe_diseqc_reset_overload(struct dvb_frontend* fe)
2021{
2022 struct av7110* av7110 = fe->dvb->priv;
2023
2024 int ret = av7110_fe_lock_fix(av7110, 0);
2025 if (!ret)
2026 ret = av7110->fe_diseqc_reset_overload(fe);
2027 return ret;
2028}
2029
2030static int av7110_fe_diseqc_send_master_cmd(struct dvb_frontend* fe,
2031 struct dvb_diseqc_master_cmd* cmd)
2032{
2033 struct av7110* av7110 = fe->dvb->priv;
2034
2035 int ret = av7110_fe_lock_fix(av7110, 0);
2036 if (!ret) {
2037 av7110->saved_master_cmd = *cmd;
2038 ret = av7110->fe_diseqc_send_master_cmd(fe, cmd);
2039 }
2040 return ret;
2041}
2042
2043static int av7110_fe_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
2044{
2045 struct av7110* av7110 = fe->dvb->priv;
2046
2047 int ret = av7110_fe_lock_fix(av7110, 0);
2048 if (!ret) {
2049 av7110->saved_minicmd = minicmd;
2050 ret = av7110->fe_diseqc_send_burst(fe, minicmd);
2051 }
2052 return ret;
2053}
2054
2055static int av7110_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
2056{
2057 struct av7110* av7110 = fe->dvb->priv;
2058
2059 int ret = av7110_fe_lock_fix(av7110, 0);
2060 if (!ret) {
2061 av7110->saved_tone = tone;
2062 ret = av7110->fe_set_tone(fe, tone);
2063 }
2064 return ret;
2065}
2066
2067static int av7110_fe_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
2068{
2069 struct av7110* av7110 = fe->dvb->priv;
2070
2071 int ret = av7110_fe_lock_fix(av7110, 0);
2072 if (!ret) {
2073 av7110->saved_voltage = voltage;
2074 ret = av7110->fe_set_voltage(fe, voltage);
2075 }
2076 return ret;
2077}
2078
2079static int av7110_fe_dishnetwork_send_legacy_command(struct dvb_frontend* fe, unsigned long cmd)
2080{
2081 struct av7110* av7110 = fe->dvb->priv;
2082
2083 int ret = av7110_fe_lock_fix(av7110, 0);
2084 if (!ret)
2085 ret = av7110->fe_dishnetwork_send_legacy_command(fe, cmd);
2086 return ret;
2087}
2088
2089static void dvb_s_recover(struct av7110* av7110)
2090{
2091 av7110_fe_init(av7110->fe);
2092
2093 av7110_fe_set_voltage(av7110->fe, av7110->saved_voltage);
2094 if (av7110->saved_master_cmd.msg_len) {
2095 msleep(20);
2096 av7110_fe_diseqc_send_master_cmd(av7110->fe, &av7110->saved_master_cmd);
2097 }
2098 msleep(20);
2099 av7110_fe_diseqc_send_burst(av7110->fe, av7110->saved_minicmd);
2100 msleep(20);
2101 av7110_fe_set_tone(av7110->fe, av7110->saved_tone);
2102
2103 av7110_fe_set_frontend(av7110->fe);
2104}
2105
2106static u8 read_pwm(struct av7110* av7110)
2107{
2108 u8 b = 0xff;
2109 u8 pwm;
2110 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
2111 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
2112
2113 if ((i2c_transfer(&av7110->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
2114 pwm = 0x48;
2115
2116 return pwm;
2117}
2118
2119static int frontend_init(struct av7110 *av7110)
2120{
2121 int ret;
2122
2123 if (av7110->dev->pci->subsystem_vendor == 0x110a) {
2124 switch(av7110->dev->pci->subsystem_device) {
2125 case 0x0000: // Fujitsu/Siemens DVB-Cable (ves1820/Philips CD1516(??))
2126 av7110->fe = dvb_attach(ves1820_attach, &philips_cd1516_config,
2127 &av7110->i2c_adap, read_pwm(av7110));
2128 if (av7110->fe) {
2129 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params;
2130 }
2131 break;
2132 }
2133
2134 } else if (av7110->dev->pci->subsystem_vendor == 0x13c2) {
2135 switch(av7110->dev->pci->subsystem_device) {
2136 case 0x0000: // Hauppauge/TT WinTV DVB-S rev1.X
2137 case 0x0003: // Hauppauge/TT WinTV Nexus-S Rev 2.X
2138 case 0x1002: // Hauppauge/TT WinTV DVB-S rev1.3SE
2139
2140 // try the ALPS BSRV2 first of all
2141 av7110->fe = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &av7110->i2c_adap);
2142 if (av7110->fe) {
2143 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
2144 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
2145 av7110->fe->ops.diseqc_send_burst = av7110_diseqc_send_burst;
2146 av7110->fe->ops.set_tone = av7110_set_tone;
2147 av7110->recover = dvb_s_recover;
2148 break;
2149 }
2150
2151 // try the ALPS BSRU6 now
2152 av7110->fe = dvb_attach(stv0299_attach, &alps_bsru6_config, &av7110->i2c_adap);
2153 if (av7110->fe) {
2154 av7110->fe->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
2155 av7110->fe->tuner_priv = &av7110->i2c_adap;
2156
2157 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
2158 av7110->fe->ops.diseqc_send_burst = av7110_diseqc_send_burst;
2159 av7110->fe->ops.set_tone = av7110_set_tone;
2160 av7110->recover = dvb_s_recover;
2161 break;
2162 }
2163
2164 // Try the grundig 29504-451
2165 av7110->fe = dvb_attach(tda8083_attach, &grundig_29504_451_config, &av7110->i2c_adap);
2166 if (av7110->fe) {
2167 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
2168 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
2169 av7110->fe->ops.diseqc_send_burst = av7110_diseqc_send_burst;
2170 av7110->fe->ops.set_tone = av7110_set_tone;
2171 av7110->recover = dvb_s_recover;
2172 break;
2173 }
2174
2175 /* Try DVB-C cards */
2176 switch(av7110->dev->pci->subsystem_device) {
2177 case 0x0000:
2178 /* Siemens DVB-C (full-length card) VES1820/Philips CD1516 */
2179 av7110->fe = dvb_attach(ves1820_attach, &philips_cd1516_config, &av7110->i2c_adap,
2180 read_pwm(av7110));
2181 if (av7110->fe) {
2182 av7110->fe->ops.tuner_ops.set_params = philips_cd1516_tuner_set_params;
2183 }
2184 break;
2185 case 0x0003:
2186 /* Hauppauge DVB-C 2.1 VES1820/ALPS TDBE2 */
2187 av7110->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &av7110->i2c_adap,
2188 read_pwm(av7110));
2189 if (av7110->fe) {
2190 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
2191 }
2192 break;
2193 }
2194 break;
2195
2196 case 0x0001: // Hauppauge/TT Nexus-T premium rev1.X
2197 // try ALPS TDLB7 first, then Grundig 29504-401
2198 av7110->fe = dvb_attach(sp8870_attach, &alps_tdlb7_config, &av7110->i2c_adap);
2199 if (av7110->fe) {
2200 av7110->fe->ops.tuner_ops.set_params = alps_tdlb7_tuner_set_params;
2201 break;
2202 }
2203 /* fall-thru */
2204
2205 case 0x0008: // Hauppauge/TT DVB-T
2206 // Grundig 29504-401
2207 av7110->fe = dvb_attach(l64781_attach, &grundig_29504_401_config, &av7110->i2c_adap);
2208 if (av7110->fe)
2209 av7110->fe->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
2210 break;
2211
2212 case 0x0002: // Hauppauge/TT DVB-C premium rev2.X
2213
2214 av7110->fe = dvb_attach(ves1820_attach, &alps_tdbe2_config, &av7110->i2c_adap, read_pwm(av7110));
2215 if (av7110->fe) {
2216 av7110->fe->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
2217 }
2218 break;
2219
2220 case 0x0004: // Galaxis DVB-S rev1.3
2221 /* ALPS BSRV2 */
2222 av7110->fe = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &av7110->i2c_adap);
2223 if (av7110->fe) {
2224 av7110->fe->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
2225 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
2226 av7110->fe->ops.diseqc_send_burst = av7110_diseqc_send_burst;
2227 av7110->fe->ops.set_tone = av7110_set_tone;
2228 av7110->recover = dvb_s_recover;
2229 }
2230 break;
2231
2232 case 0x0006: /* Fujitsu-Siemens DVB-S rev 1.6 */
2233 /* Grundig 29504-451 */
2234 av7110->fe = dvb_attach(tda8083_attach, &grundig_29504_451_config, &av7110->i2c_adap);
2235 if (av7110->fe) {
2236 av7110->fe->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
2237 av7110->fe->ops.diseqc_send_master_cmd = av7110_diseqc_send_master_cmd;
2238 av7110->fe->ops.diseqc_send_burst = av7110_diseqc_send_burst;
2239 av7110->fe->ops.set_tone = av7110_set_tone;
2240 av7110->recover = dvb_s_recover;
2241 }
2242 break;
2243
2244 case 0x000A: // Hauppauge/TT Nexus-CA rev1.X
2245
2246 av7110->fe = dvb_attach(stv0297_attach, &nexusca_stv0297_config, &av7110->i2c_adap);
2247 if (av7110->fe) {
2248 av7110->fe->ops.tuner_ops.set_params = nexusca_stv0297_tuner_set_params;
2249
2250 /* set TDA9819 into DVB mode */
2251 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
2252 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
2253
2254 /* tuner on this needs a slower i2c bus speed */
2255 av7110->dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
2256 break;
2257 }
2258 break;
2259
2260 case 0x000E: /* Hauppauge/TT Nexus-S rev 2.3 */
2261 /* ALPS BSBE1 */
2262 av7110->fe = dvb_attach(stv0299_attach, &alps_bsbe1_config, &av7110->i2c_adap);
2263 if (av7110->fe) {
2264 av7110->fe->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
2265 av7110->fe->tuner_priv = &av7110->i2c_adap;
2266
2267 if (dvb_attach(lnbp21_attach, av7110->fe, &av7110->i2c_adap, 0, 0) == NULL) {
2268 printk("dvb-ttpci: LNBP21 not found!\n");
2269 if (av7110->fe->ops.release)
2270 av7110->fe->ops.release(av7110->fe);
2271 av7110->fe = NULL;
2272 } else {
2273 av7110->fe->ops.dishnetwork_send_legacy_command = NULL;
2274 av7110->recover = dvb_s_recover;
2275 }
2276 }
2277 break;
2278 }
2279 }
2280
2281 if (!av7110->fe) {
2282 /* FIXME: propagate the failure code from the lower layers */
2283 ret = -ENOMEM;
2284 printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
2285 av7110->dev->pci->vendor,
2286 av7110->dev->pci->device,
2287 av7110->dev->pci->subsystem_vendor,
2288 av7110->dev->pci->subsystem_device);
2289 } else {
2290 FE_FUNC_OVERRIDE(av7110->fe->ops.init, av7110->fe_init, av7110_fe_init);
2291 FE_FUNC_OVERRIDE(av7110->fe->ops.read_status, av7110->fe_read_status, av7110_fe_read_status);
2292 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_reset_overload, av7110->fe_diseqc_reset_overload, av7110_fe_diseqc_reset_overload);
2293 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_master_cmd, av7110->fe_diseqc_send_master_cmd, av7110_fe_diseqc_send_master_cmd);
2294 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_burst, av7110->fe_diseqc_send_burst, av7110_fe_diseqc_send_burst);
2295 FE_FUNC_OVERRIDE(av7110->fe->ops.set_tone, av7110->fe_set_tone, av7110_fe_set_tone);
2296 FE_FUNC_OVERRIDE(av7110->fe->ops.set_voltage, av7110->fe_set_voltage, av7110_fe_set_voltage);
2297 FE_FUNC_OVERRIDE(av7110->fe->ops.dishnetwork_send_legacy_command, av7110->fe_dishnetwork_send_legacy_command, av7110_fe_dishnetwork_send_legacy_command);
2298 FE_FUNC_OVERRIDE(av7110->fe->ops.set_frontend, av7110->fe_set_frontend, av7110_fe_set_frontend);
2299
2300 ret = dvb_register_frontend(&av7110->dvb_adapter, av7110->fe);
2301 if (ret < 0) {
2302 printk("av7110: Frontend registration failed!\n");
2303 dvb_frontend_detach(av7110->fe);
2304 av7110->fe = NULL;
2305 }
2306 }
2307 return ret;
2308}
2309
2310/* Budgetpatch note:
2311 * Original hardware design by Roberto Deza:
2312 * There is a DVB_Wiki at
2313 * http://www.linuxtv.org/
2314 *
2315 * New software triggering design by Emard that works on
2316 * original Roberto Deza's hardware:
2317 *
2318 * rps1 code for budgetpatch will copy internal HS event to GPIO3 pin.
2319 * GPIO3 is in budget-patch hardware connectd to port B VSYNC
2320 * HS is an internal event of 7146, accessible with RPS
2321 * and temporarily raised high every n lines
2322 * (n in defined in the RPS_THRESH1 counter threshold)
2323 * I think HS is raised high on the beginning of the n-th line
2324 * and remains high until this n-th line that triggered
2325 * it is completely received. When the receiption of n-th line
2326 * ends, HS is lowered.
2327 *
2328 * To transmit data over DMA, 7146 needs changing state at
2329 * port B VSYNC pin. Any changing of port B VSYNC will
2330 * cause some DMA data transfer, with more or less packets loss.
2331 * It depends on the phase and frequency of VSYNC and
2332 * the way of 7146 is instructed to trigger on port B (defined
2333 * in DD1_INIT register, 3rd nibble from the right valid
2334 * numbers are 0-7, see datasheet)
2335 *
2336 * The correct triggering can minimize packet loss,
2337 * dvbtraffic should give this stable bandwidths:
2338 * 22k transponder = 33814 kbit/s
2339 * 27.5k transponder = 38045 kbit/s
2340 * by experiment it is found that the best results
2341 * (stable bandwidths and almost no packet loss)
2342 * are obtained using DD1_INIT triggering number 2
2343 * (Va at rising edge of VS Fa = HS x VS-failing forced toggle)
2344 * and a VSYNC phase that occurs in the middle of DMA transfer
2345 * (about byte 188*512=96256 in the DMA window).
2346 *
2347 * Phase of HS is still not clear to me how to control,
2348 * It just happens to be so. It can be seen if one enables
2349 * RPS_IRQ and print Event Counter 1 in vpeirq(). Every
2350 * time RPS_INTERRUPT is called, the Event Counter 1 will
2351 * increment. That's how the 7146 is programmed to do event
2352 * counting in this budget-patch.c
2353 * I *think* HPS setting has something to do with the phase
2354 * of HS but I can't be 100% sure in that.
2355 *
2356 * hardware debug note: a working budget card (including budget patch)
2357 * with vpeirq() interrupt setup in mode "0x90" (every 64K) will
2358 * generate 3 interrupts per 25-Hz DMA frame of 2*188*512 bytes
2359 * and that means 3*25=75 Hz of interrupt freqency, as seen by
2360 * watch cat /proc/interrupts
2361 *
2362 * If this frequency is 3x lower (and data received in the DMA
2363 * buffer don't start with 0x47, but in the middle of packets,
2364 * whose lengths appear to be like 188 292 188 104 etc.
2365 * this means VSYNC line is not connected in the hardware.
2366 * (check soldering pcb and pins)
2367 * The same behaviour of missing VSYNC can be duplicated on budget
2368 * cards, by seting DD1_INIT trigger mode 7 in 3rd nibble.
2369 */
2370static int __devinit av7110_attach(struct saa7146_dev* dev,
2371 struct saa7146_pci_extension_data *pci_ext)
2372{
2373 const int length = TS_WIDTH * TS_HEIGHT;
2374 struct pci_dev *pdev = dev->pci;
2375 struct av7110 *av7110;
2376 struct task_struct *thread;
2377 int ret, count = 0;
2378
2379 dprintk(4, "dev: %p\n", dev);
2380
2381 /* Set RPS_IRQ to 1 to track rps1 activity.
2382 * Enabling this won't send any interrupt to PC CPU.
2383 */
2384#define RPS_IRQ 0
2385
2386 if (budgetpatch == 1) {
2387 budgetpatch = 0;
2388 /* autodetect the presence of budget patch
2389 * this only works if saa7146 has been recently
2390 * reset with with MASK_31 to MC1
2391 *
2392 * will wait for VBI_B event (vertical blank at port B)
2393 * and will reset GPIO3 after VBI_B is detected.
2394 * (GPIO3 should be raised high by CPU to
2395 * test if GPIO3 will generate vertical blank signal
2396 * in budget patch GPIO3 is connected to VSYNC_B
2397 */
2398
2399 /* RESET SAA7146 */
2400 saa7146_write(dev, MC1, MASK_31);
2401 /* autodetection success seems to be time-dependend after reset */
2402
2403 /* Fix VSYNC level */
2404 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
2405 /* set vsync_b triggering */
2406 saa7146_write(dev, DD1_STREAM_B, 0);
2407 /* port B VSYNC at rising edge */
2408 saa7146_write(dev, DD1_INIT, 0x00000200);
2409 saa7146_write(dev, BRS_CTRL, 0x00000000); // VBI
2410 saa7146_write(dev, MC2,
2411 1 * (MASK_08 | MASK_24) | // BRS control
2412 0 * (MASK_09 | MASK_25) | // a
2413 1 * (MASK_10 | MASK_26) | // b
2414 0 * (MASK_06 | MASK_22) | // HPS_CTRL1
2415 0 * (MASK_05 | MASK_21) | // HPS_CTRL2
2416 0 * (MASK_01 | MASK_15) // DEBI
2417 );
2418
2419 /* start writing RPS1 code from beginning */
2420 count = 0;
2421 /* Disable RPS1 */
2422 saa7146_write(dev, MC1, MASK_29);
2423 /* RPS1 timeout disable */
2424 saa7146_write(dev, RPS_TOV1, 0);
2425 WRITE_RPS1(CMD_PAUSE | EVT_VBI_B);
2426 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
2427 WRITE_RPS1(GPIO3_MSK);
2428 WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
2429#if RPS_IRQ
2430 /* issue RPS1 interrupt to increment counter */
2431 WRITE_RPS1(CMD_INTERRUPT);
2432#endif
2433 WRITE_RPS1(CMD_STOP);
2434 /* Jump to begin of RPS program as safety measure (p37) */
2435 WRITE_RPS1(CMD_JUMP);
2436 WRITE_RPS1(dev->d_rps1.dma_handle);
2437
2438#if RPS_IRQ
2439 /* set event counter 1 source as RPS1 interrupt (0x03) (rE4 p53)
2440 * use 0x03 to track RPS1 interrupts - increase by 1 every gpio3 is toggled
2441 * use 0x15 to track VPE interrupts - increase by 1 every vpeirq() is called
2442 */
2443 saa7146_write(dev, EC1SSR, (0x03<<2) | 3 );
2444 /* set event counter 1 threshold to maximum allowed value (rEC p55) */
2445 saa7146_write(dev, ECT1R, 0x3fff );
2446#endif
2447 /* Set RPS1 Address register to point to RPS code (r108 p42) */
2448 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
2449 /* Enable RPS1, (rFC p33) */
2450 saa7146_write(dev, MC1, (MASK_13 | MASK_29 ));
2451
2452 mdelay(10);
2453 /* now send VSYNC_B to rps1 by rising GPIO3 */
2454 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
2455 mdelay(10);
2456 /* if rps1 responded by lowering the GPIO3,
2457 * then we have budgetpatch hardware
2458 */
2459 if ((saa7146_read(dev, GPIO_CTRL) & 0x10000000) == 0) {
2460 budgetpatch = 1;
2461 printk("dvb-ttpci: BUDGET-PATCH DETECTED.\n");
2462 }
2463 /* Disable RPS1 */
2464 saa7146_write(dev, MC1, ( MASK_29 ));
2465#if RPS_IRQ
2466 printk("dvb-ttpci: Event Counter 1 0x%04x\n", saa7146_read(dev, EC1R) & 0x3fff );
2467#endif
2468 }
2469
2470 /* prepare the av7110 device struct */
2471 av7110 = kzalloc(sizeof(struct av7110), GFP_KERNEL);
2472 if (!av7110) {
2473 dprintk(1, "out of memory\n");
2474 return -ENOMEM;
2475 }
2476
2477 av7110->card_name = (char*) pci_ext->ext_priv;
2478 av7110->dev = dev;
2479 dev->ext_priv = av7110;
2480
2481 ret = get_firmware(av7110);
2482 if (ret < 0)
2483 goto err_kfree_0;
2484
2485 ret = dvb_register_adapter(&av7110->dvb_adapter, av7110->card_name,
2486 THIS_MODULE, &dev->pci->dev, adapter_nr);
2487 if (ret < 0)
2488 goto err_put_firmware_1;
2489
2490 /* the Siemens DVB needs this if you want to have the i2c chips
2491 get recognized before the main driver is fully loaded */
2492 saa7146_write(dev, GPIO_CTRL, 0x500000);
2493
2494 strlcpy(av7110->i2c_adap.name, pci_ext->ext_priv, sizeof(av7110->i2c_adap.name));
2495
2496 saa7146_i2c_adapter_prepare(dev, &av7110->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120); /* 275 kHz */
2497
2498 ret = i2c_add_adapter(&av7110->i2c_adap);
2499 if (ret < 0)
2500 goto err_dvb_unregister_adapter_2;
2501
2502 ttpci_eeprom_parse_mac(&av7110->i2c_adap,
2503 av7110->dvb_adapter.proposed_mac);
2504 ret = -ENOMEM;
2505
2506 /* full-ts mod? */
2507 if (full_ts)
2508 av7110->full_ts = true;
2509
2510 /* check for full-ts flag in eeprom */
2511 if (i2c_readreg(av7110, 0xaa, 0) == 0x4f && i2c_readreg(av7110, 0xaa, 1) == 0x45) {
2512 u8 flags = i2c_readreg(av7110, 0xaa, 2);
2513 if (flags != 0xff && (flags & 0x01))
2514 av7110->full_ts = true;
2515 }
2516
2517 if (av7110->full_ts) {
2518 printk(KERN_INFO "dvb-ttpci: full-ts mode enabled for saa7146 port B\n");
2519 spin_lock_init(&av7110->feedlock1);
2520 av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
2521 &av7110->pt);
2522 if (!av7110->grabbing)
2523 goto err_i2c_del_3;
2524
2525 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
2526 saa7146_write(dev, MC2, (MASK_10 | MASK_26));
2527
2528 saa7146_write(dev, DD1_INIT, 0x00000600);
2529 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
2530
2531 saa7146_write(dev, BRS_CTRL, 0x60000000);
2532 saa7146_write(dev, MC2, MASK_08 | MASK_24);
2533
2534 /* dma3 */
2535 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
2536 saa7146_write(dev, BASE_ODD3, 0);
2537 saa7146_write(dev, BASE_EVEN3, 0);
2538 saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT);
2539 saa7146_write(dev, PITCH3, TS_WIDTH);
2540 saa7146_write(dev, BASE_PAGE3, av7110->pt.dma | ME1 | 0x90);
2541 saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
2542 saa7146_write(dev, MC2, MASK_04 | MASK_20);
2543
2544 tasklet_init(&av7110->vpe_tasklet, vpeirq, (unsigned long) av7110);
2545
2546 } else if (budgetpatch) {
2547 spin_lock_init(&av7110->feedlock1);
2548 av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
2549 &av7110->pt);
2550 if (!av7110->grabbing)
2551 goto err_i2c_del_3;
2552
2553 saa7146_write(dev, PCI_BT_V1, 0x1c1f101f);
2554 saa7146_write(dev, BCS_CTRL, 0x80400040);
2555 /* set dd1 stream a & b */
2556 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
2557 saa7146_write(dev, DD1_INIT, 0x03000200);
2558 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
2559 saa7146_write(dev, BRS_CTRL, 0x60000000);
2560 saa7146_write(dev, BASE_ODD3, 0);
2561 saa7146_write(dev, BASE_EVEN3, 0);
2562 saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT);
2563 saa7146_write(dev, BASE_PAGE3, av7110->pt.dma | ME1 | 0x90);
2564
2565 saa7146_write(dev, PITCH3, TS_WIDTH);
2566 saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
2567
2568 /* upload all */
2569 saa7146_write(dev, MC2, 0x077c077c);
2570 saa7146_write(dev, GPIO_CTRL, 0x000000);
2571#if RPS_IRQ
2572 /* set event counter 1 source as RPS1 interrupt (0x03) (rE4 p53)
2573 * use 0x03 to track RPS1 interrupts - increase by 1 every gpio3 is toggled
2574 * use 0x15 to track VPE interrupts - increase by 1 every vpeirq() is called
2575 */
2576 saa7146_write(dev, EC1SSR, (0x03<<2) | 3 );
2577 /* set event counter 1 threshold to maximum allowed value (rEC p55) */
2578 saa7146_write(dev, ECT1R, 0x3fff );
2579#endif
2580 /* Setup BUDGETPATCH MAIN RPS1 "program" (p35) */
2581 count = 0;
2582
2583 /* Wait Source Line Counter Threshold (p36) */
2584 WRITE_RPS1(CMD_PAUSE | EVT_HS);
2585 /* Set GPIO3=1 (p42) */
2586 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
2587 WRITE_RPS1(GPIO3_MSK);
2588 WRITE_RPS1(SAA7146_GPIO_OUTHI<<24);
2589#if RPS_IRQ
2590 /* issue RPS1 interrupt */
2591 WRITE_RPS1(CMD_INTERRUPT);
2592#endif
2593 /* Wait reset Source Line Counter Threshold (p36) */
2594 WRITE_RPS1(CMD_PAUSE | RPS_INV | EVT_HS);
2595 /* Set GPIO3=0 (p42) */
2596 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
2597 WRITE_RPS1(GPIO3_MSK);
2598 WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
2599#if RPS_IRQ
2600 /* issue RPS1 interrupt */
2601 WRITE_RPS1(CMD_INTERRUPT);
2602#endif
2603 /* Jump to begin of RPS program (p37) */
2604 WRITE_RPS1(CMD_JUMP);
2605 WRITE_RPS1(dev->d_rps1.dma_handle);
2606
2607 /* Fix VSYNC level */
2608 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
2609 /* Set RPS1 Address register to point to RPS code (r108 p42) */
2610 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
2611 /* Set Source Line Counter Threshold, using BRS (rCC p43)
2612 * It generates HS event every TS_HEIGHT lines
2613 * this is related to TS_WIDTH set in register
2614 * NUM_LINE_BYTE3. If NUM_LINE_BYTE low 16 bits
2615 * are set to TS_WIDTH bytes (TS_WIDTH=2*188),
2616 * then RPS_THRESH1 should be set to trigger
2617 * every TS_HEIGHT (512) lines.
2618 */
2619 saa7146_write(dev, RPS_THRESH1, (TS_HEIGHT*1) | MASK_12 );
2620
2621 /* Enable RPS1 (rFC p33) */
2622 saa7146_write(dev, MC1, (MASK_13 | MASK_29));
2623
2624 /* end of budgetpatch register initialization */
2625 tasklet_init (&av7110->vpe_tasklet, vpeirq, (unsigned long) av7110);
2626 } else {
2627 saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
2628 saa7146_write(dev, BCS_CTRL, 0x80400040);
2629
2630 /* set dd1 stream a & b */
2631 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
2632 saa7146_write(dev, DD1_INIT, 0x03000000);
2633 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
2634
2635 /* upload all */
2636 saa7146_write(dev, MC2, 0x077c077c);
2637 saa7146_write(dev, GPIO_CTRL, 0x000000);
2638 }
2639
2640 tasklet_init (&av7110->debi_tasklet, debiirq, (unsigned long) av7110);
2641 tasklet_init (&av7110->gpio_tasklet, gpioirq, (unsigned long) av7110);
2642
2643 mutex_init(&av7110->pid_mutex);
2644
2645 /* locks for data transfers from/to AV7110 */
2646 spin_lock_init(&av7110->debilock);
2647 mutex_init(&av7110->dcomlock);
2648 av7110->debitype = -1;
2649
2650 /* default OSD window */
2651 av7110->osdwin = 1;
2652 mutex_init(&av7110->osd_mutex);
2653
2654 /* TV standard */
2655 av7110->vidmode = tv_standard == 1 ? AV7110_VIDEO_MODE_NTSC
2656 : AV7110_VIDEO_MODE_PAL;
2657
2658 /* ARM "watchdog" */
2659 init_waitqueue_head(&av7110->arm_wait);
2660 av7110->arm_thread = NULL;
2661
2662 /* allocate and init buffers */
2663 av7110->debi_virt = pci_alloc_consistent(pdev, 8192, &av7110->debi_bus);
2664 if (!av7110->debi_virt)
2665 goto err_saa71466_vfree_4;
2666
2667
2668 av7110->iobuf = vmalloc(AVOUTLEN+AOUTLEN+BMPLEN+4*IPACKS);
2669 if (!av7110->iobuf)
2670 goto err_pci_free_5;
2671
2672 ret = av7110_av_init(av7110);
2673 if (ret < 0)
2674 goto err_iobuf_vfree_6;
2675
2676 /* init BMP buffer */
2677 av7110->bmpbuf = av7110->iobuf+AVOUTLEN+AOUTLEN;
2678 init_waitqueue_head(&av7110->bmpq);
2679
2680 ret = av7110_ca_init(av7110);
2681 if (ret < 0)
2682 goto err_av7110_av_exit_7;
2683
2684 /* load firmware into AV7110 cards */
2685 ret = av7110_bootarm(av7110);
2686 if (ret < 0)
2687 goto err_av7110_ca_exit_8;
2688
2689 ret = av7110_firmversion(av7110);
2690 if (ret < 0)
2691 goto err_stop_arm_9;
2692
2693 if (FW_VERSION(av7110->arm_app)<0x2501)
2694 printk ("dvb-ttpci: Warning, firmware version 0x%04x is too old. "
2695 "System might be unstable!\n", FW_VERSION(av7110->arm_app));
2696
2697 thread = kthread_run(arm_thread, (void *) av7110, "arm_mon");
2698 if (IS_ERR(thread)) {
2699 ret = PTR_ERR(thread);
2700 goto err_stop_arm_9;
2701 }
2702 av7110->arm_thread = thread;
2703
2704 /* set initial volume in mixer struct */
2705 av7110->mixer.volume_left = volume;
2706 av7110->mixer.volume_right = volume;
2707
2708 ret = av7110_register(av7110);
2709 if (ret < 0)
2710 goto err_arm_thread_stop_10;
2711
2712 init_av7110_av(av7110);
2713
2714 /* special case DVB-C: these cards have an analog tuner
2715 plus need some special handling, so we have separate
2716 saa7146_ext_vv data for these... */
2717 ret = av7110_init_v4l(av7110);
2718 if (ret < 0)
2719 goto err_av7110_unregister_11;
2720
2721 av7110->dvb_adapter.priv = av7110;
2722 ret = frontend_init(av7110);
2723 if (ret < 0)
2724 goto err_av7110_exit_v4l_12;
2725
2726#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2727 av7110_ir_init(av7110);
2728#endif
2729 printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num);
2730 av7110_num++;
2731out:
2732 return ret;
2733
2734err_av7110_exit_v4l_12:
2735 av7110_exit_v4l(av7110);
2736err_av7110_unregister_11:
2737 dvb_unregister(av7110);
2738err_arm_thread_stop_10:
2739 av7110_arm_sync(av7110);
2740err_stop_arm_9:
2741 /* Nothing to do. Rejoice. */
2742err_av7110_ca_exit_8:
2743 av7110_ca_exit(av7110);
2744err_av7110_av_exit_7:
2745 av7110_av_exit(av7110);
2746err_iobuf_vfree_6:
2747 vfree(av7110->iobuf);
2748err_pci_free_5:
2749 pci_free_consistent(pdev, 8192, av7110->debi_virt, av7110->debi_bus);
2750err_saa71466_vfree_4:
2751 if (av7110->grabbing)
2752 saa7146_vfree_destroy_pgtable(pdev, av7110->grabbing, &av7110->pt);
2753err_i2c_del_3:
2754 i2c_del_adapter(&av7110->i2c_adap);
2755err_dvb_unregister_adapter_2:
2756 dvb_unregister_adapter(&av7110->dvb_adapter);
2757err_put_firmware_1:
2758 put_firmware(av7110);
2759err_kfree_0:
2760 kfree(av7110);
2761 goto out;
2762}
2763
2764static int __devexit av7110_detach(struct saa7146_dev* saa)
2765{
2766 struct av7110 *av7110 = saa->ext_priv;
2767 dprintk(4, "%p\n", av7110);
2768
2769#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2770 av7110_ir_exit(av7110);
2771#endif
2772 if (budgetpatch || av7110->full_ts) {
2773 if (budgetpatch) {
2774 /* Disable RPS1 */
2775 saa7146_write(saa, MC1, MASK_29);
2776 /* VSYNC LOW (inactive) */
2777 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
2778 }
2779 saa7146_write(saa, MC1, MASK_20); /* DMA3 off */
2780 SAA7146_IER_DISABLE(saa, MASK_10);
2781 SAA7146_ISR_CLEAR(saa, MASK_10);
2782 msleep(50);
2783 tasklet_kill(&av7110->vpe_tasklet);
2784 saa7146_vfree_destroy_pgtable(saa->pci, av7110->grabbing, &av7110->pt);
2785 }
2786 av7110_exit_v4l(av7110);
2787
2788 av7110_arm_sync(av7110);
2789
2790 tasklet_kill(&av7110->debi_tasklet);
2791 tasklet_kill(&av7110->gpio_tasklet);
2792
2793 dvb_unregister(av7110);
2794
2795 SAA7146_IER_DISABLE(saa, MASK_19 | MASK_03);
2796 SAA7146_ISR_CLEAR(saa, MASK_19 | MASK_03);
2797
2798 av7110_ca_exit(av7110);
2799 av7110_av_exit(av7110);
2800
2801 vfree(av7110->iobuf);
2802 pci_free_consistent(saa->pci, 8192, av7110->debi_virt,
2803 av7110->debi_bus);
2804
2805 i2c_del_adapter(&av7110->i2c_adap);
2806
2807 dvb_unregister_adapter (&av7110->dvb_adapter);
2808
2809 av7110_num--;
2810
2811 put_firmware(av7110);
2812
2813 kfree(av7110);
2814
2815 saa->ext_priv = NULL;
2816
2817 return 0;
2818}
2819
2820
2821static void av7110_irq(struct saa7146_dev* dev, u32 *isr)
2822{
2823 struct av7110 *av7110 = dev->ext_priv;
2824
2825 //print_time("av7110_irq");
2826
2827 /* Note: Don't try to handle the DEBI error irq (MASK_18), in
2828 * intel mode the timeout is asserted all the time...
2829 */
2830
2831 if (*isr & MASK_19) {
2832 //printk("av7110_irq: DEBI\n");
2833 /* Note 1: The DEBI irq is level triggered: We must enable it
2834 * only after we started a DMA xfer, and disable it here
2835 * immediately, or it will be signalled all the time while
2836 * DEBI is idle.
2837 * Note 2: You would think that an irq which is masked is
2838 * not signalled by the hardware. Not so for the SAA7146:
2839 * An irq is signalled as long as the corresponding bit
2840 * in the ISR is set, and disabling irqs just prevents the
2841 * hardware from setting the ISR bit. This means a) that we
2842 * must clear the ISR *after* disabling the irq (which is why
2843 * we must do it here even though saa7146_core did it already),
2844 * and b) that if we were to disable an edge triggered irq
2845 * (like the gpio irqs sadly are) temporarily we would likely
2846 * loose some. This sucks :-(
2847 */
2848 SAA7146_IER_DISABLE(av7110->dev, MASK_19);
2849 SAA7146_ISR_CLEAR(av7110->dev, MASK_19);
2850 tasklet_schedule(&av7110->debi_tasklet);
2851 }
2852
2853 if (*isr & MASK_03) {
2854 //printk("av7110_irq: GPIO\n");
2855 tasklet_schedule(&av7110->gpio_tasklet);
2856 }
2857
2858 if (*isr & MASK_10)
2859 tasklet_schedule(&av7110->vpe_tasklet);
2860}
2861
2862
2863static struct saa7146_extension av7110_extension_driver;
2864
2865#define MAKE_AV7110_INFO(x_var,x_name) \
2866static struct saa7146_pci_extension_data x_var = { \
2867 .ext_priv = x_name, \
2868 .ext = &av7110_extension_driver }
2869
2870MAKE_AV7110_INFO(tts_1_X_fsc,"Technotrend/Hauppauge WinTV DVB-S rev1.X or Fujitsu Siemens DVB-C");
2871MAKE_AV7110_INFO(ttt_1_X, "Technotrend/Hauppauge WinTV DVB-T rev1.X");
2872MAKE_AV7110_INFO(ttc_1_X, "Technotrend/Hauppauge WinTV Nexus-CA rev1.X");
2873MAKE_AV7110_INFO(ttc_2_X, "Technotrend/Hauppauge WinTV DVB-C rev2.X");
2874MAKE_AV7110_INFO(tts_2_X, "Technotrend/Hauppauge WinTV Nexus-S rev2.X");
2875MAKE_AV7110_INFO(tts_2_3, "Technotrend/Hauppauge WinTV Nexus-S rev2.3");
2876MAKE_AV7110_INFO(tts_1_3se, "Technotrend/Hauppauge WinTV DVB-S rev1.3 SE");
2877MAKE_AV7110_INFO(ttt, "Technotrend/Hauppauge DVB-T");
2878MAKE_AV7110_INFO(fsc, "Fujitsu Siemens DVB-C");
2879MAKE_AV7110_INFO(fss, "Fujitsu Siemens DVB-S rev1.6");
2880MAKE_AV7110_INFO(gxs_1_3, "Galaxis DVB-S rev1.3");
2881
2882static struct pci_device_id pci_tbl[] = {
2883 MAKE_EXTENSION_PCI(fsc, 0x110a, 0x0000),
2884 MAKE_EXTENSION_PCI(tts_1_X_fsc, 0x13c2, 0x0000),
2885 MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001),
2886 MAKE_EXTENSION_PCI(ttc_2_X, 0x13c2, 0x0002),
2887 MAKE_EXTENSION_PCI(tts_2_X, 0x13c2, 0x0003),
2888 MAKE_EXTENSION_PCI(gxs_1_3, 0x13c2, 0x0004),
2889 MAKE_EXTENSION_PCI(fss, 0x13c2, 0x0006),
2890 MAKE_EXTENSION_PCI(ttt, 0x13c2, 0x0008),
2891 MAKE_EXTENSION_PCI(ttc_1_X, 0x13c2, 0x000a),
2892 MAKE_EXTENSION_PCI(tts_2_3, 0x13c2, 0x000e),
2893 MAKE_EXTENSION_PCI(tts_1_3se, 0x13c2, 0x1002),
2894
2895/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0005), UNDEFINED CARD */ // Technisat SkyStar1
2896/* MAKE_EXTENSION_PCI(???, 0x13c2, 0x0009), UNDEFINED CARD */ // TT/Hauppauge WinTV Nexus-CA v????
2897
2898 {
2899 .vendor = 0,
2900 }
2901};
2902
2903MODULE_DEVICE_TABLE(pci, pci_tbl);
2904
2905
2906static struct saa7146_extension av7110_extension_driver = {
2907 .name = "av7110",
2908 .flags = SAA7146_USE_I2C_IRQ,
2909
2910 .module = THIS_MODULE,
2911 .pci_tbl = &pci_tbl[0],
2912 .attach = av7110_attach,
2913 .detach = __devexit_p(av7110_detach),
2914
2915 .irq_mask = MASK_19 | MASK_03 | MASK_10,
2916 .irq_func = av7110_irq,
2917};
2918
2919
2920static int __init av7110_init(void)
2921{
2922 int retval;
2923 retval = saa7146_register_extension(&av7110_extension_driver);
2924 return retval;
2925}
2926
2927
2928static void __exit av7110_exit(void)
2929{
2930 saa7146_unregister_extension(&av7110_extension_driver);
2931}
2932
2933module_init(av7110_init);
2934module_exit(av7110_exit);
2935
2936MODULE_DESCRIPTION("driver for the SAA7146 based AV110 PCI DVB cards by "
2937 "Siemens, Technotrend, Hauppauge");
2938MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
2939MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
deleted file mode 100644
index 88b3b2d6cc0e..000000000000
--- a/drivers/media/dvb/ttpci/av7110.h
+++ /dev/null
@@ -1,314 +0,0 @@
1#ifndef _AV7110_H_
2#define _AV7110_H_
3
4#include <linux/interrupt.h>
5#include <linux/socket.h>
6#include <linux/netdevice.h>
7#include <linux/i2c.h>
8#include <linux/input.h>
9
10#include <linux/dvb/video.h>
11#include <linux/dvb/audio.h>
12#include <linux/dvb/dmx.h>
13#include <linux/dvb/ca.h>
14#include <linux/dvb/osd.h>
15#include <linux/dvb/net.h>
16#include <linux/mutex.h>
17
18#include "dvbdev.h"
19#include "demux.h"
20#include "dvb_demux.h"
21#include "dmxdev.h"
22#include "dvb_filter.h"
23#include "dvb_net.h"
24#include "dvb_ringbuffer.h"
25#include "dvb_frontend.h"
26#include "ves1820.h"
27#include "ves1x93.h"
28#include "stv0299.h"
29#include "tda8083.h"
30#include "sp8870.h"
31#include "stv0297.h"
32#include "l64781.h"
33
34#include <media/saa7146_vv.h>
35
36
37#define ANALOG_TUNER_VES1820 1
38#define ANALOG_TUNER_STV0297 2
39
40extern int av7110_debug;
41
42#define dprintk(level,args...) \
43 do { if ((av7110_debug & level)) { printk("dvb-ttpci: %s(): ", __func__); printk(args); } } while (0)
44
45#define MAXFILT 32
46
47enum {AV_PES_STREAM, PS_STREAM, TS_STREAM, PES_STREAM};
48
49enum av7110_video_mode {
50 AV7110_VIDEO_MODE_PAL = 0,
51 AV7110_VIDEO_MODE_NTSC = 1
52};
53
54struct av7110_p2t {
55 u8 pes[TS_SIZE];
56 u8 counter;
57 long int pos;
58 int frags;
59 struct dvb_demux_feed *feed;
60};
61
62/* video MPEG decoder events: */
63/* (code copied from dvb_frontend.c, should maybe be factored out...) */
64#define MAX_VIDEO_EVENT 8
65struct dvb_video_events {
66 struct video_event events[MAX_VIDEO_EVENT];
67 int eventw;
68 int eventr;
69 int overflow;
70 wait_queue_head_t wait_queue;
71 spinlock_t lock;
72};
73
74
75struct av7110;
76
77/* infrared remote control */
78struct infrared {
79 u16 key_map[256];
80 struct input_dev *input_dev;
81 char input_phys[32];
82 struct timer_list keyup_timer;
83 struct tasklet_struct ir_tasklet;
84 void (*ir_handler)(struct av7110 *av7110, u32 ircom);
85 u32 ir_command;
86 u32 ir_config;
87 u32 device_mask;
88 u8 protocol;
89 u8 inversion;
90 u16 last_key;
91 u16 last_toggle;
92 u8 delay_timer_finished;
93};
94
95
96/* place to store all the necessary device information */
97struct av7110 {
98
99 /* devices */
100
101 struct dvb_device dvb_dev;
102 struct dvb_net dvb_net;
103
104 struct video_device *v4l_dev;
105 struct video_device *vbi_dev;
106
107 struct saa7146_dev *dev;
108
109 struct i2c_adapter i2c_adap;
110
111 char *card_name;
112
113 /* support for analog module of dvb-c */
114 int analog_tuner_flags;
115 int current_input;
116 u32 current_freq;
117
118 struct tasklet_struct debi_tasklet;
119 struct tasklet_struct gpio_tasklet;
120
121 int adac_type; /* audio DAC type */
122#define DVB_ADAC_TI 0
123#define DVB_ADAC_CRYSTAL 1
124#define DVB_ADAC_MSP34x0 2
125#define DVB_ADAC_MSP34x5 3
126#define DVB_ADAC_NONE -1
127
128
129 /* buffers */
130
131 void *iobuf; /* memory for all buffers */
132 struct dvb_ringbuffer avout; /* buffer for video or A/V mux */
133#define AVOUTLEN (128*1024)
134 struct dvb_ringbuffer aout; /* buffer for audio */
135#define AOUTLEN (64*1024)
136 void *bmpbuf;
137#define BMPLEN (8*32768+1024)
138
139 /* bitmap buffers and states */
140
141 int bmpp;
142 int bmplen;
143 volatile int bmp_state;
144#define BMP_NONE 0
145#define BMP_LOADING 1
146#define BMP_LOADED 2
147 wait_queue_head_t bmpq;
148
149
150 /* DEBI and polled command interface */
151
152 spinlock_t debilock;
153 struct mutex dcomlock;
154 volatile int debitype;
155 volatile int debilen;
156
157
158 /* Recording and playback flags */
159
160 int rec_mode;
161 int playing;
162#define RP_NONE 0
163#define RP_VIDEO 1
164#define RP_AUDIO 2
165#define RP_AV 3
166
167
168 /* OSD */
169
170 int osdwin; /* currently active window */
171 u16 osdbpp[8];
172 struct mutex osd_mutex;
173
174 /* CA */
175
176 ca_slot_info_t ci_slot[2];
177
178 enum av7110_video_mode vidmode;
179 struct dmxdev dmxdev;
180 struct dvb_demux demux;
181
182 struct dmx_frontend hw_frontend;
183 struct dmx_frontend mem_frontend;
184
185 /* for budget mode demux1 */
186 struct dmxdev dmxdev1;
187 struct dvb_demux demux1;
188 struct dvb_net dvb_net1;
189 spinlock_t feedlock1;
190 int feeding1;
191 u32 ttbp;
192 unsigned char *grabbing;
193 struct saa7146_pgtable pt;
194 struct tasklet_struct vpe_tasklet;
195 bool full_ts;
196
197 int fe_synced;
198 struct mutex pid_mutex;
199
200 int video_blank;
201 struct video_status videostate;
202 u16 display_panscan;
203 int display_ar;
204 int trickmode;
205#define TRICK_NONE 0
206#define TRICK_FAST 1
207#define TRICK_SLOW 2
208#define TRICK_FREEZE 3
209 struct audio_status audiostate;
210
211 struct dvb_demux_filter *handle2filter[32];
212 struct av7110_p2t p2t_filter[MAXFILT];
213 struct dvb_filter_pes2ts p2t[2];
214 struct ipack ipack[2];
215 u8 *kbuf[2];
216
217 int sinfo;
218 int feeding;
219
220 int arm_errors;
221 int registered;
222
223
224 /* AV711X */
225
226 u32 arm_fw;
227 u32 arm_rtsl;
228 u32 arm_vid;
229 u32 arm_app;
230 u32 avtype;
231 int arm_ready;
232 struct task_struct *arm_thread;
233 wait_queue_head_t arm_wait;
234 u16 arm_loops;
235
236 void *debi_virt;
237 dma_addr_t debi_bus;
238
239 u16 pids[DMX_PES_OTHER];
240
241 struct dvb_ringbuffer ci_rbuffer;
242 struct dvb_ringbuffer ci_wbuffer;
243
244 struct audio_mixer mixer;
245
246 struct dvb_adapter dvb_adapter;
247 struct dvb_device *video_dev;
248 struct dvb_device *audio_dev;
249 struct dvb_device *ca_dev;
250 struct dvb_device *osd_dev;
251
252 struct dvb_video_events video_events;
253 video_size_t video_size;
254
255 u16 wssMode;
256 u16 wssData;
257
258 struct infrared ir;
259
260 /* firmware stuff */
261 unsigned char *bin_fw;
262 unsigned long size_fw;
263
264 unsigned char *bin_dpram;
265 unsigned long size_dpram;
266
267 unsigned char *bin_root;
268 unsigned long size_root;
269
270 struct dvb_frontend* fe;
271 fe_status_t fe_status;
272
273 /* crash recovery */
274 void (*recover)(struct av7110* av7110);
275 fe_sec_voltage_t saved_voltage;
276 fe_sec_tone_mode_t saved_tone;
277 struct dvb_diseqc_master_cmd saved_master_cmd;
278 fe_sec_mini_cmd_t saved_minicmd;
279
280 int (*fe_init)(struct dvb_frontend* fe);
281 int (*fe_read_status)(struct dvb_frontend* fe, fe_status_t* status);
282 int (*fe_diseqc_reset_overload)(struct dvb_frontend* fe);
283 int (*fe_diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd);
284 int (*fe_diseqc_send_burst)(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd);
285 int (*fe_set_tone)(struct dvb_frontend* fe, fe_sec_tone_mode_t tone);
286 int (*fe_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
287 int (*fe_dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd);
288 int (*fe_set_frontend)(struct dvb_frontend *fe);
289};
290
291
292extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
293 u16 subpid, u16 pcrpid);
294
295extern int av7110_check_ir_config(struct av7110 *av7110, int force);
296extern int av7110_ir_init(struct av7110 *av7110);
297extern void av7110_ir_exit(struct av7110 *av7110);
298
299/* msp3400 i2c subaddresses */
300#define MSP_WR_DEM 0x10
301#define MSP_RD_DEM 0x11
302#define MSP_WR_DSP 0x12
303#define MSP_RD_DSP 0x13
304
305extern int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val);
306extern u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg);
307extern int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val);
308
309
310extern int av7110_init_analog_module(struct av7110 *av7110);
311extern int av7110_init_v4l(struct av7110 *av7110);
312extern int av7110_exit_v4l(struct av7110 *av7110);
313
314#endif /* _AV7110_H_ */
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
deleted file mode 100644
index 952b33dbac4f..000000000000
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ /dev/null
@@ -1,1626 +0,0 @@
1/*
2 * av7110_av.c: audio and video MPEG decoder stuff
3 *
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
6 *
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 *
27 *
28 * the project's page is at http://www.linuxtv.org/
29 */
30
31#include <linux/types.h>
32#include <linux/kernel.h>
33#include <linux/string.h>
34#include <linux/delay.h>
35#include <linux/fs.h>
36
37#include "av7110.h"
38#include "av7110_hw.h"
39#include "av7110_av.h"
40#include "av7110_ipack.h"
41
42/* MPEG-2 (ISO 13818 / H.222.0) stream types */
43#define PROG_STREAM_MAP 0xBC
44#define PRIVATE_STREAM1 0xBD
45#define PADDING_STREAM 0xBE
46#define PRIVATE_STREAM2 0xBF
47#define AUDIO_STREAM_S 0xC0
48#define AUDIO_STREAM_E 0xDF
49#define VIDEO_STREAM_S 0xE0
50#define VIDEO_STREAM_E 0xEF
51#define ECM_STREAM 0xF0
52#define EMM_STREAM 0xF1
53#define DSM_CC_STREAM 0xF2
54#define ISO13522_STREAM 0xF3
55#define PROG_STREAM_DIR 0xFF
56
57#define PTS_DTS_FLAGS 0xC0
58
59//pts_dts flags
60#define PTS_ONLY 0x80
61#define PTS_DTS 0xC0
62#define TS_SIZE 188
63#define TRANS_ERROR 0x80
64#define PAY_START 0x40
65#define TRANS_PRIO 0x20
66#define PID_MASK_HI 0x1F
67//flags
68#define TRANS_SCRMBL1 0x80
69#define TRANS_SCRMBL2 0x40
70#define ADAPT_FIELD 0x20
71#define PAYLOAD 0x10
72#define COUNT_MASK 0x0F
73
74// adaptation flags
75#define DISCON_IND 0x80
76#define RAND_ACC_IND 0x40
77#define ES_PRI_IND 0x20
78#define PCR_FLAG 0x10
79#define OPCR_FLAG 0x08
80#define SPLICE_FLAG 0x04
81#define TRANS_PRIV 0x02
82#define ADAP_EXT_FLAG 0x01
83
84// adaptation extension flags
85#define LTW_FLAG 0x80
86#define PIECE_RATE 0x40
87#define SEAM_SPLICE 0x20
88
89
90static void p_to_t(u8 const *buf, long int length, u16 pid,
91 u8 *counter, struct dvb_demux_feed *feed);
92static int write_ts_to_decoder(struct av7110 *av7110, int type, const u8 *buf, size_t len);
93
94
95int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len)
96{
97 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) p2t->priv;
98
99 if (!(dvbdmxfeed->ts_type & TS_PACKET))
100 return 0;
101 if (buf[3] == 0xe0) // video PES do not have a length in TS
102 buf[4] = buf[5] = 0;
103 if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
104 return dvbdmxfeed->cb.ts(buf, len, NULL, 0,
105 &dvbdmxfeed->feed.ts, DMX_OK);
106 else
107 return dvb_filter_pes2ts(p2t, buf, len, 1);
108}
109
110static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
111{
112 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv;
113
114 dvbdmxfeed->cb.ts(data, 188, NULL, 0,
115 &dvbdmxfeed->feed.ts, DMX_OK);
116 return 0;
117}
118
119int av7110_av_start_record(struct av7110 *av7110, int av,
120 struct dvb_demux_feed *dvbdmxfeed)
121{
122 int ret = 0;
123 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
124
125 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed);
126
127 if (av7110->playing || (av7110->rec_mode & av))
128 return -EBUSY;
129 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
130 dvbdmx->recording = 1;
131 av7110->rec_mode |= av;
132
133 switch (av7110->rec_mode) {
134 case RP_AUDIO:
135 dvb_filter_pes2ts_init(&av7110->p2t[0],
136 dvbdmx->pesfilter[0]->pid,
137 dvb_filter_pes2ts_cb,
138 (void *) dvbdmx->pesfilter[0]);
139 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
140 break;
141
142 case RP_VIDEO:
143 dvb_filter_pes2ts_init(&av7110->p2t[1],
144 dvbdmx->pesfilter[1]->pid,
145 dvb_filter_pes2ts_cb,
146 (void *) dvbdmx->pesfilter[1]);
147 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
148 break;
149
150 case RP_AV:
151 dvb_filter_pes2ts_init(&av7110->p2t[0],
152 dvbdmx->pesfilter[0]->pid,
153 dvb_filter_pes2ts_cb,
154 (void *) dvbdmx->pesfilter[0]);
155 dvb_filter_pes2ts_init(&av7110->p2t[1],
156 dvbdmx->pesfilter[1]->pid,
157 dvb_filter_pes2ts_cb,
158 (void *) dvbdmx->pesfilter[1]);
159 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0);
160 break;
161 }
162 return ret;
163}
164
165int av7110_av_start_play(struct av7110 *av7110, int av)
166{
167 int ret = 0;
168 dprintk(2, "av7110:%p, \n", av7110);
169
170 if (av7110->rec_mode)
171 return -EBUSY;
172 if (av7110->playing & av)
173 return -EBUSY;
174
175 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
176
177 if (av7110->playing == RP_NONE) {
178 av7110_ipack_reset(&av7110->ipack[0]);
179 av7110_ipack_reset(&av7110->ipack[1]);
180 }
181
182 av7110->playing |= av;
183 switch (av7110->playing) {
184 case RP_AUDIO:
185 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
186 break;
187 case RP_VIDEO:
188 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
189 av7110->sinfo = 0;
190 break;
191 case RP_AV:
192 av7110->sinfo = 0;
193 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0);
194 break;
195 }
196 return ret;
197}
198
199int av7110_av_stop(struct av7110 *av7110, int av)
200{
201 int ret = 0;
202 dprintk(2, "av7110:%p, \n", av7110);
203
204 if (!(av7110->playing & av) && !(av7110->rec_mode & av))
205 return 0;
206 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
207 if (av7110->playing) {
208 av7110->playing &= ~av;
209 switch (av7110->playing) {
210 case RP_AUDIO:
211 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
212 break;
213 case RP_VIDEO:
214 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
215 break;
216 case RP_NONE:
217 ret = av7110_set_vidmode(av7110, av7110->vidmode);
218 break;
219 }
220 } else {
221 av7110->rec_mode &= ~av;
222 switch (av7110->rec_mode) {
223 case RP_AUDIO:
224 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
225 break;
226 case RP_VIDEO:
227 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
228 break;
229 case RP_NONE:
230 break;
231 }
232 }
233 return ret;
234}
235
236
237int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
238{
239 int len;
240 u32 sync;
241 u16 blen;
242
243 if (!dlen) {
244 wake_up(&buf->queue);
245 return -1;
246 }
247 while (1) {
248 len = dvb_ringbuffer_avail(buf);
249 if (len < 6) {
250 wake_up(&buf->queue);
251 return -1;
252 }
253 sync = DVB_RINGBUFFER_PEEK(buf, 0) << 24;
254 sync |= DVB_RINGBUFFER_PEEK(buf, 1) << 16;
255 sync |= DVB_RINGBUFFER_PEEK(buf, 2) << 8;
256 sync |= DVB_RINGBUFFER_PEEK(buf, 3);
257
258 if (((sync &~ 0x0f) == 0x000001e0) ||
259 ((sync &~ 0x1f) == 0x000001c0) ||
260 (sync == 0x000001bd))
261 break;
262 printk("resync\n");
263 DVB_RINGBUFFER_SKIP(buf, 1);
264 }
265 blen = DVB_RINGBUFFER_PEEK(buf, 4) << 8;
266 blen |= DVB_RINGBUFFER_PEEK(buf, 5);
267 blen += 6;
268 if (len < blen || blen > dlen) {
269 //printk("buffer empty - avail %d blen %u dlen %d\n", len, blen, dlen);
270 wake_up(&buf->queue);
271 return -1;
272 }
273
274 dvb_ringbuffer_read(buf, dest, (size_t) blen);
275
276 dprintk(2, "pread=0x%08lx, pwrite=0x%08lx\n",
277 (unsigned long) buf->pread, (unsigned long) buf->pwrite);
278 wake_up(&buf->queue);
279 return blen;
280}
281
282
283int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
284{
285 int err, vol, val, balance = 0;
286
287 dprintk(2, "av7110:%p, \n", av7110);
288
289 av7110->mixer.volume_left = volleft;
290 av7110->mixer.volume_right = volright;
291
292 switch (av7110->adac_type) {
293 case DVB_ADAC_TI:
294 volleft = (volleft * 256) / 1036;
295 volright = (volright * 256) / 1036;
296 if (volleft > 0x3f)
297 volleft = 0x3f;
298 if (volright > 0x3f)
299 volright = 0x3f;
300 if ((err = SendDAC(av7110, 3, 0x80 + volleft)))
301 return err;
302 return SendDAC(av7110, 4, volright);
303
304 case DVB_ADAC_CRYSTAL:
305 volleft = 127 - volleft / 2;
306 volright = 127 - volright / 2;
307 i2c_writereg(av7110, 0x20, 0x03, volleft);
308 i2c_writereg(av7110, 0x20, 0x04, volright);
309 return 0;
310
311 case DVB_ADAC_MSP34x0:
312 vol = (volleft > volright) ? volleft : volright;
313 val = (vol * 0x73 / 255) << 8;
314 if (vol > 0)
315 balance = ((volright - volleft) * 127) / vol;
316 msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
317 msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
318 msp_writereg(av7110, MSP_WR_DSP, 0x0006, val); /* headphonesr */
319 return 0;
320
321 case DVB_ADAC_MSP34x5:
322 vol = (volleft > volright) ? volleft : volright;
323 val = (vol * 0x73 / 255) << 8;
324 if (vol > 0)
325 balance = ((volright - volleft) * 127) / vol;
326 msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
327 msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
328 return 0;
329 }
330
331 return 0;
332}
333
334int av7110_set_vidmode(struct av7110 *av7110, enum av7110_video_mode mode)
335{
336 int ret;
337 dprintk(2, "av7110:%p, \n", av7110);
338
339 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode);
340
341 if (!ret && !av7110->playing) {
342 ret = ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO],
343 av7110->pids[DMX_PES_AUDIO],
344 av7110->pids[DMX_PES_TELETEXT],
345 0, av7110->pids[DMX_PES_PCR]);
346 if (!ret)
347 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
348 }
349 return ret;
350}
351
352
353static enum av7110_video_mode sw2mode[16] = {
354 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
355 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_PAL,
356 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_NTSC,
357 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
358 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
359 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
360 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
361 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
362};
363
364static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
365{
366 int i;
367 int hsize, vsize;
368 int sw;
369 u8 *p;
370 int ret = 0;
371
372 dprintk(2, "av7110:%p, \n", av7110);
373
374 if (av7110->sinfo)
375 return 0;
376 for (i = 7; i < count - 10; i++) {
377 p = buf + i;
378 if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3)
379 continue;
380 p += 4;
381 hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4);
382 vsize = ((p[1] &0x0F) << 8) | (p[2]);
383 sw = (p[3] & 0x0F);
384 ret = av7110_set_vidmode(av7110, sw2mode[sw]);
385 if (!ret) {
386 dprintk(2, "playback %dx%d fr=%d\n", hsize, vsize, sw);
387 av7110->sinfo = 1;
388 }
389 break;
390 }
391 return ret;
392}
393
394
395/****************************************************************************
396 * I/O buffer management and control
397 ****************************************************************************/
398
399static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
400 const u8 *buf, unsigned long count)
401{
402 unsigned long todo = count;
403 int free;
404
405 while (todo > 0) {
406 if (dvb_ringbuffer_free(rbuf) < 2048) {
407 if (wait_event_interruptible(rbuf->queue,
408 (dvb_ringbuffer_free(rbuf) >= 2048)))
409 return count - todo;
410 }
411 free = dvb_ringbuffer_free(rbuf);
412 if (free > todo)
413 free = todo;
414 dvb_ringbuffer_write(rbuf, buf, free);
415 todo -= free;
416 buf += free;
417 }
418
419 return count - todo;
420}
421
422static void play_video_cb(u8 *buf, int count, void *priv)
423{
424 struct av7110 *av7110 = (struct av7110 *) priv;
425 dprintk(2, "av7110:%p, \n", av7110);
426
427 if ((buf[3] & 0xe0) == 0xe0) {
428 get_video_format(av7110, buf, count);
429 aux_ring_buffer_write(&av7110->avout, buf, count);
430 } else
431 aux_ring_buffer_write(&av7110->aout, buf, count);
432}
433
434static void play_audio_cb(u8 *buf, int count, void *priv)
435{
436 struct av7110 *av7110 = (struct av7110 *) priv;
437 dprintk(2, "av7110:%p, \n", av7110);
438
439 aux_ring_buffer_write(&av7110->aout, buf, count);
440}
441
442
443#define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096)
444
445static ssize_t ts_play(struct av7110 *av7110, const char __user *buf,
446 unsigned long count, int nonblock, int type)
447{
448 struct dvb_ringbuffer *rb;
449 u8 *kb;
450 unsigned long todo = count;
451
452 dprintk(2, "%s: type %d cnt %lu\n", __func__, type, count);
453
454 rb = (type) ? &av7110->avout : &av7110->aout;
455 kb = av7110->kbuf[type];
456
457 if (!kb)
458 return -ENOBUFS;
459
460 if (nonblock && !FREE_COND_TS)
461 return -EWOULDBLOCK;
462
463 while (todo >= TS_SIZE) {
464 if (!FREE_COND_TS) {
465 if (nonblock)
466 return count - todo;
467 if (wait_event_interruptible(rb->queue, FREE_COND_TS))
468 return count - todo;
469 }
470 if (copy_from_user(kb, buf, TS_SIZE))
471 return -EFAULT;
472 write_ts_to_decoder(av7110, type, kb, TS_SIZE);
473 todo -= TS_SIZE;
474 buf += TS_SIZE;
475 }
476
477 return count - todo;
478}
479
480
481#define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
482 dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
483
484static ssize_t dvb_play(struct av7110 *av7110, const char __user *buf,
485 unsigned long count, int nonblock, int type)
486{
487 unsigned long todo = count, n;
488 dprintk(2, "av7110:%p, \n", av7110);
489
490 if (!av7110->kbuf[type])
491 return -ENOBUFS;
492
493 if (nonblock && !FREE_COND)
494 return -EWOULDBLOCK;
495
496 while (todo > 0) {
497 if (!FREE_COND) {
498 if (nonblock)
499 return count - todo;
500 if (wait_event_interruptible(av7110->avout.queue,
501 FREE_COND))
502 return count - todo;
503 }
504 n = todo;
505 if (n > IPACKS * 2)
506 n = IPACKS * 2;
507 if (copy_from_user(av7110->kbuf[type], buf, n))
508 return -EFAULT;
509 av7110_ipack_instant_repack(av7110->kbuf[type], n,
510 &av7110->ipack[type]);
511 todo -= n;
512 buf += n;
513 }
514 return count - todo;
515}
516
517static ssize_t dvb_play_kernel(struct av7110 *av7110, const u8 *buf,
518 unsigned long count, int nonblock, int type)
519{
520 unsigned long todo = count, n;
521 dprintk(2, "av7110:%p, \n", av7110);
522
523 if (!av7110->kbuf[type])
524 return -ENOBUFS;
525
526 if (nonblock && !FREE_COND)
527 return -EWOULDBLOCK;
528
529 while (todo > 0) {
530 if (!FREE_COND) {
531 if (nonblock)
532 return count - todo;
533 if (wait_event_interruptible(av7110->avout.queue,
534 FREE_COND))
535 return count - todo;
536 }
537 n = todo;
538 if (n > IPACKS * 2)
539 n = IPACKS * 2;
540 av7110_ipack_instant_repack(buf, n, &av7110->ipack[type]);
541 todo -= n;
542 buf += n;
543 }
544 return count - todo;
545}
546
547static ssize_t dvb_aplay(struct av7110 *av7110, const char __user *buf,
548 unsigned long count, int nonblock, int type)
549{
550 unsigned long todo = count, n;
551 dprintk(2, "av7110:%p, \n", av7110);
552
553 if (!av7110->kbuf[type])
554 return -ENOBUFS;
555 if (nonblock && dvb_ringbuffer_free(&av7110->aout) < 20 * 1024)
556 return -EWOULDBLOCK;
557
558 while (todo > 0) {
559 if (dvb_ringbuffer_free(&av7110->aout) < 20 * 1024) {
560 if (nonblock)
561 return count - todo;
562 if (wait_event_interruptible(av7110->aout.queue,
563 (dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)))
564 return count-todo;
565 }
566 n = todo;
567 if (n > IPACKS * 2)
568 n = IPACKS * 2;
569 if (copy_from_user(av7110->kbuf[type], buf, n))
570 return -EFAULT;
571 av7110_ipack_instant_repack(av7110->kbuf[type], n,
572 &av7110->ipack[type]);
573 todo -= n;
574 buf += n;
575 }
576 return count - todo;
577}
578
579void av7110_p2t_init(struct av7110_p2t *p, struct dvb_demux_feed *feed)
580{
581 memset(p->pes, 0, TS_SIZE);
582 p->counter = 0;
583 p->pos = 0;
584 p->frags = 0;
585 if (feed)
586 p->feed = feed;
587}
588
589static void clear_p2t(struct av7110_p2t *p)
590{
591 memset(p->pes, 0, TS_SIZE);
592// p->counter = 0;
593 p->pos = 0;
594 p->frags = 0;
595}
596
597
598static int find_pes_header(u8 const *buf, long int length, int *frags)
599{
600 int c = 0;
601 int found = 0;
602
603 *frags = 0;
604
605 while (c < length - 3 && !found) {
606 if (buf[c] == 0x00 && buf[c + 1] == 0x00 &&
607 buf[c + 2] == 0x01) {
608 switch ( buf[c + 3] ) {
609 case PROG_STREAM_MAP:
610 case PRIVATE_STREAM2:
611 case PROG_STREAM_DIR:
612 case ECM_STREAM :
613 case EMM_STREAM :
614 case PADDING_STREAM :
615 case DSM_CC_STREAM :
616 case ISO13522_STREAM:
617 case PRIVATE_STREAM1:
618 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
619 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
620 found = 1;
621 break;
622
623 default:
624 c++;
625 break;
626 }
627 } else
628 c++;
629 }
630 if (c == length - 3 && !found) {
631 if (buf[length - 1] == 0x00)
632 *frags = 1;
633 if (buf[length - 2] == 0x00 &&
634 buf[length - 1] == 0x00)
635 *frags = 2;
636 if (buf[length - 3] == 0x00 &&
637 buf[length - 2] == 0x00 &&
638 buf[length - 1] == 0x01)
639 *frags = 3;
640 return -1;
641 }
642
643 return c;
644}
645
646void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t *p)
647{
648 int c, c2, l, add;
649 int check, rest;
650
651 c = 0;
652 c2 = 0;
653 if (p->frags){
654 check = 0;
655 switch(p->frags) {
656 case 1:
657 if (buf[c] == 0x00 && buf[c + 1] == 0x01) {
658 check = 1;
659 c += 2;
660 }
661 break;
662 case 2:
663 if (buf[c] == 0x01) {
664 check = 1;
665 c++;
666 }
667 break;
668 case 3:
669 check = 1;
670 }
671 if (check) {
672 switch (buf[c]) {
673 case PROG_STREAM_MAP:
674 case PRIVATE_STREAM2:
675 case PROG_STREAM_DIR:
676 case ECM_STREAM :
677 case EMM_STREAM :
678 case PADDING_STREAM :
679 case DSM_CC_STREAM :
680 case ISO13522_STREAM:
681 case PRIVATE_STREAM1:
682 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
683 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
684 p->pes[0] = 0x00;
685 p->pes[1] = 0x00;
686 p->pes[2] = 0x01;
687 p->pes[3] = buf[c];
688 p->pos = 4;
689 memcpy(p->pes + p->pos, buf + c, (TS_SIZE - 4) - p->pos);
690 c += (TS_SIZE - 4) - p->pos;
691 p_to_t(p->pes, (TS_SIZE - 4), pid, &p->counter, p->feed);
692 clear_p2t(p);
693 break;
694
695 default:
696 c = 0;
697 break;
698 }
699 }
700 p->frags = 0;
701 }
702
703 if (p->pos) {
704 c2 = find_pes_header(buf + c, length - c, &p->frags);
705 if (c2 >= 0 && c2 < (TS_SIZE - 4) - p->pos)
706 l = c2+c;
707 else
708 l = (TS_SIZE - 4) - p->pos;
709 memcpy(p->pes + p->pos, buf, l);
710 c += l;
711 p->pos += l;
712 p_to_t(p->pes, p->pos, pid, &p->counter, p->feed);
713 clear_p2t(p);
714 }
715
716 add = 0;
717 while (c < length) {
718 c2 = find_pes_header(buf + c + add, length - c - add, &p->frags);
719 if (c2 >= 0) {
720 c2 += c + add;
721 if (c2 > c){
722 p_to_t(buf + c, c2 - c, pid, &p->counter, p->feed);
723 c = c2;
724 clear_p2t(p);
725 add = 0;
726 } else
727 add = 1;
728 } else {
729 l = length - c;
730 rest = l % (TS_SIZE - 4);
731 l -= rest;
732 p_to_t(buf + c, l, pid, &p->counter, p->feed);
733 memcpy(p->pes, buf + c + l, rest);
734 p->pos = rest;
735 c = length;
736 }
737 }
738}
739
740
741static int write_ts_header2(u16 pid, u8 *counter, int pes_start, u8 *buf, u8 length)
742{
743 int i;
744 int c = 0;
745 int fill;
746 u8 tshead[4] = { 0x47, 0x00, 0x00, 0x10 };
747
748 fill = (TS_SIZE - 4) - length;
749 if (pes_start)
750 tshead[1] = 0x40;
751 if (fill)
752 tshead[3] = 0x30;
753 tshead[1] |= (u8)((pid & 0x1F00) >> 8);
754 tshead[2] |= (u8)(pid & 0x00FF);
755 tshead[3] |= ((*counter)++ & 0x0F);
756 memcpy(buf, tshead, 4);
757 c += 4;
758
759 if (fill) {
760 buf[4] = fill - 1;
761 c++;
762 if (fill > 1) {
763 buf[5] = 0x00;
764 c++;
765 }
766 for (i = 6; i < fill + 4; i++) {
767 buf[i] = 0xFF;
768 c++;
769 }
770 }
771
772 return c;
773}
774
775
776static void p_to_t(u8 const *buf, long int length, u16 pid, u8 *counter,
777 struct dvb_demux_feed *feed)
778{
779 int l, pes_start;
780 u8 obuf[TS_SIZE];
781 long c = 0;
782
783 pes_start = 0;
784 if (length > 3 &&
785 buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x01)
786 switch (buf[3]) {
787 case PROG_STREAM_MAP:
788 case PRIVATE_STREAM2:
789 case PROG_STREAM_DIR:
790 case ECM_STREAM :
791 case EMM_STREAM :
792 case PADDING_STREAM :
793 case DSM_CC_STREAM :
794 case ISO13522_STREAM:
795 case PRIVATE_STREAM1:
796 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
797 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
798 pes_start = 1;
799 break;
800
801 default:
802 break;
803 }
804
805 while (c < length) {
806 memset(obuf, 0, TS_SIZE);
807 if (length - c >= (TS_SIZE - 4)){
808 l = write_ts_header2(pid, counter, pes_start,
809 obuf, (TS_SIZE - 4));
810 memcpy(obuf + l, buf + c, TS_SIZE - l);
811 c += TS_SIZE - l;
812 } else {
813 l = write_ts_header2(pid, counter, pes_start,
814 obuf, length - c);
815 memcpy(obuf + l, buf + c, TS_SIZE - l);
816 c = length;
817 }
818 feed->cb.ts(obuf, 188, NULL, 0, &feed->feed.ts, DMX_OK);
819 pes_start = 0;
820 }
821}
822
823
824static int write_ts_to_decoder(struct av7110 *av7110, int type, const u8 *buf, size_t len)
825{
826 struct ipack *ipack = &av7110->ipack[type];
827
828 if (buf[1] & TRANS_ERROR) {
829 av7110_ipack_reset(ipack);
830 return -1;
831 }
832
833 if (!(buf[3] & PAYLOAD))
834 return -1;
835
836 if (buf[1] & PAY_START)
837 av7110_ipack_flush(ipack);
838
839 if (buf[3] & ADAPT_FIELD) {
840 len -= buf[4] + 1;
841 buf += buf[4] + 1;
842 if (!len)
843 return 0;
844 }
845
846 av7110_ipack_instant_repack(buf + 4, len - 4, ipack);
847 return 0;
848}
849
850
851int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len)
852{
853 struct dvb_demux *demux = feed->demux;
854 struct av7110 *av7110 = (struct av7110 *) demux->priv;
855
856 dprintk(2, "av7110:%p, \n", av7110);
857
858 if (av7110->full_ts && demux->dmx.frontend->source != DMX_MEMORY_FE)
859 return 0;
860
861 switch (feed->pes_type) {
862 case 0:
863 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
864 return -EINVAL;
865 break;
866 case 1:
867 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
868 return -EINVAL;
869 break;
870 default:
871 return -1;
872 }
873
874 return write_ts_to_decoder(av7110, feed->pes_type, buf, len);
875}
876
877
878
879/******************************************************************************
880 * Video MPEG decoder events
881 ******************************************************************************/
882void dvb_video_add_event(struct av7110 *av7110, struct video_event *event)
883{
884 struct dvb_video_events *events = &av7110->video_events;
885 int wp;
886
887 spin_lock_bh(&events->lock);
888
889 wp = (events->eventw + 1) % MAX_VIDEO_EVENT;
890 if (wp == events->eventr) {
891 events->overflow = 1;
892 events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
893 }
894
895 //FIXME: timestamp?
896 memcpy(&events->events[events->eventw], event, sizeof(struct video_event));
897 events->eventw = wp;
898
899 spin_unlock_bh(&events->lock);
900
901 wake_up_interruptible(&events->wait_queue);
902}
903
904
905static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event, int flags)
906{
907 struct dvb_video_events *events = &av7110->video_events;
908
909 if (events->overflow) {
910 events->overflow = 0;
911 return -EOVERFLOW;
912 }
913 if (events->eventw == events->eventr) {
914 int ret;
915
916 if (flags & O_NONBLOCK)
917 return -EWOULDBLOCK;
918
919 ret = wait_event_interruptible(events->wait_queue,
920 events->eventw != events->eventr);
921 if (ret < 0)
922 return ret;
923 }
924
925 spin_lock_bh(&events->lock);
926
927 memcpy(event, &events->events[events->eventr],
928 sizeof(struct video_event));
929 events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
930
931 spin_unlock_bh(&events->lock);
932
933 return 0;
934}
935
936
937/******************************************************************************
938 * DVB device file operations
939 ******************************************************************************/
940
941static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
942{
943 struct dvb_device *dvbdev = file->private_data;
944 struct av7110 *av7110 = dvbdev->priv;
945 unsigned int mask = 0;
946
947 dprintk(2, "av7110:%p, \n", av7110);
948
949 if ((file->f_flags & O_ACCMODE) != O_RDONLY)
950 poll_wait(file, &av7110->avout.queue, wait);
951
952 poll_wait(file, &av7110->video_events.wait_queue, wait);
953
954 if (av7110->video_events.eventw != av7110->video_events.eventr)
955 mask = POLLPRI;
956
957 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
958 if (av7110->playing) {
959 if (FREE_COND)
960 mask |= (POLLOUT | POLLWRNORM);
961 } else /* if not playing: may play if asked for */
962 mask |= (POLLOUT | POLLWRNORM);
963 }
964
965 return mask;
966}
967
968static ssize_t dvb_video_write(struct file *file, const char __user *buf,
969 size_t count, loff_t *ppos)
970{
971 struct dvb_device *dvbdev = file->private_data;
972 struct av7110 *av7110 = dvbdev->priv;
973 unsigned char c;
974
975 dprintk(2, "av7110:%p, \n", av7110);
976
977 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
978 return -EPERM;
979
980 if (av7110->videostate.stream_source != VIDEO_SOURCE_MEMORY)
981 return -EPERM;
982
983 if (get_user(c, buf))
984 return -EFAULT;
985 if (c == 0x47 && count % TS_SIZE == 0)
986 return ts_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1);
987 else
988 return dvb_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1);
989}
990
991static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
992{
993 struct dvb_device *dvbdev = file->private_data;
994 struct av7110 *av7110 = dvbdev->priv;
995 unsigned int mask = 0;
996
997 dprintk(2, "av7110:%p, \n", av7110);
998
999 poll_wait(file, &av7110->aout.queue, wait);
1000
1001 if (av7110->playing) {
1002 if (dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
1003 mask |= (POLLOUT | POLLWRNORM);
1004 } else /* if not playing: may play if asked for */
1005 mask = (POLLOUT | POLLWRNORM);
1006
1007 return mask;
1008}
1009
1010static ssize_t dvb_audio_write(struct file *file, const char __user *buf,
1011 size_t count, loff_t *ppos)
1012{
1013 struct dvb_device *dvbdev = file->private_data;
1014 struct av7110 *av7110 = dvbdev->priv;
1015 unsigned char c;
1016
1017 dprintk(2, "av7110:%p, \n", av7110);
1018
1019 if (av7110->audiostate.stream_source != AUDIO_SOURCE_MEMORY) {
1020 printk(KERN_ERR "not audio source memory\n");
1021 return -EPERM;
1022 }
1023
1024 if (get_user(c, buf))
1025 return -EFAULT;
1026 if (c == 0x47 && count % TS_SIZE == 0)
1027 return ts_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
1028 else
1029 return dvb_aplay(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
1030}
1031
1032static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1033
1034#define MIN_IFRAME 400000
1035
1036static int play_iframe(struct av7110 *av7110, char __user *buf, unsigned int len, int nonblock)
1037{
1038 unsigned i, n;
1039 int progressive = 0;
1040 int match = 0;
1041
1042 dprintk(2, "av7110:%p, \n", av7110);
1043
1044 if (!(av7110->playing & RP_VIDEO)) {
1045 if (av7110_av_start_play(av7110, RP_VIDEO) < 0)
1046 return -EBUSY;
1047 }
1048
1049 /* search in buf for instances of 00 00 01 b5 1? */
1050 for (i = 0; i < len; i++) {
1051 unsigned char c;
1052 if (get_user(c, buf + i))
1053 return -EFAULT;
1054 if (match == 5) {
1055 progressive = c & 0x08;
1056 match = 0;
1057 }
1058 if (c == 0x00) {
1059 match = (match == 1 || match == 2) ? 2 : 1;
1060 continue;
1061 }
1062 switch (match++) {
1063 case 2: if (c == 0x01)
1064 continue;
1065 break;
1066 case 3: if (c == 0xb5)
1067 continue;
1068 break;
1069 case 4: if ((c & 0xf0) == 0x10)
1070 continue;
1071 break;
1072 }
1073 match = 0;
1074 }
1075
1076 /* setting n always > 1, fixes problems when playing stillframes
1077 consisting of I- and P-Frames */
1078 n = MIN_IFRAME / len + 1;
1079
1080 /* FIXME: nonblock? */
1081 dvb_play_kernel(av7110, iframe_header, sizeof(iframe_header), 0, 1);
1082
1083 for (i = 0; i < n; i++)
1084 dvb_play(av7110, buf, len, 0, 1);
1085
1086 av7110_ipack_flush(&av7110->ipack[1]);
1087
1088 if (progressive)
1089 return vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
1090 else
1091 return 0;
1092}
1093
1094
1095static int dvb_video_ioctl(struct file *file,
1096 unsigned int cmd, void *parg)
1097{
1098 struct dvb_device *dvbdev = file->private_data;
1099 struct av7110 *av7110 = dvbdev->priv;
1100 unsigned long arg = (unsigned long) parg;
1101 int ret = 0;
1102
1103 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
1104
1105 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
1106 if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT &&
1107 cmd != VIDEO_GET_SIZE ) {
1108 return -EPERM;
1109 }
1110 }
1111
1112 switch (cmd) {
1113 case VIDEO_STOP:
1114 av7110->videostate.play_state = VIDEO_STOPPED;
1115 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
1116 ret = av7110_av_stop(av7110, RP_VIDEO);
1117 else
1118 ret = vidcom(av7110, AV_VIDEO_CMD_STOP,
1119 av7110->videostate.video_blank ? 0 : 1);
1120 if (!ret)
1121 av7110->trickmode = TRICK_NONE;
1122 break;
1123
1124 case VIDEO_PLAY:
1125 av7110->trickmode = TRICK_NONE;
1126 if (av7110->videostate.play_state == VIDEO_FREEZED) {
1127 av7110->videostate.play_state = VIDEO_PLAYING;
1128 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
1129 if (ret)
1130 break;
1131 }
1132 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) {
1133 if (av7110->playing == RP_AV) {
1134 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
1135 if (ret)
1136 break;
1137 av7110->playing &= ~RP_VIDEO;
1138 }
1139 ret = av7110_av_start_play(av7110, RP_VIDEO);
1140 }
1141 if (!ret)
1142 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
1143 if (!ret)
1144 av7110->videostate.play_state = VIDEO_PLAYING;
1145 break;
1146
1147 case VIDEO_FREEZE:
1148 av7110->videostate.play_state = VIDEO_FREEZED;
1149 if (av7110->playing & RP_VIDEO)
1150 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0);
1151 else
1152 ret = vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
1153 if (!ret)
1154 av7110->trickmode = TRICK_FREEZE;
1155 break;
1156
1157 case VIDEO_CONTINUE:
1158 if (av7110->playing & RP_VIDEO)
1159 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0);
1160 if (!ret)
1161 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
1162 if (!ret) {
1163 av7110->videostate.play_state = VIDEO_PLAYING;
1164 av7110->trickmode = TRICK_NONE;
1165 }
1166 break;
1167
1168 case VIDEO_SELECT_SOURCE:
1169 av7110->videostate.stream_source = (video_stream_source_t) arg;
1170 break;
1171
1172 case VIDEO_SET_BLANK:
1173 av7110->videostate.video_blank = (int) arg;
1174 break;
1175
1176 case VIDEO_GET_STATUS:
1177 memcpy(parg, &av7110->videostate, sizeof(struct video_status));
1178 break;
1179
1180 case VIDEO_GET_EVENT:
1181 ret = dvb_video_get_event(av7110, parg, file->f_flags);
1182 break;
1183
1184 case VIDEO_GET_SIZE:
1185 memcpy(parg, &av7110->video_size, sizeof(video_size_t));
1186 break;
1187
1188 case VIDEO_SET_DISPLAY_FORMAT:
1189 {
1190 video_displayformat_t format = (video_displayformat_t) arg;
1191 switch (format) {
1192 case VIDEO_PAN_SCAN:
1193 av7110->display_panscan = VID_PAN_SCAN_PREF;
1194 break;
1195 case VIDEO_LETTER_BOX:
1196 av7110->display_panscan = VID_VC_AND_PS_PREF;
1197 break;
1198 case VIDEO_CENTER_CUT_OUT:
1199 av7110->display_panscan = VID_CENTRE_CUT_PREF;
1200 break;
1201 default:
1202 ret = -EINVAL;
1203 }
1204 if (ret < 0)
1205 break;
1206 av7110->videostate.display_format = format;
1207 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
1208 1, av7110->display_panscan);
1209 break;
1210 }
1211
1212 case VIDEO_SET_FORMAT:
1213 if (arg > 1) {
1214 ret = -EINVAL;
1215 break;
1216 }
1217 av7110->display_ar = arg;
1218 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetMonitorType,
1219 1, (u16) arg);
1220 break;
1221
1222 case VIDEO_STILLPICTURE:
1223 {
1224 struct video_still_picture *pic =
1225 (struct video_still_picture *) parg;
1226 av7110->videostate.stream_source = VIDEO_SOURCE_MEMORY;
1227 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1228 ret = play_iframe(av7110, pic->iFrame, pic->size,
1229 file->f_flags & O_NONBLOCK);
1230 break;
1231 }
1232
1233 case VIDEO_FAST_FORWARD:
1234 //note: arg is ignored by firmware
1235 if (av7110->playing & RP_VIDEO)
1236 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1237 __Scan_I, 2, AV_PES, 0);
1238 else
1239 ret = vidcom(av7110, AV_VIDEO_CMD_FFWD, arg);
1240 if (!ret) {
1241 av7110->trickmode = TRICK_FAST;
1242 av7110->videostate.play_state = VIDEO_PLAYING;
1243 }
1244 break;
1245
1246 case VIDEO_SLOWMOTION:
1247 if (av7110->playing&RP_VIDEO) {
1248 if (av7110->trickmode != TRICK_SLOW)
1249 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0);
1250 if (!ret)
1251 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
1252 } else {
1253 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
1254 if (!ret)
1255 ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 0);
1256 if (!ret)
1257 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
1258 }
1259 if (!ret) {
1260 av7110->trickmode = TRICK_SLOW;
1261 av7110->videostate.play_state = VIDEO_PLAYING;
1262 }
1263 break;
1264
1265 case VIDEO_GET_CAPABILITIES:
1266 *(int *)parg = VIDEO_CAP_MPEG1 | VIDEO_CAP_MPEG2 |
1267 VIDEO_CAP_SYS | VIDEO_CAP_PROG;
1268 break;
1269
1270 case VIDEO_CLEAR_BUFFER:
1271 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1272 av7110_ipack_reset(&av7110->ipack[1]);
1273 if (av7110->playing == RP_AV) {
1274 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1275 __Play, 2, AV_PES, 0);
1276 if (ret)
1277 break;
1278 if (av7110->trickmode == TRICK_FAST)
1279 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1280 __Scan_I, 2, AV_PES, 0);
1281 if (av7110->trickmode == TRICK_SLOW) {
1282 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1283 __Slow, 2, 0, 0);
1284 if (!ret)
1285 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
1286 }
1287 if (av7110->trickmode == TRICK_FREEZE)
1288 ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 1);
1289 }
1290 break;
1291
1292 case VIDEO_SET_STREAMTYPE:
1293 break;
1294
1295 default:
1296 ret = -ENOIOCTLCMD;
1297 break;
1298 }
1299
1300 return ret;
1301}
1302
1303static int dvb_audio_ioctl(struct file *file,
1304 unsigned int cmd, void *parg)
1305{
1306 struct dvb_device *dvbdev = file->private_data;
1307 struct av7110 *av7110 = dvbdev->priv;
1308 unsigned long arg = (unsigned long) parg;
1309 int ret = 0;
1310
1311 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
1312
1313 if (((file->f_flags & O_ACCMODE) == O_RDONLY) &&
1314 (cmd != AUDIO_GET_STATUS))
1315 return -EPERM;
1316
1317 switch (cmd) {
1318 case AUDIO_STOP:
1319 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
1320 ret = av7110_av_stop(av7110, RP_AUDIO);
1321 else
1322 ret = audcom(av7110, AUDIO_CMD_MUTE);
1323 if (!ret)
1324 av7110->audiostate.play_state = AUDIO_STOPPED;
1325 break;
1326
1327 case AUDIO_PLAY:
1328 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
1329 ret = av7110_av_start_play(av7110, RP_AUDIO);
1330 if (!ret)
1331 ret = audcom(av7110, AUDIO_CMD_UNMUTE);
1332 if (!ret)
1333 av7110->audiostate.play_state = AUDIO_PLAYING;
1334 break;
1335
1336 case AUDIO_PAUSE:
1337 ret = audcom(av7110, AUDIO_CMD_MUTE);
1338 if (!ret)
1339 av7110->audiostate.play_state = AUDIO_PAUSED;
1340 break;
1341
1342 case AUDIO_CONTINUE:
1343 if (av7110->audiostate.play_state == AUDIO_PAUSED) {
1344 av7110->audiostate.play_state = AUDIO_PLAYING;
1345 ret = audcom(av7110, AUDIO_CMD_UNMUTE | AUDIO_CMD_PCM16);
1346 }
1347 break;
1348
1349 case AUDIO_SELECT_SOURCE:
1350 av7110->audiostate.stream_source = (audio_stream_source_t) arg;
1351 break;
1352
1353 case AUDIO_SET_MUTE:
1354 {
1355 ret = audcom(av7110, arg ? AUDIO_CMD_MUTE : AUDIO_CMD_UNMUTE);
1356 if (!ret)
1357 av7110->audiostate.mute_state = (int) arg;
1358 break;
1359 }
1360
1361 case AUDIO_SET_AV_SYNC:
1362 av7110->audiostate.AV_sync_state = (int) arg;
1363 ret = audcom(av7110, arg ? AUDIO_CMD_SYNC_ON : AUDIO_CMD_SYNC_OFF);
1364 break;
1365
1366 case AUDIO_SET_BYPASS_MODE:
1367 if (FW_VERSION(av7110->arm_app) < 0x2621)
1368 ret = -EINVAL;
1369 av7110->audiostate.bypass_mode = (int)arg;
1370 break;
1371
1372 case AUDIO_CHANNEL_SELECT:
1373 av7110->audiostate.channel_select = (audio_channel_select_t) arg;
1374 switch(av7110->audiostate.channel_select) {
1375 case AUDIO_STEREO:
1376 ret = audcom(av7110, AUDIO_CMD_STEREO);
1377 if (!ret) {
1378 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1379 i2c_writereg(av7110, 0x20, 0x02, 0x49);
1380 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1381 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220);
1382 }
1383 break;
1384 case AUDIO_MONO_LEFT:
1385 ret = audcom(av7110, AUDIO_CMD_MONO_L);
1386 if (!ret) {
1387 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1388 i2c_writereg(av7110, 0x20, 0x02, 0x4a);
1389 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1390 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0200);
1391 }
1392 break;
1393 case AUDIO_MONO_RIGHT:
1394 ret = audcom(av7110, AUDIO_CMD_MONO_R);
1395 if (!ret) {
1396 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1397 i2c_writereg(av7110, 0x20, 0x02, 0x45);
1398 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1399 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0210);
1400 }
1401 break;
1402 default:
1403 ret = -EINVAL;
1404 break;
1405 }
1406 break;
1407
1408 case AUDIO_GET_STATUS:
1409 memcpy(parg, &av7110->audiostate, sizeof(struct audio_status));
1410 break;
1411
1412 case AUDIO_GET_CAPABILITIES:
1413 if (FW_VERSION(av7110->arm_app) < 0x2621)
1414 *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
1415 else
1416 *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_DTS | AUDIO_CAP_AC3 |
1417 AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
1418 break;
1419
1420 case AUDIO_CLEAR_BUFFER:
1421 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1422 av7110_ipack_reset(&av7110->ipack[0]);
1423 if (av7110->playing == RP_AV)
1424 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
1425 __Play, 2, AV_PES, 0);
1426 break;
1427
1428 case AUDIO_SET_ID:
1429 break;
1430
1431 case AUDIO_SET_MIXER:
1432 {
1433 struct audio_mixer *amix = (struct audio_mixer *)parg;
1434 ret = av7110_set_volume(av7110, amix->volume_left, amix->volume_right);
1435 break;
1436 }
1437
1438 case AUDIO_SET_STREAMTYPE:
1439 break;
1440
1441 default:
1442 ret = -ENOIOCTLCMD;
1443 }
1444
1445 return ret;
1446}
1447
1448
1449static int dvb_video_open(struct inode *inode, struct file *file)
1450{
1451 struct dvb_device *dvbdev = file->private_data;
1452 struct av7110 *av7110 = dvbdev->priv;
1453 int err;
1454
1455 dprintk(2, "av7110:%p, \n", av7110);
1456
1457 if ((err = dvb_generic_open(inode, file)) < 0)
1458 return err;
1459
1460 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1461 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1462 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1463 av7110->video_blank = 1;
1464 av7110->audiostate.AV_sync_state = 1;
1465 av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
1466
1467 /* empty event queue */
1468 av7110->video_events.eventr = av7110->video_events.eventw = 0;
1469 }
1470
1471 return 0;
1472}
1473
1474static int dvb_video_release(struct inode *inode, struct file *file)
1475{
1476 struct dvb_device *dvbdev = file->private_data;
1477 struct av7110 *av7110 = dvbdev->priv;
1478
1479 dprintk(2, "av7110:%p, \n", av7110);
1480
1481 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1482 av7110_av_stop(av7110, RP_VIDEO);
1483 }
1484
1485 return dvb_generic_release(inode, file);
1486}
1487
1488static int dvb_audio_open(struct inode *inode, struct file *file)
1489{
1490 struct dvb_device *dvbdev = file->private_data;
1491 struct av7110 *av7110 = dvbdev->priv;
1492 int err = dvb_generic_open(inode, file);
1493
1494 dprintk(2, "av7110:%p, \n", av7110);
1495
1496 if (err < 0)
1497 return err;
1498 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1499 av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
1500 return 0;
1501}
1502
1503static int dvb_audio_release(struct inode *inode, struct file *file)
1504{
1505 struct dvb_device *dvbdev = file->private_data;
1506 struct av7110 *av7110 = dvbdev->priv;
1507
1508 dprintk(2, "av7110:%p, \n", av7110);
1509
1510 av7110_av_stop(av7110, RP_AUDIO);
1511 return dvb_generic_release(inode, file);
1512}
1513
1514
1515
1516/******************************************************************************
1517 * driver registration
1518 ******************************************************************************/
1519
1520static const struct file_operations dvb_video_fops = {
1521 .owner = THIS_MODULE,
1522 .write = dvb_video_write,
1523 .unlocked_ioctl = dvb_generic_ioctl,
1524 .open = dvb_video_open,
1525 .release = dvb_video_release,
1526 .poll = dvb_video_poll,
1527 .llseek = noop_llseek,
1528};
1529
1530static struct dvb_device dvbdev_video = {
1531 .priv = NULL,
1532 .users = 6,
1533 .readers = 5, /* arbitrary */
1534 .writers = 1,
1535 .fops = &dvb_video_fops,
1536 .kernel_ioctl = dvb_video_ioctl,
1537};
1538
1539static const struct file_operations dvb_audio_fops = {
1540 .owner = THIS_MODULE,
1541 .write = dvb_audio_write,
1542 .unlocked_ioctl = dvb_generic_ioctl,
1543 .open = dvb_audio_open,
1544 .release = dvb_audio_release,
1545 .poll = dvb_audio_poll,
1546 .llseek = noop_llseek,
1547};
1548
1549static struct dvb_device dvbdev_audio = {
1550 .priv = NULL,
1551 .users = 1,
1552 .writers = 1,
1553 .fops = &dvb_audio_fops,
1554 .kernel_ioctl = dvb_audio_ioctl,
1555};
1556
1557
1558int av7110_av_register(struct av7110 *av7110)
1559{
1560 av7110->audiostate.AV_sync_state = 0;
1561 av7110->audiostate.mute_state = 0;
1562 av7110->audiostate.play_state = AUDIO_STOPPED;
1563 av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
1564 av7110->audiostate.channel_select = AUDIO_STEREO;
1565 av7110->audiostate.bypass_mode = 0;
1566
1567 av7110->videostate.video_blank = 0;
1568 av7110->videostate.play_state = VIDEO_STOPPED;
1569 av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
1570 av7110->videostate.video_format = VIDEO_FORMAT_4_3;
1571 av7110->videostate.display_format = VIDEO_LETTER_BOX;
1572 av7110->display_ar = VIDEO_FORMAT_4_3;
1573 av7110->display_panscan = VID_VC_AND_PS_PREF;
1574
1575 init_waitqueue_head(&av7110->video_events.wait_queue);
1576 spin_lock_init(&av7110->video_events.lock);
1577 av7110->video_events.eventw = av7110->video_events.eventr = 0;
1578 av7110->video_events.overflow = 0;
1579 memset(&av7110->video_size, 0, sizeof (video_size_t));
1580
1581 dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
1582 &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
1583
1584 dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
1585 &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
1586
1587 return 0;
1588}
1589
1590void av7110_av_unregister(struct av7110 *av7110)
1591{
1592 dvb_unregister_device(av7110->audio_dev);
1593 dvb_unregister_device(av7110->video_dev);
1594}
1595
1596int av7110_av_init(struct av7110 *av7110)
1597{
1598 void (*play[])(u8 *, int, void *) = { play_audio_cb, play_video_cb };
1599 int i, ret;
1600
1601 for (i = 0; i < 2; i++) {
1602 struct ipack *ipack = av7110->ipack + i;
1603
1604 ret = av7110_ipack_init(ipack, IPACKS, play[i]);
1605 if (ret < 0) {
1606 if (i)
1607 av7110_ipack_free(--ipack);
1608 goto out;
1609 }
1610 ipack->data = av7110;
1611 }
1612
1613 dvb_ringbuffer_init(&av7110->avout, av7110->iobuf, AVOUTLEN);
1614 dvb_ringbuffer_init(&av7110->aout, av7110->iobuf + AVOUTLEN, AOUTLEN);
1615
1616 av7110->kbuf[0] = (u8 *)(av7110->iobuf + AVOUTLEN + AOUTLEN + BMPLEN);
1617 av7110->kbuf[1] = av7110->kbuf[0] + 2 * IPACKS;
1618out:
1619 return ret;
1620}
1621
1622void av7110_av_exit(struct av7110 *av7110)
1623{
1624 av7110_ipack_free(&av7110->ipack[0]);
1625 av7110_ipack_free(&av7110->ipack[1]);
1626}
diff --git a/drivers/media/dvb/ttpci/av7110_av.h b/drivers/media/dvb/ttpci/av7110_av.h
deleted file mode 100644
index 5f02ef85e47d..000000000000
--- a/drivers/media/dvb/ttpci/av7110_av.h
+++ /dev/null
@@ -1,30 +0,0 @@
1#ifndef _AV7110_AV_H_
2#define _AV7110_AV_H_
3
4struct av7110;
5
6extern int av7110_set_vidmode(struct av7110 *av7110,
7 enum av7110_video_mode mode);
8
9extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len);
10extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen);
11extern int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len);
12
13extern int av7110_set_volume(struct av7110 *av7110, int volleft, int volright);
14extern int av7110_av_stop(struct av7110 *av7110, int av);
15extern int av7110_av_start_record(struct av7110 *av7110, int av,
16 struct dvb_demux_feed *dvbdmxfeed);
17extern int av7110_av_start_play(struct av7110 *av7110, int av);
18
19extern void dvb_video_add_event(struct av7110 *av7110, struct video_event *event);
20
21extern void av7110_p2t_init(struct av7110_p2t *p, struct dvb_demux_feed *feed);
22extern void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t *p);
23
24extern int av7110_av_register(struct av7110 *av7110);
25extern void av7110_av_unregister(struct av7110 *av7110);
26extern int av7110_av_init(struct av7110 *av7110);
27extern void av7110_av_exit(struct av7110 *av7110);
28
29
30#endif /* _AV7110_AV_H_ */
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
deleted file mode 100644
index 9fc1dd0ba4c3..000000000000
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ /dev/null
@@ -1,387 +0,0 @@
1/*
2 * av7110_ca.c: CA and CI stuff
3 *
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
6 *
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 *
27 *
28 * the project's page is at http://www.linuxtv.org/
29 */
30
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/delay.h>
34#include <linux/fs.h>
35#include <linux/timer.h>
36#include <linux/poll.h>
37#include <linux/gfp.h>
38
39#include "av7110.h"
40#include "av7110_hw.h"
41#include "av7110_ca.h"
42
43
44void CI_handle(struct av7110 *av7110, u8 *data, u16 len)
45{
46 dprintk(8, "av7110:%p\n",av7110);
47
48 if (len < 3)
49 return;
50 switch (data[0]) {
51 case CI_MSG_CI_INFO:
52 if (data[2] != 1 && data[2] != 2)
53 break;
54 switch (data[1]) {
55 case 0:
56 av7110->ci_slot[data[2] - 1].flags = 0;
57 break;
58 case 1:
59 av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_PRESENT;
60 break;
61 case 2:
62 av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_READY;
63 break;
64 }
65 break;
66 case CI_SWITCH_PRG_REPLY:
67 //av7110->ci_stat=data[1];
68 break;
69 default:
70 break;
71 }
72}
73
74
75void ci_get_data(struct dvb_ringbuffer *cibuf, u8 *data, int len)
76{
77 if (dvb_ringbuffer_free(cibuf) < len + 2)
78 return;
79
80 DVB_RINGBUFFER_WRITE_BYTE(cibuf, len >> 8);
81 DVB_RINGBUFFER_WRITE_BYTE(cibuf, len & 0xff);
82 dvb_ringbuffer_write(cibuf, data, len);
83 wake_up_interruptible(&cibuf->queue);
84}
85
86
87/******************************************************************************
88 * CI link layer file ops
89 ******************************************************************************/
90
91static int ci_ll_init(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf, int size)
92{
93 struct dvb_ringbuffer *tab[] = { cirbuf, ciwbuf, NULL }, **p;
94 void *data;
95
96 for (p = tab; *p; p++) {
97 data = vmalloc(size);
98 if (!data) {
99 while (p-- != tab) {
100 vfree(p[0]->data);
101 p[0]->data = NULL;
102 }
103 return -ENOMEM;
104 }
105 dvb_ringbuffer_init(*p, data, size);
106 }
107 return 0;
108}
109
110static void ci_ll_flush(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf)
111{
112 dvb_ringbuffer_flush_spinlock_wakeup(cirbuf);
113 dvb_ringbuffer_flush_spinlock_wakeup(ciwbuf);
114}
115
116static void ci_ll_release(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf)
117{
118 vfree(cirbuf->data);
119 cirbuf->data = NULL;
120 vfree(ciwbuf->data);
121 ciwbuf->data = NULL;
122}
123
124static int ci_ll_reset(struct dvb_ringbuffer *cibuf, struct file *file,
125 int slots, ca_slot_info_t *slot)
126{
127 int i;
128 int len = 0;
129 u8 msg[8] = { 0x00, 0x06, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00 };
130
131 for (i = 0; i < 2; i++) {
132 if (slots & (1 << i))
133 len += 8;
134 }
135
136 if (dvb_ringbuffer_free(cibuf) < len)
137 return -EBUSY;
138
139 for (i = 0; i < 2; i++) {
140 if (slots & (1 << i)) {
141 msg[2] = i;
142 dvb_ringbuffer_write(cibuf, msg, 8);
143 slot[i].flags = 0;
144 }
145 }
146
147 return 0;
148}
149
150static ssize_t ci_ll_write(struct dvb_ringbuffer *cibuf, struct file *file,
151 const char __user *buf, size_t count, loff_t *ppos)
152{
153 int free;
154 int non_blocking = file->f_flags & O_NONBLOCK;
155 u8 *page = (u8 *)__get_free_page(GFP_USER);
156 int res;
157
158 if (!page)
159 return -ENOMEM;
160
161 res = -EINVAL;
162 if (count > 2048)
163 goto out;
164
165 res = -EFAULT;
166 if (copy_from_user(page, buf, count))
167 goto out;
168
169 free = dvb_ringbuffer_free(cibuf);
170 if (count + 2 > free) {
171 res = -EWOULDBLOCK;
172 if (non_blocking)
173 goto out;
174 res = -ERESTARTSYS;
175 if (wait_event_interruptible(cibuf->queue,
176 (dvb_ringbuffer_free(cibuf) >= count + 2)))
177 goto out;
178 }
179
180 DVB_RINGBUFFER_WRITE_BYTE(cibuf, count >> 8);
181 DVB_RINGBUFFER_WRITE_BYTE(cibuf, count & 0xff);
182
183 res = dvb_ringbuffer_write(cibuf, page, count);
184out:
185 free_page((unsigned long)page);
186 return res;
187}
188
189static ssize_t ci_ll_read(struct dvb_ringbuffer *cibuf, struct file *file,
190 char __user *buf, size_t count, loff_t *ppos)
191{
192 int avail;
193 int non_blocking = file->f_flags & O_NONBLOCK;
194 ssize_t len;
195
196 if (!cibuf->data || !count)
197 return 0;
198 if (non_blocking && (dvb_ringbuffer_empty(cibuf)))
199 return -EWOULDBLOCK;
200 if (wait_event_interruptible(cibuf->queue,
201 !dvb_ringbuffer_empty(cibuf)))
202 return -ERESTARTSYS;
203 avail = dvb_ringbuffer_avail(cibuf);
204 if (avail < 4)
205 return 0;
206 len = DVB_RINGBUFFER_PEEK(cibuf, 0) << 8;
207 len |= DVB_RINGBUFFER_PEEK(cibuf, 1);
208 if (avail < len + 2 || count < len)
209 return -EINVAL;
210 DVB_RINGBUFFER_SKIP(cibuf, 2);
211
212 return dvb_ringbuffer_read_user(cibuf, buf, len);
213}
214
215static int dvb_ca_open(struct inode *inode, struct file *file)
216{
217 struct dvb_device *dvbdev = file->private_data;
218 struct av7110 *av7110 = dvbdev->priv;
219 int err = dvb_generic_open(inode, file);
220
221 dprintk(8, "av7110:%p\n",av7110);
222
223 if (err < 0)
224 return err;
225 ci_ll_flush(&av7110->ci_rbuffer, &av7110->ci_wbuffer);
226 return 0;
227}
228
229static unsigned int dvb_ca_poll (struct file *file, poll_table *wait)
230{
231 struct dvb_device *dvbdev = file->private_data;
232 struct av7110 *av7110 = dvbdev->priv;
233 struct dvb_ringbuffer *rbuf = &av7110->ci_rbuffer;
234 struct dvb_ringbuffer *wbuf = &av7110->ci_wbuffer;
235 unsigned int mask = 0;
236
237 dprintk(8, "av7110:%p\n",av7110);
238
239 poll_wait(file, &rbuf->queue, wait);
240 poll_wait(file, &wbuf->queue, wait);
241
242 if (!dvb_ringbuffer_empty(rbuf))
243 mask |= (POLLIN | POLLRDNORM);
244
245 if (dvb_ringbuffer_free(wbuf) > 1024)
246 mask |= (POLLOUT | POLLWRNORM);
247
248 return mask;
249}
250
251static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
252{
253 struct dvb_device *dvbdev = file->private_data;
254 struct av7110 *av7110 = dvbdev->priv;
255 unsigned long arg = (unsigned long) parg;
256
257 dprintk(8, "av7110:%p\n",av7110);
258
259 switch (cmd) {
260 case CA_RESET:
261 return ci_ll_reset(&av7110->ci_wbuffer, file, arg, &av7110->ci_slot[0]);
262 break;
263 case CA_GET_CAP:
264 {
265 ca_caps_t cap;
266
267 cap.slot_num = 2;
268 cap.slot_type = (FW_CI_LL_SUPPORT(av7110->arm_app) ?
269 CA_CI_LINK : CA_CI) | CA_DESCR;
270 cap.descr_num = 16;
271 cap.descr_type = CA_ECD;
272 memcpy(parg, &cap, sizeof(cap));
273 break;
274 }
275
276 case CA_GET_SLOT_INFO:
277 {
278 ca_slot_info_t *info=(ca_slot_info_t *)parg;
279
280 if (info->num < 0 || info->num > 1)
281 return -EINVAL;
282 av7110->ci_slot[info->num].num = info->num;
283 av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
284 CA_CI_LINK : CA_CI;
285 memcpy(info, &av7110->ci_slot[info->num], sizeof(ca_slot_info_t));
286 break;
287 }
288
289 case CA_GET_MSG:
290 break;
291
292 case CA_SEND_MSG:
293 break;
294
295 case CA_GET_DESCR_INFO:
296 {
297 ca_descr_info_t info;
298
299 info.num = 16;
300 info.type = CA_ECD;
301 memcpy(parg, &info, sizeof (info));
302 break;
303 }
304
305 case CA_SET_DESCR:
306 {
307 ca_descr_t *descr = (ca_descr_t*) parg;
308
309 if (descr->index >= 16)
310 return -EINVAL;
311 if (descr->parity > 1)
312 return -EINVAL;
313 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetDescr, 5,
314 (descr->index<<8)|descr->parity,
315 (descr->cw[0]<<8)|descr->cw[1],
316 (descr->cw[2]<<8)|descr->cw[3],
317 (descr->cw[4]<<8)|descr->cw[5],
318 (descr->cw[6]<<8)|descr->cw[7]);
319 break;
320 }
321
322 default:
323 return -EINVAL;
324 }
325 return 0;
326}
327
328static ssize_t dvb_ca_write(struct file *file, const char __user *buf,
329 size_t count, loff_t *ppos)
330{
331 struct dvb_device *dvbdev = file->private_data;
332 struct av7110 *av7110 = dvbdev->priv;
333
334 dprintk(8, "av7110:%p\n",av7110);
335 return ci_ll_write(&av7110->ci_wbuffer, file, buf, count, ppos);
336}
337
338static ssize_t dvb_ca_read(struct file *file, char __user *buf,
339 size_t count, loff_t *ppos)
340{
341 struct dvb_device *dvbdev = file->private_data;
342 struct av7110 *av7110 = dvbdev->priv;
343
344 dprintk(8, "av7110:%p\n",av7110);
345 return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos);
346}
347
348static const struct file_operations dvb_ca_fops = {
349 .owner = THIS_MODULE,
350 .read = dvb_ca_read,
351 .write = dvb_ca_write,
352 .unlocked_ioctl = dvb_generic_ioctl,
353 .open = dvb_ca_open,
354 .release = dvb_generic_release,
355 .poll = dvb_ca_poll,
356 .llseek = default_llseek,
357};
358
359static struct dvb_device dvbdev_ca = {
360 .priv = NULL,
361 .users = 1,
362 .writers = 1,
363 .fops = &dvb_ca_fops,
364 .kernel_ioctl = dvb_ca_ioctl,
365};
366
367
368int av7110_ca_register(struct av7110 *av7110)
369{
370 return dvb_register_device(&av7110->dvb_adapter, &av7110->ca_dev,
371 &dvbdev_ca, av7110, DVB_DEVICE_CA);
372}
373
374void av7110_ca_unregister(struct av7110 *av7110)
375{
376 dvb_unregister_device(av7110->ca_dev);
377}
378
379int av7110_ca_init(struct av7110* av7110)
380{
381 return ci_ll_init(&av7110->ci_rbuffer, &av7110->ci_wbuffer, 8192);
382}
383
384void av7110_ca_exit(struct av7110* av7110)
385{
386 ci_ll_release(&av7110->ci_rbuffer, &av7110->ci_wbuffer);
387}
diff --git a/drivers/media/dvb/ttpci/av7110_ca.h b/drivers/media/dvb/ttpci/av7110_ca.h
deleted file mode 100644
index 70ee855ece1b..000000000000
--- a/drivers/media/dvb/ttpci/av7110_ca.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef _AV7110_CA_H_
2#define _AV7110_CA_H_
3
4struct av7110;
5
6extern void CI_handle(struct av7110 *av7110, u8 *data, u16 len);
7extern void ci_get_data(struct dvb_ringbuffer *cibuf, u8 *data, int len);
8
9extern int av7110_ca_register(struct av7110 *av7110);
10extern void av7110_ca_unregister(struct av7110 *av7110);
11extern int av7110_ca_init(struct av7110* av7110);
12extern void av7110_ca_exit(struct av7110* av7110);
13
14#endif /* _AV7110_CA_H_ */
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
deleted file mode 100644
index f1cbfe526989..000000000000
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ /dev/null
@@ -1,1208 +0,0 @@
1/*
2 * av7110_hw.c: av7110 low level hardware access and firmware interface
3 *
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
6 *
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 *
25 * the project's page is at http://www.linuxtv.org/
26 */
27
28/* for debugging ARM communication: */
29//#define COM_DEBUG
30
31#include <stdarg.h>
32#include <linux/types.h>
33#include <linux/kernel.h>
34#include <linux/string.h>
35#include <linux/delay.h>
36#include <linux/fs.h>
37
38#include "av7110.h"
39#include "av7110_hw.h"
40
41#define _NOHANDSHAKE
42
43/****************************************************************************
44 * DEBI functions
45 ****************************************************************************/
46
47/* This DEBI code is based on the Stradis driver
48 by Nathan Laredo <laredo@gnu.org> */
49
50int av7110_debiwrite(struct av7110 *av7110, u32 config,
51 int addr, u32 val, int count)
52{
53 struct saa7146_dev *dev = av7110->dev;
54
55 if (count <= 0 || count > 32764) {
56 printk("%s: invalid count %d\n", __func__, count);
57 return -1;
58 }
59 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
60 printk("%s: wait_for_debi_done failed\n", __func__);
61 return -1;
62 }
63 saa7146_write(dev, DEBI_CONFIG, config);
64 if (count <= 4) /* immediate transfer */
65 saa7146_write(dev, DEBI_AD, val);
66 else /* block transfer */
67 saa7146_write(dev, DEBI_AD, av7110->debi_bus);
68 saa7146_write(dev, DEBI_COMMAND, (count << 17) | (addr & 0xffff));
69 saa7146_write(dev, MC2, (2 << 16) | 2);
70 return 0;
71}
72
73u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
74{
75 struct saa7146_dev *dev = av7110->dev;
76 u32 result = 0;
77
78 if (count > 32764 || count <= 0) {
79 printk("%s: invalid count %d\n", __func__, count);
80 return 0;
81 }
82 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
83 printk("%s: wait_for_debi_done #1 failed\n", __func__);
84 return 0;
85 }
86 saa7146_write(dev, DEBI_AD, av7110->debi_bus);
87 saa7146_write(dev, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
88
89 saa7146_write(dev, DEBI_CONFIG, config);
90 saa7146_write(dev, MC2, (2 << 16) | 2);
91 if (count > 4)
92 return count;
93 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
94 printk("%s: wait_for_debi_done #2 failed\n", __func__);
95 return 0;
96 }
97
98 result = saa7146_read(dev, DEBI_AD);
99 result &= (0xffffffffUL >> ((4 - count) * 8));
100 return result;
101}
102
103
104
105/* av7110 ARM core boot stuff */
106#if 0
107void av7110_reset_arm(struct av7110 *av7110)
108{
109 saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTLO);
110
111 /* Disable DEBI and GPIO irq */
112 SAA7146_IER_DISABLE(av7110->dev, MASK_19 | MASK_03);
113 SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
114
115 saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTHI);
116 msleep(30); /* the firmware needs some time to initialize */
117
118 ARM_ResetMailBox(av7110);
119
120 SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
121 SAA7146_IER_ENABLE(av7110->dev, MASK_03);
122
123 av7110->arm_ready = 1;
124 dprintk(1, "reset ARM\n");
125}
126#endif /* 0 */
127
128static int waitdebi(struct av7110 *av7110, int adr, int state)
129{
130 int k;
131
132 dprintk(4, "%p\n", av7110);
133
134 for (k = 0; k < 100; k++) {
135 if (irdebi(av7110, DEBINOSWAP, adr, 0, 2) == state)
136 return 0;
137 udelay(5);
138 }
139 return -ETIMEDOUT;
140}
141
142static int load_dram(struct av7110 *av7110, u32 *data, int len)
143{
144 int i;
145 int blocks, rest;
146 u32 base, bootblock = AV7110_BOOT_BLOCK;
147
148 dprintk(4, "%p\n", av7110);
149
150 blocks = len / AV7110_BOOT_MAX_SIZE;
151 rest = len % AV7110_BOOT_MAX_SIZE;
152 base = DRAM_START_CODE;
153
154 for (i = 0; i < blocks; i++) {
155 if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
156 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at block %d\n", i);
157 return -ETIMEDOUT;
158 }
159 dprintk(4, "writing DRAM block %d\n", i);
160 mwdebi(av7110, DEBISWAB, bootblock,
161 ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE, AV7110_BOOT_MAX_SIZE);
162 bootblock ^= 0x1400;
163 iwdebi(av7110, DEBISWAB, AV7110_BOOT_BASE, swab32(base), 4);
164 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, AV7110_BOOT_MAX_SIZE, 2);
165 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
166 base += AV7110_BOOT_MAX_SIZE;
167 }
168
169 if (rest > 0) {
170 if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
171 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at last block\n");
172 return -ETIMEDOUT;
173 }
174 if (rest > 4)
175 mwdebi(av7110, DEBISWAB, bootblock,
176 ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE, rest);
177 else
178 mwdebi(av7110, DEBISWAB, bootblock,
179 ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE - 4, rest + 4);
180
181 iwdebi(av7110, DEBISWAB, AV7110_BOOT_BASE, swab32(base), 4);
182 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, rest, 2);
183 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
184 }
185 if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
186 printk(KERN_ERR "dvb-ttpci: load_dram(): timeout after last block\n");
187 return -ETIMEDOUT;
188 }
189 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, 0, 2);
190 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
191 if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_AV7110_BOOT_COMPLETE) < 0) {
192 printk(KERN_ERR "dvb-ttpci: load_dram(): final handshake timeout\n");
193 return -ETIMEDOUT;
194 }
195 return 0;
196}
197
198
199/* we cannot write av7110 DRAM directly, so load a bootloader into
200 * the DPRAM which implements a simple boot protocol */
201int av7110_bootarm(struct av7110 *av7110)
202{
203 const struct firmware *fw;
204 const char *fw_name = "av7110/bootcode.bin";
205 struct saa7146_dev *dev = av7110->dev;
206 u32 ret;
207 int i;
208
209 dprintk(4, "%p\n", av7110);
210
211 av7110->arm_ready = 0;
212
213 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
214
215 /* Disable DEBI and GPIO irq */
216 SAA7146_IER_DISABLE(av7110->dev, MASK_03 | MASK_19);
217 SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
218
219 /* enable DEBI */
220 saa7146_write(av7110->dev, MC1, 0x08800880);
221 saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
222 saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
223
224 /* test DEBI */
225 iwdebi(av7110, DEBISWAP, DPRAM_BASE, 0x76543210, 4);
226 /* FIXME: Why does Nexus CA require 2x iwdebi for first init? */
227 iwdebi(av7110, DEBISWAP, DPRAM_BASE, 0x76543210, 4);
228
229 if ((ret=irdebi(av7110, DEBINOSWAP, DPRAM_BASE, 0, 4)) != 0x10325476) {
230 printk(KERN_ERR "dvb-ttpci: debi test in av7110_bootarm() failed: "
231 "%08x != %08x (check your BIOS 'Plug&Play OS' settings)\n",
232 ret, 0x10325476);
233 return -1;
234 }
235 for (i = 0; i < 8192; i += 4)
236 iwdebi(av7110, DEBISWAP, DPRAM_BASE + i, 0x00, 4);
237 dprintk(2, "debi test OK\n");
238
239 /* boot */
240 dprintk(1, "load boot code\n");
241 saa7146_setgpio(dev, ARM_IRQ_LINE, SAA7146_GPIO_IRQLO);
242 //saa7146_setgpio(dev, DEBI_DONE_LINE, SAA7146_GPIO_INPUT);
243 //saa7146_setgpio(dev, 3, SAA7146_GPIO_INPUT);
244
245 ret = request_firmware(&fw, fw_name, &dev->pci->dev);
246 if (ret) {
247 printk(KERN_ERR "dvb-ttpci: Failed to load firmware \"%s\"\n",
248 fw_name);
249 return ret;
250 }
251
252 mwdebi(av7110, DEBISWAB, DPRAM_BASE, fw->data, fw->size);
253 release_firmware(fw);
254 iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
255
256 if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
257 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
258 "saa7146_wait_for_debi_done() timed out\n");
259 return -ETIMEDOUT;
260 }
261 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
262 mdelay(1);
263
264 dprintk(1, "load dram code\n");
265 if (load_dram(av7110, (u32 *)av7110->bin_root, av7110->size_root) < 0) {
266 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
267 "load_dram() failed\n");
268 return -1;
269 }
270
271 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
272 mdelay(1);
273
274 dprintk(1, "load dpram code\n");
275 mwdebi(av7110, DEBISWAB, DPRAM_BASE, av7110->bin_dpram, av7110->size_dpram);
276
277 if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
278 printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
279 "saa7146_wait_for_debi_done() timed out after loading DRAM\n");
280 return -ETIMEDOUT;
281 }
282 saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
283 msleep(30); /* the firmware needs some time to initialize */
284
285 //ARM_ClearIrq(av7110);
286 ARM_ResetMailBox(av7110);
287 SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
288 SAA7146_IER_ENABLE(av7110->dev, MASK_03);
289
290 av7110->arm_errors = 0;
291 av7110->arm_ready = 1;
292 return 0;
293}
294MODULE_FIRMWARE("av7110/bootcode.bin");
295
296/****************************************************************************
297 * DEBI command polling
298 ****************************************************************************/
299
300int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
301{
302 unsigned long start;
303 u32 stat;
304 int err;
305
306 if (FW_VERSION(av7110->arm_app) <= 0x261c) {
307 /* not supported by old firmware */
308 msleep(50);
309 return 0;
310 }
311
312 /* new firmware */
313 start = jiffies;
314 for (;;) {
315 err = time_after(jiffies, start + ARM_WAIT_FREE);
316 if (mutex_lock_interruptible(&av7110->dcomlock))
317 return -ERESTARTSYS;
318 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
319 mutex_unlock(&av7110->dcomlock);
320 if ((stat & flags) == 0)
321 break;
322 if (err) {
323 printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n",
324 __func__, stat & flags);
325 return -ETIMEDOUT;
326 }
327 msleep(1);
328 }
329 return 0;
330}
331
332static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
333{
334 int i;
335 unsigned long start;
336 char *type = NULL;
337 u16 flags[2] = {0, 0};
338 u32 stat;
339 int err;
340
341// dprintk(4, "%p\n", av7110);
342
343 if (!av7110->arm_ready) {
344 dprintk(1, "arm not ready.\n");
345 return -ENXIO;
346 }
347
348 start = jiffies;
349 while (1) {
350 err = time_after(jiffies, start + ARM_WAIT_FREE);
351 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
352 break;
353 if (err) {
354 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __func__);
355 av7110->arm_errors++;
356 return -ETIMEDOUT;
357 }
358 msleep(1);
359 }
360
361 if (FW_VERSION(av7110->arm_app) <= 0x261f)
362 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2);
363
364#ifndef _NOHANDSHAKE
365 start = jiffies;
366 while (1) {
367 err = time_after(jiffies, start + ARM_WAIT_SHAKE);
368 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
369 break;
370 if (err) {
371 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __func__);
372 return -ETIMEDOUT;
373 }
374 msleep(1);
375 }
376#endif
377
378 switch ((buf[0] >> 8) & 0xff) {
379 case COMTYPE_PIDFILTER:
380 case COMTYPE_ENCODER:
381 case COMTYPE_REC_PLAY:
382 case COMTYPE_MPEGDECODER:
383 type = "MSG";
384 flags[0] = GPMQOver;
385 flags[1] = GPMQFull;
386 break;
387 case COMTYPE_OSD:
388 type = "OSD";
389 flags[0] = OSDQOver;
390 flags[1] = OSDQFull;
391 break;
392 case COMTYPE_MISC:
393 if (FW_VERSION(av7110->arm_app) >= 0x261d) {
394 type = "MSG";
395 flags[0] = GPMQOver;
396 flags[1] = GPMQBusy;
397 }
398 break;
399 default:
400 break;
401 }
402
403 if (type != NULL) {
404 /* non-immediate COMMAND type */
405 start = jiffies;
406 for (;;) {
407 err = time_after(jiffies, start + ARM_WAIT_FREE);
408 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
409 if (stat & flags[0]) {
410 printk(KERN_ERR "%s: %s QUEUE overflow\n",
411 __func__, type);
412 return -1;
413 }
414 if ((stat & flags[1]) == 0)
415 break;
416 if (err) {
417 printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n",
418 __func__, type);
419 av7110->arm_errors++;
420 return -ETIMEDOUT;
421 }
422 msleep(1);
423 }
424 }
425
426 for (i = 2; i < length; i++)
427 wdebi(av7110, DEBINOSWAP, COMMAND + 2 * i, (u32) buf[i], 2);
428
429 if (length)
430 wdebi(av7110, DEBINOSWAP, COMMAND + 2, (u32) buf[1], 2);
431 else
432 wdebi(av7110, DEBINOSWAP, COMMAND + 2, 0, 2);
433
434 wdebi(av7110, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
435
436 if (FW_VERSION(av7110->arm_app) <= 0x261f)
437 wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0x0000, 2);
438
439#ifdef COM_DEBUG
440 start = jiffies;
441 while (1) {
442 err = time_after(jiffies, start + ARM_WAIT_FREE);
443 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
444 break;
445 if (err) {
446 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND %d to complete\n",
447 __func__, (buf[0] >> 8) & 0xff);
448 return -ETIMEDOUT;
449 }
450 msleep(1);
451 }
452
453 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
454 if (stat & GPMQOver) {
455 printk(KERN_ERR "dvb-ttpci: %s(): GPMQOver\n", __func__);
456 return -ENOSPC;
457 }
458 else if (stat & OSDQOver) {
459 printk(KERN_ERR "dvb-ttpci: %s(): OSDQOver\n", __func__);
460 return -ENOSPC;
461 }
462#endif
463
464 return 0;
465}
466
467static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
468{
469 int ret;
470
471// dprintk(4, "%p\n", av7110);
472
473 if (!av7110->arm_ready) {
474 dprintk(1, "arm not ready.\n");
475 return -1;
476 }
477 if (mutex_lock_interruptible(&av7110->dcomlock))
478 return -ERESTARTSYS;
479
480 ret = __av7110_send_fw_cmd(av7110, buf, length);
481 mutex_unlock(&av7110->dcomlock);
482 if (ret && ret!=-ERESTARTSYS)
483 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
484 __func__, ret);
485 return ret;
486}
487
488int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
489{
490 va_list args;
491 u16 buf[num + 2];
492 int i, ret;
493
494// dprintk(4, "%p\n", av7110);
495
496 buf[0] = ((type << 8) | com);
497 buf[1] = num;
498
499 if (num) {
500 va_start(args, num);
501 for (i = 0; i < num; i++)
502 buf[i + 2] = va_arg(args, u32);
503 va_end(args);
504 }
505
506 ret = av7110_send_fw_cmd(av7110, buf, num + 2);
507 if (ret && ret != -ERESTARTSYS)
508 printk(KERN_ERR "dvb-ttpci: av7110_fw_cmd error %d\n", ret);
509 return ret;
510}
511
512#if 0
513int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
514{
515 int i, ret;
516 u16 cmd[18] = { ((COMTYPE_COMMON_IF << 8) + subcom),
517 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
518
519 dprintk(4, "%p\n", av7110);
520
521 for(i = 0; i < len && i < 32; i++)
522 {
523 if(i % 2 == 0)
524 cmd[(i / 2) + 2] = (u16)(buf[i]) << 8;
525 else
526 cmd[(i / 2) + 2] |= buf[i];
527 }
528
529 ret = av7110_send_fw_cmd(av7110, cmd, 18);
530 if (ret && ret != -ERESTARTSYS)
531 printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret);
532 return ret;
533}
534#endif /* 0 */
535
536int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
537 int request_buf_len, u16 *reply_buf, int reply_buf_len)
538{
539 int err;
540 s16 i;
541 unsigned long start;
542#ifdef COM_DEBUG
543 u32 stat;
544#endif
545
546 dprintk(4, "%p\n", av7110);
547
548 if (!av7110->arm_ready) {
549 dprintk(1, "arm not ready.\n");
550 return -1;
551 }
552
553 if (mutex_lock_interruptible(&av7110->dcomlock))
554 return -ERESTARTSYS;
555
556 if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) {
557 mutex_unlock(&av7110->dcomlock);
558 printk(KERN_ERR "dvb-ttpci: av7110_fw_request error %d\n", err);
559 return err;
560 }
561
562 start = jiffies;
563 while (1) {
564 err = time_after(jiffies, start + ARM_WAIT_FREE);
565 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
566 break;
567 if (err) {
568 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __func__);
569 mutex_unlock(&av7110->dcomlock);
570 return -ETIMEDOUT;
571 }
572#ifdef _NOHANDSHAKE
573 msleep(1);
574#endif
575 }
576
577#ifndef _NOHANDSHAKE
578 start = jiffies;
579 while (1) {
580 err = time_after(jiffies, start + ARM_WAIT_SHAKE);
581 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
582 break;
583 if (err) {
584 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __func__);
585 mutex_unlock(&av7110->dcomlock);
586 return -ETIMEDOUT;
587 }
588 msleep(1);
589 }
590#endif
591
592#ifdef COM_DEBUG
593 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
594 if (stat & GPMQOver) {
595 printk(KERN_ERR "%s: GPMQOver\n", __func__);
596 mutex_unlock(&av7110->dcomlock);
597 return -1;
598 }
599 else if (stat & OSDQOver) {
600 printk(KERN_ERR "%s: OSDQOver\n", __func__);
601 mutex_unlock(&av7110->dcomlock);
602 return -1;
603 }
604#endif
605
606 for (i = 0; i < reply_buf_len; i++)
607 reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2);
608
609 mutex_unlock(&av7110->dcomlock);
610 return 0;
611}
612
613static int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length)
614{
615 int ret;
616 ret = av7110_fw_request(av7110, &tag, 0, buf, length);
617 if (ret)
618 printk(KERN_ERR "dvb-ttpci: av7110_fw_query error %d\n", ret);
619 return ret;
620}
621
622
623/****************************************************************************
624 * Firmware commands
625 ****************************************************************************/
626
627/* get version of the firmware ROM, RTSL, video ucode and ARM application */
628int av7110_firmversion(struct av7110 *av7110)
629{
630 u16 buf[20];
631 u16 tag = ((COMTYPE_REQUEST << 8) + ReqVersion);
632
633 dprintk(4, "%p\n", av7110);
634
635 if (av7110_fw_query(av7110, tag, buf, 16)) {
636 printk("dvb-ttpci: failed to boot firmware @ card %d\n",
637 av7110->dvb_adapter.num);
638 return -EIO;
639 }
640
641 av7110->arm_fw = (buf[0] << 16) + buf[1];
642 av7110->arm_rtsl = (buf[2] << 16) + buf[3];
643 av7110->arm_vid = (buf[4] << 16) + buf[5];
644 av7110->arm_app = (buf[6] << 16) + buf[7];
645 av7110->avtype = (buf[8] << 16) + buf[9];
646
647 printk("dvb-ttpci: info @ card %d: firm %08x, rtsl %08x, vid %08x, app %08x\n",
648 av7110->dvb_adapter.num, av7110->arm_fw,
649 av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app);
650
651 /* print firmware capabilities */
652 if (FW_CI_LL_SUPPORT(av7110->arm_app))
653 printk("dvb-ttpci: firmware @ card %d supports CI link layer interface\n",
654 av7110->dvb_adapter.num);
655 else
656 printk("dvb-ttpci: no firmware support for CI link layer interface @ card %d\n",
657 av7110->dvb_adapter.num);
658
659 return 0;
660}
661
662
663int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst)
664{
665 int i, ret;
666 u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) + SendDiSEqC),
667 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
668
669 dprintk(4, "%p\n", av7110);
670
671 if (len > 10)
672 len = 10;
673
674 buf[1] = len + 2;
675 buf[2] = len;
676
677 if (burst != -1)
678 buf[3] = burst ? 0x01 : 0x00;
679 else
680 buf[3] = 0xffff;
681
682 for (i = 0; i < len; i++)
683 buf[i + 4] = msg[i];
684
685 ret = av7110_send_fw_cmd(av7110, buf, 18);
686 if (ret && ret!=-ERESTARTSYS)
687 printk(KERN_ERR "dvb-ttpci: av7110_diseqc_send error %d\n", ret);
688 return ret;
689}
690
691
692#ifdef CONFIG_DVB_AV7110_OSD
693
694static inline int SetColorBlend(struct av7110 *av7110, u8 windownr)
695{
696 return av7110_fw_cmd(av7110, COMTYPE_OSD, SetCBlend, 1, windownr);
697}
698
699static inline int SetBlend_(struct av7110 *av7110, u8 windownr,
700 enum av7110_osd_palette_type colordepth, u16 index, u8 blending)
701{
702 return av7110_fw_cmd(av7110, COMTYPE_OSD, SetBlend, 4,
703 windownr, colordepth, index, blending);
704}
705
706static inline int SetColor_(struct av7110 *av7110, u8 windownr,
707 enum av7110_osd_palette_type colordepth, u16 index, u16 colorhi, u16 colorlo)
708{
709 return av7110_fw_cmd(av7110, COMTYPE_OSD, SetColor, 5,
710 windownr, colordepth, index, colorhi, colorlo);
711}
712
713static inline int SetFont(struct av7110 *av7110, u8 windownr, u8 fontsize,
714 u16 colorfg, u16 colorbg)
715{
716 return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Font, 4,
717 windownr, fontsize, colorfg, colorbg);
718}
719
720static int FlushText(struct av7110 *av7110)
721{
722 unsigned long start;
723 int err;
724
725 if (mutex_lock_interruptible(&av7110->dcomlock))
726 return -ERESTARTSYS;
727 start = jiffies;
728 while (1) {
729 err = time_after(jiffies, start + ARM_WAIT_OSD);
730 if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
731 break;
732 if (err) {
733 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
734 __func__);
735 mutex_unlock(&av7110->dcomlock);
736 return -ETIMEDOUT;
737 }
738 msleep(1);
739 }
740 mutex_unlock(&av7110->dcomlock);
741 return 0;
742}
743
744static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, char *buf)
745{
746 int i, ret;
747 unsigned long start;
748 int length = strlen(buf) + 1;
749 u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y };
750
751 if (mutex_lock_interruptible(&av7110->dcomlock))
752 return -ERESTARTSYS;
753
754 start = jiffies;
755 while (1) {
756 ret = time_after(jiffies, start + ARM_WAIT_OSD);
757 if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
758 break;
759 if (ret) {
760 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
761 __func__);
762 mutex_unlock(&av7110->dcomlock);
763 return -ETIMEDOUT;
764 }
765 msleep(1);
766 }
767#ifndef _NOHANDSHAKE
768 start = jiffies;
769 while (1) {
770 ret = time_after(jiffies, start + ARM_WAIT_SHAKE);
771 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
772 break;
773 if (ret) {
774 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
775 __func__);
776 mutex_unlock(&av7110->dcomlock);
777 return -ETIMEDOUT;
778 }
779 msleep(1);
780 }
781#endif
782 for (i = 0; i < length / 2; i++)
783 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2,
784 swab16(*(u16 *)(buf + 2 * i)), 2);
785 if (length & 1)
786 wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
787 ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
788 mutex_unlock(&av7110->dcomlock);
789 if (ret && ret!=-ERESTARTSYS)
790 printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret);
791 return ret;
792}
793
794static inline int DrawLine(struct av7110 *av7110, u8 windownr,
795 u16 x, u16 y, u16 dx, u16 dy, u16 color)
796{
797 return av7110_fw_cmd(av7110, COMTYPE_OSD, DLine, 6,
798 windownr, x, y, dx, dy, color);
799}
800
801static inline int DrawBlock(struct av7110 *av7110, u8 windownr,
802 u16 x, u16 y, u16 dx, u16 dy, u16 color)
803{
804 return av7110_fw_cmd(av7110, COMTYPE_OSD, DBox, 6,
805 windownr, x, y, dx, dy, color);
806}
807
808static inline int HideWindow(struct av7110 *av7110, u8 windownr)
809{
810 return av7110_fw_cmd(av7110, COMTYPE_OSD, WHide, 1, windownr);
811}
812
813static inline int MoveWindowRel(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
814{
815 return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveD, 3, windownr, x, y);
816}
817
818static inline int MoveWindowAbs(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
819{
820 return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveA, 3, windownr, x, y);
821}
822
823static inline int DestroyOSDWindow(struct av7110 *av7110, u8 windownr)
824{
825 return av7110_fw_cmd(av7110, COMTYPE_OSD, WDestroy, 1, windownr);
826}
827
828static inline int CreateOSDWindow(struct av7110 *av7110, u8 windownr,
829 osd_raw_window_t disptype,
830 u16 width, u16 height)
831{
832 return av7110_fw_cmd(av7110, COMTYPE_OSD, WCreate, 4,
833 windownr, disptype, width, height);
834}
835
836
837static enum av7110_osd_palette_type bpp2pal[8] = {
838 Pal1Bit, Pal2Bit, 0, Pal4Bit, 0, 0, 0, Pal8Bit
839};
840static osd_raw_window_t bpp2bit[8] = {
841 OSD_BITMAP1, OSD_BITMAP2, 0, OSD_BITMAP4, 0, 0, 0, OSD_BITMAP8
842};
843
844static inline int WaitUntilBmpLoaded(struct av7110 *av7110)
845{
846 int ret = wait_event_timeout(av7110->bmpq,
847 av7110->bmp_state != BMP_LOADING, 10*HZ);
848 if (ret == 0) {
849 printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
850 ret, av7110->bmp_state);
851 av7110->bmp_state = BMP_NONE;
852 return -ETIMEDOUT;
853 }
854 return 0;
855}
856
857static inline int LoadBitmap(struct av7110 *av7110,
858 u16 dx, u16 dy, int inc, u8 __user * data)
859{
860 u16 format;
861 int bpp;
862 int i;
863 int d, delta;
864 u8 c;
865 int ret;
866
867 dprintk(4, "%p\n", av7110);
868
869 format = bpp2bit[av7110->osdbpp[av7110->osdwin]];
870
871 av7110->bmp_state = BMP_LOADING;
872 if (format == OSD_BITMAP8) {
873 bpp=8; delta = 1;
874 } else if (format == OSD_BITMAP4) {
875 bpp=4; delta = 2;
876 } else if (format == OSD_BITMAP2) {
877 bpp=2; delta = 4;
878 } else if (format == OSD_BITMAP1) {
879 bpp=1; delta = 8;
880 } else {
881 av7110->bmp_state = BMP_NONE;
882 return -EINVAL;
883 }
884 av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8;
885 av7110->bmpp = 0;
886 if (av7110->bmplen > 32768) {
887 av7110->bmp_state = BMP_NONE;
888 return -EINVAL;
889 }
890 for (i = 0; i < dy; i++) {
891 if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) {
892 av7110->bmp_state = BMP_NONE;
893 return -EINVAL;
894 }
895 }
896 if (format != OSD_BITMAP8) {
897 for (i = 0; i < dx * dy / delta; i++) {
898 c = ((u8 *)av7110->bmpbuf)[1024 + i * delta + delta - 1];
899 for (d = delta - 2; d >= 0; d--) {
900 c |= (((u8 *)av7110->bmpbuf)[1024 + i * delta + d]
901 << ((delta - d - 1) * bpp));
902 ((u8 *)av7110->bmpbuf)[1024 + i] = c;
903 }
904 }
905 }
906 av7110->bmplen += 1024;
907 dprintk(4, "av7110_fw_cmd: LoadBmp size %d\n", av7110->bmplen);
908 ret = av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy);
909 if (!ret)
910 ret = WaitUntilBmpLoaded(av7110);
911 return ret;
912}
913
914static int BlitBitmap(struct av7110 *av7110, u16 x, u16 y)
915{
916 dprintk(4, "%p\n", av7110);
917
918 return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, av7110->osdwin, x, y, 0);
919}
920
921static inline int ReleaseBitmap(struct av7110 *av7110)
922{
923 dprintk(4, "%p\n", av7110);
924
925 if (av7110->bmp_state != BMP_LOADED && FW_VERSION(av7110->arm_app) < 0x261e)
926 return -1;
927 if (av7110->bmp_state == BMP_LOADING)
928 dprintk(1,"ReleaseBitmap called while BMP_LOADING\n");
929 av7110->bmp_state = BMP_NONE;
930 return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0);
931}
932
933static u32 RGB2YUV(u16 R, u16 G, u16 B)
934{
935 u16 y, u, v;
936 u16 Y, Cr, Cb;
937
938 y = R * 77 + G * 150 + B * 29; /* Luma=0.299R+0.587G+0.114B 0..65535 */
939 u = 2048 + B * 8 -(y >> 5); /* Cr 0..4095 */
940 v = 2048 + R * 8 -(y >> 5); /* Cb 0..4095 */
941
942 Y = y / 256;
943 Cb = u / 16;
944 Cr = v / 16;
945
946 return Cr | (Cb << 16) | (Y << 8);
947}
948
949static int OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend)
950{
951 int ret;
952
953 u16 ch, cl;
954 u32 yuv;
955
956 yuv = blend ? RGB2YUV(r,g,b) : 0;
957 cl = (yuv & 0xffff);
958 ch = ((yuv >> 16) & 0xffff);
959 ret = SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
960 color, ch, cl);
961 if (!ret)
962 ret = SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
963 color, ((blend >> 4) & 0x0f));
964 return ret;
965}
966
967static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last)
968{
969 int i;
970 int length = last - first + 1;
971
972 if (length * 4 > DATA_BUFF3_SIZE)
973 return -EINVAL;
974
975 for (i = 0; i < length; i++) {
976 u32 color, blend, yuv;
977
978 if (get_user(color, colors + i))
979 return -EFAULT;
980 blend = (color & 0xF0000000) >> 4;
981 yuv = blend ? RGB2YUV(color & 0xFF, (color >> 8) & 0xFF,
982 (color >> 16) & 0xFF) | blend : 0;
983 yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16);
984 wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4);
985 }
986 return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4,
987 av7110->osdwin,
988 bpp2pal[av7110->osdbpp[av7110->osdwin]],
989 first, last);
990}
991
992static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
993 int x1, int y1, int inc, u8 __user * data)
994{
995 uint w, h, bpp, bpl, size, lpb, bnum, brest;
996 int i;
997 int rc,release_rc;
998
999 w = x1 - x0 + 1;
1000 h = y1 - y0 + 1;
1001 if (inc <= 0)
1002 inc = w;
1003 if (w <= 0 || w > 720 || h <= 0 || h > 576)
1004 return -EINVAL;
1005 bpp = av7110->osdbpp[av7110->osdwin] + 1;
1006 bpl = ((w * bpp + 7) & ~7) / 8;
1007 size = h * bpl;
1008 lpb = (32 * 1024) / bpl;
1009 bnum = size / (lpb * bpl);
1010 brest = size - bnum * lpb * bpl;
1011
1012 if (av7110->bmp_state == BMP_LOADING) {
1013 /* possible if syscall is repeated by -ERESTARTSYS and if firmware cannot abort */
1014 BUG_ON (FW_VERSION(av7110->arm_app) >= 0x261e);
1015 rc = WaitUntilBmpLoaded(av7110);
1016 if (rc)
1017 return rc;
1018 /* just continue. This should work for all fw versions
1019 * if bnum==1 && !brest && LoadBitmap was successful
1020 */
1021 }
1022
1023 rc = 0;
1024 for (i = 0; i < bnum; i++) {
1025 rc = LoadBitmap(av7110, w, lpb, inc, data);
1026 if (rc)
1027 break;
1028 rc = BlitBitmap(av7110, x0, y0 + i * lpb);
1029 if (rc)
1030 break;
1031 data += lpb * inc;
1032 }
1033 if (!rc && brest) {
1034 rc = LoadBitmap(av7110, w, brest / bpl, inc, data);
1035 if (!rc)
1036 rc = BlitBitmap(av7110, x0, y0 + bnum * lpb);
1037 }
1038 release_rc = ReleaseBitmap(av7110);
1039 if (!rc)
1040 rc = release_rc;
1041 if (rc)
1042 dprintk(1,"returns %d\n",rc);
1043 return rc;
1044}
1045
1046int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
1047{
1048 int ret;
1049
1050 if (mutex_lock_interruptible(&av7110->osd_mutex))
1051 return -ERESTARTSYS;
1052
1053 switch (dc->cmd) {
1054 case OSD_Close:
1055 ret = DestroyOSDWindow(av7110, av7110->osdwin);
1056 break;
1057 case OSD_Open:
1058 av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7;
1059 ret = CreateOSDWindow(av7110, av7110->osdwin,
1060 bpp2bit[av7110->osdbpp[av7110->osdwin]],
1061 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
1062 if (ret)
1063 break;
1064 if (!dc->data) {
1065 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1066 if (ret)
1067 break;
1068 ret = SetColorBlend(av7110, av7110->osdwin);
1069 }
1070 break;
1071 case OSD_Show:
1072 ret = MoveWindowRel(av7110, av7110->osdwin, 0, 0);
1073 break;
1074 case OSD_Hide:
1075 ret = HideWindow(av7110, av7110->osdwin);
1076 break;
1077 case OSD_Clear:
1078 ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0);
1079 break;
1080 case OSD_Fill:
1081 ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color);
1082 break;
1083 case OSD_SetColor:
1084 ret = OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1);
1085 break;
1086 case OSD_SetPalette:
1087 if (FW_VERSION(av7110->arm_app) >= 0x2618)
1088 ret = OSDSetPalette(av7110, dc->data, dc->color, dc->x0);
1089 else {
1090 int i, len = dc->x0-dc->color+1;
1091 u8 __user *colors = (u8 __user *)dc->data;
1092 u8 r, g = 0, b = 0, blend = 0;
1093 ret = 0;
1094 for (i = 0; i<len; i++) {
1095 if (get_user(r, colors + i * 4) ||
1096 get_user(g, colors + i * 4 + 1) ||
1097 get_user(b, colors + i * 4 + 2) ||
1098 get_user(blend, colors + i * 4 + 3)) {
1099 ret = -EFAULT;
1100 break;
1101 }
1102 ret = OSDSetColor(av7110, dc->color + i, r, g, b, blend);
1103 if (ret)
1104 break;
1105 }
1106 }
1107 break;
1108 case OSD_SetPixel:
1109 ret = DrawLine(av7110, av7110->osdwin,
1110 dc->x0, dc->y0, 0, 0, dc->color);
1111 break;
1112 case OSD_SetRow:
1113 dc->y1 = dc->y0;
1114 /* fall through */
1115 case OSD_SetBlock:
1116 ret = OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data);
1117 break;
1118 case OSD_FillRow:
1119 ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
1120 dc->x1-dc->x0+1, dc->y1, dc->color);
1121 break;
1122 case OSD_FillBlock:
1123 ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
1124 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color);
1125 break;
1126 case OSD_Line:
1127 ret = DrawLine(av7110, av7110->osdwin,
1128 dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color);
1129 break;
1130 case OSD_Text:
1131 {
1132 char textbuf[240];
1133
1134 if (strncpy_from_user(textbuf, dc->data, 240) < 0) {
1135 ret = -EFAULT;
1136 break;
1137 }
1138 textbuf[239] = 0;
1139 if (dc->x1 > 3)
1140 dc->x1 = 3;
1141 ret = SetFont(av7110, av7110->osdwin, dc->x1,
1142 (u16) (dc->color & 0xffff), (u16) (dc->color >> 16));
1143 if (!ret)
1144 ret = FlushText(av7110);
1145 if (!ret)
1146 ret = WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf);
1147 break;
1148 }
1149 case OSD_SetWindow:
1150 if (dc->x0 < 1 || dc->x0 > 7)
1151 ret = -EINVAL;
1152 else {
1153 av7110->osdwin = dc->x0;
1154 ret = 0;
1155 }
1156 break;
1157 case OSD_MoveWindow:
1158 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1159 if (!ret)
1160 ret = SetColorBlend(av7110, av7110->osdwin);
1161 break;
1162 case OSD_OpenRaw:
1163 if (dc->color < OSD_BITMAP1 || dc->color > OSD_CURSOR) {
1164 ret = -EINVAL;
1165 break;
1166 }
1167 if (dc->color >= OSD_BITMAP1 && dc->color <= OSD_BITMAP8HR)
1168 av7110->osdbpp[av7110->osdwin] = (1 << (dc->color & 3)) - 1;
1169 else
1170 av7110->osdbpp[av7110->osdwin] = 0;
1171 ret = CreateOSDWindow(av7110, av7110->osdwin, (osd_raw_window_t)dc->color,
1172 dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
1173 if (ret)
1174 break;
1175 if (!dc->data) {
1176 ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
1177 if (!ret)
1178 ret = SetColorBlend(av7110, av7110->osdwin);
1179 }
1180 break;
1181 default:
1182 ret = -EINVAL;
1183 break;
1184 }
1185
1186 mutex_unlock(&av7110->osd_mutex);
1187 if (ret==-ERESTARTSYS)
1188 dprintk(1, "av7110_osd_cmd(%d) returns with -ERESTARTSYS\n",dc->cmd);
1189 else if (ret)
1190 dprintk(1, "av7110_osd_cmd(%d) returns with %d\n",dc->cmd,ret);
1191
1192 return ret;
1193}
1194
1195int av7110_osd_capability(struct av7110 *av7110, osd_cap_t *cap)
1196{
1197 switch (cap->cmd) {
1198 case OSD_CAP_MEMSIZE:
1199 if (FW_4M_SDRAM(av7110->arm_app))
1200 cap->val = 1000000;
1201 else
1202 cap->val = 92000;
1203 return 0;
1204 default:
1205 return -EINVAL;
1206 }
1207}
1208#endif /* CONFIG_DVB_AV7110_OSD */
diff --git a/drivers/media/dvb/ttpci/av7110_hw.h b/drivers/media/dvb/ttpci/av7110_hw.h
deleted file mode 100644
index 1634aba5cb84..000000000000
--- a/drivers/media/dvb/ttpci/av7110_hw.h
+++ /dev/null
@@ -1,495 +0,0 @@
1#ifndef _AV7110_HW_H_
2#define _AV7110_HW_H_
3
4#include "av7110.h"
5
6/* DEBI transfer mode defs */
7
8#define DEBINOSWAP 0x000e0000
9#define DEBISWAB 0x001e0000
10#define DEBISWAP 0x002e0000
11
12#define ARM_WAIT_FREE (HZ)
13#define ARM_WAIT_SHAKE (HZ/5)
14#define ARM_WAIT_OSD (HZ)
15
16
17enum av7110_bootstate
18{
19 BOOTSTATE_BUFFER_EMPTY = 0,
20 BOOTSTATE_BUFFER_FULL = 1,
21 BOOTSTATE_AV7110_BOOT_COMPLETE = 2
22};
23
24enum av7110_type_rec_play_format
25{ RP_None,
26 AudioPES,
27 AudioMp2,
28 AudioPCM,
29 VideoPES,
30 AV_PES
31};
32
33enum av7110_osd_palette_type
34{
35 NoPalet = 0, /* No palette */
36 Pal1Bit = 2, /* 2 colors for 1 Bit Palette */
37 Pal2Bit = 4, /* 4 colors for 2 bit palette */
38 Pal4Bit = 16, /* 16 colors for 4 bit palette */
39 Pal8Bit = 256 /* 256 colors for 16 bit palette */
40};
41
42/* switch defines */
43#define SB_GPIO 3
44#define SB_OFF SAA7146_GPIO_OUTLO /* SlowBlank off (TV-Mode) */
45#define SB_ON SAA7146_GPIO_INPUT /* SlowBlank on (AV-Mode) */
46#define SB_WIDE SAA7146_GPIO_OUTHI /* SlowBlank 6V (16/9-Mode) (not implemented) */
47
48#define FB_GPIO 1
49#define FB_OFF SAA7146_GPIO_LO /* FastBlank off (CVBS-Mode) */
50#define FB_ON SAA7146_GPIO_OUTHI /* FastBlank on (RGB-Mode) */
51#define FB_LOOP SAA7146_GPIO_INPUT /* FastBlank loop-through (PC graphics ???) */
52
53enum av7110_video_output_mode
54{
55 NO_OUT = 0, /* disable analog output */
56 CVBS_RGB_OUT = 1,
57 CVBS_YC_OUT = 2,
58 YC_OUT = 3
59};
60
61/* firmware internal msg q status: */
62#define GPMQFull 0x0001 /* Main Message Queue Full */
63#define GPMQOver 0x0002 /* Main Message Queue Overflow */
64#define HPQFull 0x0004 /* High Priority Msg Queue Full */
65#define HPQOver 0x0008
66#define OSDQFull 0x0010 /* OSD Queue Full */
67#define OSDQOver 0x0020
68#define GPMQBusy 0x0040 /* Queue not empty, FW >= 261d */
69#define HPQBusy 0x0080
70#define OSDQBusy 0x0100
71
72/* hw section filter flags */
73#define SECTION_EIT 0x01
74#define SECTION_SINGLE 0x00
75#define SECTION_CYCLE 0x02
76#define SECTION_CONTINUOS 0x04
77#define SECTION_MODE 0x06
78#define SECTION_IPMPE 0x0C /* size up to 4k */
79#define SECTION_HIGH_SPEED 0x1C /* larger buffer */
80#define DATA_PIPING_FLAG 0x20 /* for Data Piping Filter */
81
82#define PBUFSIZE_NONE 0x0000
83#define PBUFSIZE_1P 0x0100
84#define PBUFSIZE_2P 0x0200
85#define PBUFSIZE_1K 0x0300
86#define PBUFSIZE_2K 0x0400
87#define PBUFSIZE_4K 0x0500
88#define PBUFSIZE_8K 0x0600
89#define PBUFSIZE_16K 0x0700
90#define PBUFSIZE_32K 0x0800
91
92
93/* firmware command codes */
94enum av7110_osd_command {
95 WCreate,
96 WDestroy,
97 WMoveD,
98 WMoveA,
99 WHide,
100 WTop,
101 DBox,
102 DLine,
103 DText,
104 Set_Font,
105 SetColor,
106 SetBlend,
107 SetWBlend,
108 SetCBlend,
109 SetNonBlend,
110 LoadBmp,
111 BlitBmp,
112 ReleaseBmp,
113 SetWTrans,
114 SetWNoTrans,
115 Set_Palette
116};
117
118enum av7110_pid_command {
119 MultiPID,
120 VideoPID,
121 AudioPID,
122 InitFilt,
123 FiltError,
124 NewVersion,
125 CacheError,
126 AddPIDFilter,
127 DelPIDFilter,
128 Scan,
129 SetDescr,
130 SetIR,
131 FlushTSQueue
132};
133
134enum av7110_mpeg_command {
135 SelAudChannels
136};
137
138enum av7110_audio_command {
139 AudioDAC,
140 CabADAC,
141 ON22K,
142 OFF22K,
143 MainSwitch,
144 ADSwitch,
145 SendDiSEqC,
146 SetRegister,
147 SpdifSwitch
148};
149
150enum av7110_request_command {
151 AudioState,
152 AudioBuffState,
153 VideoState1,
154 VideoState2,
155 VideoState3,
156 CrashCounter,
157 ReqVersion,
158 ReqVCXO,
159 ReqRegister,
160 ReqSecFilterError,
161 ReqSTC
162};
163
164enum av7110_encoder_command {
165 SetVidMode,
166 SetTestMode,
167 LoadVidCode,
168 SetMonitorType,
169 SetPanScanType,
170 SetFreezeMode,
171 SetWSSConfig
172};
173
174enum av7110_rec_play_state {
175 __Record,
176 __Stop,
177 __Play,
178 __Pause,
179 __Slow,
180 __FF_IP,
181 __Scan_I,
182 __Continue
183};
184
185enum av7110_fw_cmd_misc {
186 AV7110_FW_VIDEO_ZOOM = 1,
187 AV7110_FW_VIDEO_COMMAND,
188 AV7110_FW_AUDIO_COMMAND
189};
190
191enum av7110_command_type {
192 COMTYPE_NOCOM,
193 COMTYPE_PIDFILTER,
194 COMTYPE_MPEGDECODER,
195 COMTYPE_OSD,
196 COMTYPE_BMP,
197 COMTYPE_ENCODER,
198 COMTYPE_AUDIODAC,
199 COMTYPE_REQUEST,
200 COMTYPE_SYSTEM,
201 COMTYPE_REC_PLAY,
202 COMTYPE_COMMON_IF,
203 COMTYPE_PID_FILTER,
204 COMTYPE_PES,
205 COMTYPE_TS,
206 COMTYPE_VIDEO,
207 COMTYPE_AUDIO,
208 COMTYPE_CI_LL,
209 COMTYPE_MISC = 0x80
210};
211
212#define VID_NONE_PREF 0x00 /* No aspect ration processing preferred */
213#define VID_PAN_SCAN_PREF 0x01 /* Pan and Scan Display preferred */
214#define VID_VERT_COMP_PREF 0x02 /* Vertical compression display preferred */
215#define VID_VC_AND_PS_PREF 0x03 /* PanScan and vertical Compression if allowed */
216#define VID_CENTRE_CUT_PREF 0x05 /* PanScan with zero vector */
217
218/* MPEG video decoder commands */
219#define AV_VIDEO_CMD_STOP 0x000e
220#define AV_VIDEO_CMD_PLAY 0x000d
221#define AV_VIDEO_CMD_FREEZE 0x0102
222#define AV_VIDEO_CMD_FFWD 0x0016
223#define AV_VIDEO_CMD_SLOW 0x0022
224
225/* MPEG audio decoder commands */
226#define AUDIO_CMD_MUTE 0x0001
227#define AUDIO_CMD_UNMUTE 0x0002
228#define AUDIO_CMD_PCM16 0x0010
229#define AUDIO_CMD_STEREO 0x0080
230#define AUDIO_CMD_MONO_L 0x0100
231#define AUDIO_CMD_MONO_R 0x0200
232#define AUDIO_CMD_SYNC_OFF 0x000e
233#define AUDIO_CMD_SYNC_ON 0x000f
234
235/* firmware data interface codes */
236#define DATA_NONE 0x00
237#define DATA_FSECTION 0x01
238#define DATA_IPMPE 0x02
239#define DATA_MPEG_RECORD 0x03
240#define DATA_DEBUG_MESSAGE 0x04
241#define DATA_COMMON_INTERFACE 0x05
242#define DATA_MPEG_PLAY 0x06
243#define DATA_BMP_LOAD 0x07
244#define DATA_IRCOMMAND 0x08
245#define DATA_PIPING 0x09
246#define DATA_STREAMING 0x0a
247#define DATA_CI_GET 0x0b
248#define DATA_CI_PUT 0x0c
249#define DATA_MPEG_VIDEO_EVENT 0x0d
250
251#define DATA_PES_RECORD 0x10
252#define DATA_PES_PLAY 0x11
253#define DATA_TS_RECORD 0x12
254#define DATA_TS_PLAY 0x13
255
256/* ancient CI command codes, only two are actually still used
257 * by the link level CI firmware */
258#define CI_CMD_ERROR 0x00
259#define CI_CMD_ACK 0x01
260#define CI_CMD_SYSTEM_READY 0x02
261#define CI_CMD_KEYPRESS 0x03
262#define CI_CMD_ON_TUNED 0x04
263#define CI_CMD_ON_SWITCH_PROGRAM 0x05
264#define CI_CMD_SECTION_ARRIVED 0x06
265#define CI_CMD_SECTION_TIMEOUT 0x07
266#define CI_CMD_TIME 0x08
267#define CI_CMD_ENTER_MENU 0x09
268#define CI_CMD_FAST_PSI 0x0a
269#define CI_CMD_GET_SLOT_INFO 0x0b
270
271#define CI_MSG_NONE 0x00
272#define CI_MSG_CI_INFO 0x01
273#define CI_MSG_MENU 0x02
274#define CI_MSG_LIST 0x03
275#define CI_MSG_TEXT 0x04
276#define CI_MSG_REQUEST_INPUT 0x05
277#define CI_MSG_INPUT_COMPLETE 0x06
278#define CI_MSG_LIST_MORE 0x07
279#define CI_MSG_MENU_MORE 0x08
280#define CI_MSG_CLOSE_MMI_IMM 0x09
281#define CI_MSG_SECTION_REQUEST 0x0a
282#define CI_MSG_CLOSE_FILTER 0x0b
283#define CI_PSI_COMPLETE 0x0c
284#define CI_MODULE_READY 0x0d
285#define CI_SWITCH_PRG_REPLY 0x0e
286#define CI_MSG_TEXT_MORE 0x0f
287
288#define CI_MSG_CA_PMT 0xe0
289#define CI_MSG_ERROR 0xf0
290
291
292/* base address of the dual ported RAM which serves as communication
293 * area between PCI bus and av7110,
294 * as seen by the DEBI bus of the saa7146 */
295#define DPRAM_BASE 0x4000
296
297/* boot protocol area */
298#define AV7110_BOOT_STATE (DPRAM_BASE + 0x3F8)
299#define AV7110_BOOT_SIZE (DPRAM_BASE + 0x3FA)
300#define AV7110_BOOT_BASE (DPRAM_BASE + 0x3FC)
301#define AV7110_BOOT_BLOCK (DPRAM_BASE + 0x400)
302#define AV7110_BOOT_MAX_SIZE 0xc00
303
304/* firmware command protocol area */
305#define IRQ_STATE (DPRAM_BASE + 0x0F4)
306#define IRQ_STATE_EXT (DPRAM_BASE + 0x0F6)
307#define MSGSTATE (DPRAM_BASE + 0x0F8)
308#define COMMAND (DPRAM_BASE + 0x0FC)
309#define COM_BUFF (DPRAM_BASE + 0x100)
310#define COM_BUFF_SIZE 0x20
311
312/* various data buffers */
313#define BUFF1_BASE (DPRAM_BASE + 0x120)
314#define BUFF1_SIZE 0xE0
315
316#define DATA_BUFF0_BASE (DPRAM_BASE + 0x200)
317#define DATA_BUFF0_SIZE 0x0800
318
319#define DATA_BUFF1_BASE (DATA_BUFF0_BASE+DATA_BUFF0_SIZE)
320#define DATA_BUFF1_SIZE 0x0800
321
322#define DATA_BUFF2_BASE (DATA_BUFF1_BASE+DATA_BUFF1_SIZE)
323#define DATA_BUFF2_SIZE 0x0800
324
325#define DATA_BUFF3_BASE (DATA_BUFF2_BASE+DATA_BUFF2_SIZE)
326#define DATA_BUFF3_SIZE 0x0400
327
328#define Reserved (DPRAM_BASE + 0x1E00)
329#define Reserved_SIZE 0x1C0
330
331
332/* firmware status area */
333#define STATUS_BASE (DPRAM_BASE + 0x1FC0)
334#define STATUS_LOOPS (STATUS_BASE + 0x08)
335
336#define STATUS_MPEG_WIDTH (STATUS_BASE + 0x0C)
337/* ((aspect_ratio & 0xf) << 12) | (height & 0xfff) */
338#define STATUS_MPEG_HEIGHT_AR (STATUS_BASE + 0x0E)
339
340/* firmware data protocol area */
341#define RX_TYPE (DPRAM_BASE + 0x1FE8)
342#define RX_LEN (DPRAM_BASE + 0x1FEA)
343#define TX_TYPE (DPRAM_BASE + 0x1FEC)
344#define TX_LEN (DPRAM_BASE + 0x1FEE)
345
346#define RX_BUFF (DPRAM_BASE + 0x1FF4)
347#define TX_BUFF (DPRAM_BASE + 0x1FF6)
348
349#define HANDSHAKE_REG (DPRAM_BASE + 0x1FF8)
350#define COM_IF_LOCK (DPRAM_BASE + 0x1FFA)
351
352#define IRQ_RX (DPRAM_BASE + 0x1FFC)
353#define IRQ_TX (DPRAM_BASE + 0x1FFE)
354
355/* used by boot protocol to load firmware into av7110 DRAM */
356#define DRAM_START_CODE 0x2e000404
357#define DRAM_MAX_CODE_SIZE 0x00100000
358
359/* saa7146 gpio lines */
360#define RESET_LINE 2
361#define DEBI_DONE_LINE 1
362#define ARM_IRQ_LINE 0
363
364
365
366extern int av7110_bootarm(struct av7110 *av7110);
367extern int av7110_firmversion(struct av7110 *av7110);
368#define FW_CI_LL_SUPPORT(arm_app) ((arm_app) & 0x80000000)
369#define FW_4M_SDRAM(arm_app) ((arm_app) & 0x40000000)
370#define FW_VERSION(arm_app) ((arm_app) & 0x0000FFFF)
371
372extern int av7110_wait_msgstate(struct av7110 *av7110, u16 flags);
373extern int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...);
374extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
375 int request_buf_len, u16 *reply_buf, int reply_buf_len);
376
377
378/* DEBI (saa7146 data extension bus interface) access */
379extern int av7110_debiwrite(struct av7110 *av7110, u32 config,
380 int addr, u32 val, int count);
381extern u32 av7110_debiread(struct av7110 *av7110, u32 config,
382 int addr, int count);
383
384
385/* DEBI during interrupt */
386/* single word writes */
387static inline void iwdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
388{
389 av7110_debiwrite(av7110, config, addr, val, count);
390}
391
392/* buffer writes */
393static inline void mwdebi(struct av7110 *av7110, u32 config, int addr,
394 const u8 *val, int count)
395{
396 memcpy(av7110->debi_virt, val, count);
397 av7110_debiwrite(av7110, config, addr, 0, count);
398}
399
400static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
401{
402 u32 res;
403
404 res=av7110_debiread(av7110, config, addr, count);
405 if (count<=4)
406 memcpy(av7110->debi_virt, (char *) &res, count);
407 return res;
408}
409
410/* DEBI outside interrupts, only for count <= 4! */
411static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
412{
413 unsigned long flags;
414
415 spin_lock_irqsave(&av7110->debilock, flags);
416 av7110_debiwrite(av7110, config, addr, val, count);
417 spin_unlock_irqrestore(&av7110->debilock, flags);
418}
419
420static inline u32 rdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
421{
422 unsigned long flags;
423 u32 res;
424
425 spin_lock_irqsave(&av7110->debilock, flags);
426 res=av7110_debiread(av7110, config, addr, count);
427 spin_unlock_irqrestore(&av7110->debilock, flags);
428 return res;
429}
430
431/* handle mailbox registers of the dual ported RAM */
432static inline void ARM_ResetMailBox(struct av7110 *av7110)
433{
434 unsigned long flags;
435
436 spin_lock_irqsave(&av7110->debilock, flags);
437 av7110_debiread(av7110, DEBINOSWAP, IRQ_RX, 2);
438 av7110_debiwrite(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
439 spin_unlock_irqrestore(&av7110->debilock, flags);
440}
441
442static inline void ARM_ClearMailBox(struct av7110 *av7110)
443{
444 iwdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
445}
446
447static inline void ARM_ClearIrq(struct av7110 *av7110)
448{
449 irdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
450}
451
452/****************************************************************************
453 * Firmware commands
454 ****************************************************************************/
455
456static inline int SendDAC(struct av7110 *av7110, u8 addr, u8 data)
457{
458 return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, AudioDAC, 2, addr, data);
459}
460
461static inline int av7710_set_video_mode(struct av7110 *av7110, int mode)
462{
463 return av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetVidMode, 1, mode);
464}
465
466static inline int vidcom(struct av7110 *av7110, u32 com, u32 arg)
467{
468 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_VIDEO_COMMAND, 4,
469 (com>>16), (com&0xffff),
470 (arg>>16), (arg&0xffff));
471}
472
473static inline int audcom(struct av7110 *av7110, u32 com)
474{
475 return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_AUDIO_COMMAND, 2,
476 (com>>16), (com&0xffff));
477}
478
479static inline int Set22K(struct av7110 *av7110, int state)
480{
481 return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, (state ? ON22K : OFF22K), 0);
482}
483
484
485extern int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst);
486
487
488#ifdef CONFIG_DVB_AV7110_OSD
489extern int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc);
490extern int av7110_osd_capability(struct av7110 *av7110, osd_cap_t *cap);
491#endif /* CONFIG_DVB_AV7110_OSD */
492
493
494
495#endif /* _AV7110_HW_H_ */
diff --git a/drivers/media/dvb/ttpci/av7110_ipack.c b/drivers/media/dvb/ttpci/av7110_ipack.c
deleted file mode 100644
index 699ef8b5b99a..000000000000
--- a/drivers/media/dvb/ttpci/av7110_ipack.c
+++ /dev/null
@@ -1,403 +0,0 @@
1#include "dvb_filter.h"
2#include "av7110_ipack.h"
3#include <linux/string.h> /* for memcpy() */
4#include <linux/vmalloc.h>
5
6
7void av7110_ipack_reset(struct ipack *p)
8{
9 p->found = 0;
10 p->cid = 0;
11 p->plength = 0;
12 p->flag1 = 0;
13 p->flag2 = 0;
14 p->hlength = 0;
15 p->mpeg = 0;
16 p->check = 0;
17 p->which = 0;
18 p->done = 0;
19 p->count = 0;
20}
21
22
23int av7110_ipack_init(struct ipack *p, int size,
24 void (*func)(u8 *buf, int size, void *priv))
25{
26 if (!(p->buf = vmalloc(size*sizeof(u8)))) {
27 printk(KERN_WARNING "Couldn't allocate memory for ipack\n");
28 return -ENOMEM;
29 }
30 p->size = size;
31 p->func = func;
32 p->repack_subids = 0;
33 av7110_ipack_reset(p);
34 return 0;
35}
36
37
38void av7110_ipack_free(struct ipack *p)
39{
40 vfree(p->buf);
41}
42
43
44static void send_ipack(struct ipack *p)
45{
46 int off;
47 struct dvb_audio_info ai;
48 int ac3_off = 0;
49 int streamid = 0;
50 int nframes = 0;
51 int f = 0;
52
53 switch (p->mpeg) {
54 case 2:
55 if (p->count < 10)
56 return;
57 p->buf[3] = p->cid;
58 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
59 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
60 if (p->repack_subids && p->cid == PRIVATE_STREAM1) {
61 off = 9 + p->buf[8];
62 streamid = p->buf[off];
63 if ((streamid & 0xf8) == 0x80) {
64 ai.off = 0;
65 ac3_off = ((p->buf[off + 2] << 8)|
66 p->buf[off + 3]);
67 if (ac3_off < p->count)
68 f = dvb_filter_get_ac3info(p->buf + off + 3 + ac3_off,
69 p->count - ac3_off, &ai, 0);
70 if (!f) {
71 nframes = (p->count - off - 3 - ac3_off) /
72 ai.framesize + 1;
73 p->buf[off + 2] = (ac3_off >> 8) & 0xff;
74 p->buf[off + 3] = (ac3_off) & 0xff;
75 p->buf[off + 1] = nframes;
76 ac3_off += nframes * ai.framesize - p->count;
77 }
78 }
79 }
80 p->func(p->buf, p->count, p->data);
81
82 p->buf[6] = 0x80;
83 p->buf[7] = 0x00;
84 p->buf[8] = 0x00;
85 p->count = 9;
86 if (p->repack_subids && p->cid == PRIVATE_STREAM1
87 && (streamid & 0xf8) == 0x80) {
88 p->count += 4;
89 p->buf[9] = streamid;
90 p->buf[10] = (ac3_off >> 8) & 0xff;
91 p->buf[11] = (ac3_off) & 0xff;
92 p->buf[12] = 0;
93 }
94 break;
95
96 case 1:
97 if (p->count < 8)
98 return;
99 p->buf[3] = p->cid;
100 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
101 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
102 p->func(p->buf, p->count, p->data);
103
104 p->buf[6] = 0x0f;
105 p->count = 7;
106 break;
107 }
108}
109
110
111void av7110_ipack_flush(struct ipack *p)
112{
113 if (p->plength != MMAX_PLENGTH - 6 || p->found <= 6)
114 return;
115 p->plength = p->found - 6;
116 p->found = 0;
117 send_ipack(p);
118 av7110_ipack_reset(p);
119}
120
121
122static void write_ipack(struct ipack *p, const u8 *data, int count)
123{
124 u8 headr[3] = { 0x00, 0x00, 0x01 };
125
126 if (p->count < 6) {
127 memcpy(p->buf, headr, 3);
128 p->count = 6;
129 }
130
131 if (p->count + count < p->size){
132 memcpy(p->buf+p->count, data, count);
133 p->count += count;
134 } else {
135 int rest = p->size - p->count;
136 memcpy(p->buf+p->count, data, rest);
137 p->count += rest;
138 send_ipack(p);
139 if (count - rest > 0)
140 write_ipack(p, data + rest, count - rest);
141 }
142}
143
144
145int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
146{
147 int l;
148 int c = 0;
149
150 while (c < count && (p->mpeg == 0 ||
151 (p->mpeg == 1 && p->found < 7) ||
152 (p->mpeg == 2 && p->found < 9))
153 && (p->found < 5 || !p->done)) {
154 switch (p->found) {
155 case 0:
156 case 1:
157 if (buf[c] == 0x00)
158 p->found++;
159 else
160 p->found = 0;
161 c++;
162 break;
163 case 2:
164 if (buf[c] == 0x01)
165 p->found++;
166 else if (buf[c] == 0)
167 p->found = 2;
168 else
169 p->found = 0;
170 c++;
171 break;
172 case 3:
173 p->cid = 0;
174 switch (buf[c]) {
175 case PROG_STREAM_MAP:
176 case PRIVATE_STREAM2:
177 case PROG_STREAM_DIR:
178 case ECM_STREAM :
179 case EMM_STREAM :
180 case PADDING_STREAM :
181 case DSM_CC_STREAM :
182 case ISO13522_STREAM:
183 p->done = 1;
184 /* fall through */
185 case PRIVATE_STREAM1:
186 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
187 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
188 p->found++;
189 p->cid = buf[c];
190 c++;
191 break;
192 default:
193 p->found = 0;
194 break;
195 }
196 break;
197
198 case 4:
199 if (count-c > 1) {
200 p->plen[0] = buf[c];
201 c++;
202 p->plen[1] = buf[c];
203 c++;
204 p->found += 2;
205 p->plength = (p->plen[0] << 8) | p->plen[1];
206 } else {
207 p->plen[0] = buf[c];
208 p->found++;
209 return count;
210 }
211 break;
212 case 5:
213 p->plen[1] = buf[c];
214 c++;
215 p->found++;
216 p->plength = (p->plen[0] << 8) | p->plen[1];
217 break;
218 case 6:
219 if (!p->done) {
220 p->flag1 = buf[c];
221 c++;
222 p->found++;
223 if ((p->flag1 & 0xc0) == 0x80)
224 p->mpeg = 2;
225 else {
226 p->hlength = 0;
227 p->which = 0;
228 p->mpeg = 1;
229 p->flag2 = 0;
230 }
231 }
232 break;
233
234 case 7:
235 if (!p->done && p->mpeg == 2) {
236 p->flag2 = buf[c];
237 c++;
238 p->found++;
239 }
240 break;
241
242 case 8:
243 if (!p->done && p->mpeg == 2) {
244 p->hlength = buf[c];
245 c++;
246 p->found++;
247 }
248 break;
249 }
250 }
251
252 if (c == count)
253 return count;
254
255 if (!p->plength)
256 p->plength = MMAX_PLENGTH - 6;
257
258 if (p->done || ((p->mpeg == 2 && p->found >= 9) ||
259 (p->mpeg == 1 && p->found >= 7))) {
260 switch (p->cid) {
261 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
262 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
263 case PRIVATE_STREAM1:
264 if (p->mpeg == 2 && p->found == 9) {
265 write_ipack(p, &p->flag1, 1);
266 write_ipack(p, &p->flag2, 1);
267 write_ipack(p, &p->hlength, 1);
268 }
269
270 if (p->mpeg == 1 && p->found == 7)
271 write_ipack(p, &p->flag1, 1);
272
273 if (p->mpeg == 2 && (p->flag2 & PTS_ONLY) &&
274 p->found < 14) {
275 while (c < count && p->found < 14) {
276 p->pts[p->found - 9] = buf[c];
277 write_ipack(p, buf + c, 1);
278 c++;
279 p->found++;
280 }
281 if (c == count)
282 return count;
283 }
284
285 if (p->mpeg == 1 && p->which < 2000) {
286
287 if (p->found == 7) {
288 p->check = p->flag1;
289 p->hlength = 1;
290 }
291
292 while (!p->which && c < count &&
293 p->check == 0xff){
294 p->check = buf[c];
295 write_ipack(p, buf + c, 1);
296 c++;
297 p->found++;
298 p->hlength++;
299 }
300
301 if (c == count)
302 return count;
303
304 if ((p->check & 0xc0) == 0x40 && !p->which) {
305 p->check = buf[c];
306 write_ipack(p, buf + c, 1);
307 c++;
308 p->found++;
309 p->hlength++;
310
311 p->which = 1;
312 if (c == count)
313 return count;
314 p->check = buf[c];
315 write_ipack(p, buf + c, 1);
316 c++;
317 p->found++;
318 p->hlength++;
319 p->which = 2;
320 if (c == count)
321 return count;
322 }
323
324 if (p->which == 1) {
325 p->check = buf[c];
326 write_ipack(p, buf + c, 1);
327 c++;
328 p->found++;
329 p->hlength++;
330 p->which = 2;
331 if (c == count)
332 return count;
333 }
334
335 if ((p->check & 0x30) && p->check != 0xff) {
336 p->flag2 = (p->check & 0xf0) << 2;
337 p->pts[0] = p->check;
338 p->which = 3;
339 }
340
341 if (c == count)
342 return count;
343 if (p->which > 2){
344 if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
345 while (c < count && p->which < 7) {
346 p->pts[p->which - 2] = buf[c];
347 write_ipack(p, buf + c, 1);
348 c++;
349 p->found++;
350 p->which++;
351 p->hlength++;
352 }
353 if (c == count)
354 return count;
355 } else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
356 while (c < count && p->which < 12) {
357 if (p->which < 7)
358 p->pts[p->which - 2] = buf[c];
359 write_ipack(p, buf + c, 1);
360 c++;
361 p->found++;
362 p->which++;
363 p->hlength++;
364 }
365 if (c == count)
366 return count;
367 }
368 p->which = 2000;
369 }
370
371 }
372
373 while (c < count && p->found < p->plength + 6) {
374 l = count - c;
375 if (l + p->found > p->plength + 6)
376 l = p->plength + 6 - p->found;
377 write_ipack(p, buf + c, l);
378 p->found += l;
379 c += l;
380 }
381 break;
382 }
383
384
385 if (p->done) {
386 if (p->found + count - c < p->plength + 6) {
387 p->found += count - c;
388 c = count;
389 } else {
390 c += p->plength + 6 - p->found;
391 p->found = p->plength + 6;
392 }
393 }
394
395 if (p->plength && p->found == p->plength + 6) {
396 send_ipack(p);
397 av7110_ipack_reset(p);
398 if (c < count)
399 av7110_ipack_instant_repack(buf + c, count - c, p);
400 }
401 }
402 return count;
403}
diff --git a/drivers/media/dvb/ttpci/av7110_ipack.h b/drivers/media/dvb/ttpci/av7110_ipack.h
deleted file mode 100644
index becf94d3fdfa..000000000000
--- a/drivers/media/dvb/ttpci/av7110_ipack.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef _AV7110_IPACK_H_
2#define _AV7110_IPACK_H_
3
4extern int av7110_ipack_init(struct ipack *p, int size,
5 void (*func)(u8 *buf, int size, void *priv));
6
7extern void av7110_ipack_reset(struct ipack *p);
8extern int av7110_ipack_instant_repack(const u8 *buf, int count, struct ipack *p);
9extern void av7110_ipack_free(struct ipack * p);
10extern void av7110_ipack_flush(struct ipack *p);
11
12#endif
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
deleted file mode 100644
index 908f272fe26c..000000000000
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ /dev/null
@@ -1,415 +0,0 @@
1/*
2 * Driver for the remote control of SAA7146 based AV7110 cards
3 *
4 * Copyright (C) 1999-2003 Holger Waechtler <holger@convergence.de>
5 * Copyright (C) 2003-2007 Oliver Endriss <o.endriss@gmx.de>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
21 *
22 */
23
24
25#include <linux/types.h>
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/proc_fs.h>
29#include <linux/kernel.h>
30#include <linux/bitops.h>
31
32#include "av7110.h"
33#include "av7110_hw.h"
34
35
36#define AV_CNT 4
37
38#define IR_RC5 0
39#define IR_RCMM 1
40#define IR_RC5_EXT 2 /* internal only */
41
42#define IR_ALL 0xffffffff
43
44#define UP_TIMEOUT (HZ*7/25)
45
46
47/* Note: enable ir debugging by or'ing debug with 16 */
48
49static int ir_protocol[AV_CNT] = { IR_RCMM, IR_RCMM, IR_RCMM, IR_RCMM};
50module_param_array(ir_protocol, int, NULL, 0644);
51MODULE_PARM_DESC(ir_protocol, "Infrared protocol: 0 RC5, 1 RCMM (default)");
52
53static int ir_inversion[AV_CNT];
54module_param_array(ir_inversion, int, NULL, 0644);
55MODULE_PARM_DESC(ir_inversion, "Inversion of infrared signal: 0 not inverted (default), 1 inverted");
56
57static uint ir_device_mask[AV_CNT] = { IR_ALL, IR_ALL, IR_ALL, IR_ALL };
58module_param_array(ir_device_mask, uint, NULL, 0644);
59MODULE_PARM_DESC(ir_device_mask, "Bitmask of infrared devices: bit 0..31 = device 0..31 (default: all)");
60
61
62static int av_cnt;
63static struct av7110 *av_list[AV_CNT];
64
65static u16 default_key_map [256] = {
66 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
67 KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO,
68 KEY_VOLUMEUP, KEY_VOLUMEDOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 KEY_CHANNELUP, KEY_CHANNELDOWN, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, KEY_TEXT, 0, 0, KEY_TV, 0, 0, 0, 0, 0, KEY_SETUP, 0, 0,
72 0, 0, 0, KEY_SUBTITLE, 0, 0, KEY_LANGUAGE, 0,
73 KEY_RADIO, 0, 0, 0, 0, KEY_EXIT, 0, 0,
74 KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_OK, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RED, KEY_GREEN, KEY_YELLOW,
76 KEY_BLUE, 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_LIST, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, KEY_UP, KEY_UP, KEY_DOWN, KEY_DOWN,
82 0, 0, 0, 0, KEY_EPG, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_VCR
86};
87
88
89/* key-up timer */
90static void av7110_emit_keyup(unsigned long parm)
91{
92 struct infrared *ir = (struct infrared *) parm;
93
94 if (!ir || !test_bit(ir->last_key, ir->input_dev->key))
95 return;
96
97 input_report_key(ir->input_dev, ir->last_key, 0);
98 input_sync(ir->input_dev);
99}
100
101
102/* tasklet */
103static void av7110_emit_key(unsigned long parm)
104{
105 struct infrared *ir = (struct infrared *) parm;
106 u32 ircom = ir->ir_command;
107 u8 data;
108 u8 addr;
109 u16 toggle;
110 u16 keycode;
111
112 /* extract device address and data */
113 switch (ir->protocol) {
114 case IR_RC5: /* RC5: 5 bits device address, 6 bits data */
115 data = ircom & 0x3f;
116 addr = (ircom >> 6) & 0x1f;
117 toggle = ircom & 0x0800;
118 break;
119
120 case IR_RCMM: /* RCMM: ? bits device address, ? bits data */
121 data = ircom & 0xff;
122 addr = (ircom >> 8) & 0x1f;
123 toggle = ircom & 0x8000;
124 break;
125
126 case IR_RC5_EXT: /* extended RC5: 5 bits device address, 7 bits data */
127 data = ircom & 0x3f;
128 addr = (ircom >> 6) & 0x1f;
129 /* invert 7th data bit for backward compatibility with RC5 keymaps */
130 if (!(ircom & 0x1000))
131 data |= 0x40;
132 toggle = ircom & 0x0800;
133 break;
134
135 default:
136 printk("%s invalid protocol %x\n", __func__, ir->protocol);
137 return;
138 }
139
140 input_event(ir->input_dev, EV_MSC, MSC_RAW, (addr << 16) | data);
141 input_event(ir->input_dev, EV_MSC, MSC_SCAN, data);
142
143 keycode = ir->key_map[data];
144
145 dprintk(16, "%s: code %08x -> addr %i data 0x%02x -> keycode %i\n",
146 __func__, ircom, addr, data, keycode);
147
148 /* check device address */
149 if (!(ir->device_mask & (1 << addr)))
150 return;
151
152 if (!keycode) {
153 printk ("%s: code %08x -> addr %i data 0x%02x -> unknown key!\n",
154 __func__, ircom, addr, data);
155 return;
156 }
157
158 if (timer_pending(&ir->keyup_timer)) {
159 del_timer(&ir->keyup_timer);
160 if (ir->last_key != keycode || toggle != ir->last_toggle) {
161 ir->delay_timer_finished = 0;
162 input_event(ir->input_dev, EV_KEY, ir->last_key, 0);
163 input_event(ir->input_dev, EV_KEY, keycode, 1);
164 input_sync(ir->input_dev);
165 } else if (ir->delay_timer_finished) {
166 input_event(ir->input_dev, EV_KEY, keycode, 2);
167 input_sync(ir->input_dev);
168 }
169 } else {
170 ir->delay_timer_finished = 0;
171 input_event(ir->input_dev, EV_KEY, keycode, 1);
172 input_sync(ir->input_dev);
173 }
174
175 ir->last_key = keycode;
176 ir->last_toggle = toggle;
177
178 ir->keyup_timer.expires = jiffies + UP_TIMEOUT;
179 add_timer(&ir->keyup_timer);
180
181}
182
183
184/* register with input layer */
185static void input_register_keys(struct infrared *ir)
186{
187 int i;
188
189 set_bit(EV_KEY, ir->input_dev->evbit);
190 set_bit(EV_REP, ir->input_dev->evbit);
191 set_bit(EV_MSC, ir->input_dev->evbit);
192
193 set_bit(MSC_RAW, ir->input_dev->mscbit);
194 set_bit(MSC_SCAN, ir->input_dev->mscbit);
195
196 memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit));
197
198 for (i = 0; i < ARRAY_SIZE(ir->key_map); i++) {
199 if (ir->key_map[i] > KEY_MAX)
200 ir->key_map[i] = 0;
201 else if (ir->key_map[i] > KEY_RESERVED)
202 set_bit(ir->key_map[i], ir->input_dev->keybit);
203 }
204
205 ir->input_dev->keycode = ir->key_map;
206 ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
207 ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
208}
209
210
211/* called by the input driver after rep[REP_DELAY] ms */
212static void input_repeat_key(unsigned long parm)
213{
214 struct infrared *ir = (struct infrared *) parm;
215
216 ir->delay_timer_finished = 1;
217}
218
219
220/* check for configuration changes */
221int av7110_check_ir_config(struct av7110 *av7110, int force)
222{
223 int i;
224 int modified = force;
225 int ret = -ENODEV;
226
227 for (i = 0; i < av_cnt; i++)
228 if (av7110 == av_list[i])
229 break;
230
231 if (i < av_cnt && av7110) {
232 if ((av7110->ir.protocol & 1) != ir_protocol[i] ||
233 av7110->ir.inversion != ir_inversion[i])
234 modified = true;
235
236 if (modified) {
237 /* protocol */
238 if (ir_protocol[i]) {
239 ir_protocol[i] = 1;
240 av7110->ir.protocol = IR_RCMM;
241 av7110->ir.ir_config = 0x0001;
242 } else if (FW_VERSION(av7110->arm_app) >= 0x2620) {
243 av7110->ir.protocol = IR_RC5_EXT;
244 av7110->ir.ir_config = 0x0002;
245 } else {
246 av7110->ir.protocol = IR_RC5;
247 av7110->ir.ir_config = 0x0000;
248 }
249 /* inversion */
250 if (ir_inversion[i]) {
251 ir_inversion[i] = 1;
252 av7110->ir.ir_config |= 0x8000;
253 }
254 av7110->ir.inversion = ir_inversion[i];
255 /* update ARM */
256 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1,
257 av7110->ir.ir_config);
258 } else
259 ret = 0;
260
261 /* address */
262 if (av7110->ir.device_mask != ir_device_mask[i])
263 av7110->ir.device_mask = ir_device_mask[i];
264 }
265
266 return ret;
267}
268
269
270/* /proc/av7110_ir interface */
271static ssize_t av7110_ir_proc_write(struct file *file, const char __user *buffer,
272 size_t count, loff_t *pos)
273{
274 char *page;
275 u32 ir_config;
276 int size = sizeof ir_config + sizeof av_list[0]->ir.key_map;
277 int i;
278
279 if (count < size)
280 return -EINVAL;
281
282 page = vmalloc(size);
283 if (!page)
284 return -ENOMEM;
285
286 if (copy_from_user(page, buffer, size)) {
287 vfree(page);
288 return -EFAULT;
289 }
290
291 memcpy(&ir_config, page, sizeof ir_config);
292
293 for (i = 0; i < av_cnt; i++) {
294 /* keymap */
295 memcpy(av_list[i]->ir.key_map, page + sizeof ir_config,
296 sizeof(av_list[i]->ir.key_map));
297 /* protocol, inversion, address */
298 ir_protocol[i] = ir_config & 0x0001;
299 ir_inversion[i] = ir_config & 0x8000 ? 1 : 0;
300 if (ir_config & 0x4000)
301 ir_device_mask[i] = 1 << ((ir_config >> 16) & 0x1f);
302 else
303 ir_device_mask[i] = IR_ALL;
304 /* update configuration */
305 av7110_check_ir_config(av_list[i], false);
306 input_register_keys(&av_list[i]->ir);
307 }
308 vfree(page);
309 return count;
310}
311
312static const struct file_operations av7110_ir_proc_fops = {
313 .owner = THIS_MODULE,
314 .write = av7110_ir_proc_write,
315 .llseek = noop_llseek,
316};
317
318/* interrupt handler */
319static void ir_handler(struct av7110 *av7110, u32 ircom)
320{
321 dprintk(4, "ir command = %08x\n", ircom);
322 av7110->ir.ir_command = ircom;
323 tasklet_schedule(&av7110->ir.ir_tasklet);
324}
325
326
327int __devinit av7110_ir_init(struct av7110 *av7110)
328{
329 struct input_dev *input_dev;
330 static struct proc_dir_entry *e;
331 int err;
332
333 if (av_cnt >= ARRAY_SIZE(av_list))
334 return -ENOSPC;
335
336 av_list[av_cnt++] = av7110;
337 av7110_check_ir_config(av7110, true);
338
339 init_timer(&av7110->ir.keyup_timer);
340 av7110->ir.keyup_timer.function = av7110_emit_keyup;
341 av7110->ir.keyup_timer.data = (unsigned long) &av7110->ir;
342
343 input_dev = input_allocate_device();
344 if (!input_dev)
345 return -ENOMEM;
346
347 av7110->ir.input_dev = input_dev;
348 snprintf(av7110->ir.input_phys, sizeof(av7110->ir.input_phys),
349 "pci-%s/ir0", pci_name(av7110->dev->pci));
350
351 input_dev->name = "DVB on-card IR receiver";
352
353 input_dev->phys = av7110->ir.input_phys;
354 input_dev->id.bustype = BUS_PCI;
355 input_dev->id.version = 2;
356 if (av7110->dev->pci->subsystem_vendor) {
357 input_dev->id.vendor = av7110->dev->pci->subsystem_vendor;
358 input_dev->id.product = av7110->dev->pci->subsystem_device;
359 } else {
360 input_dev->id.vendor = av7110->dev->pci->vendor;
361 input_dev->id.product = av7110->dev->pci->device;
362 }
363 input_dev->dev.parent = &av7110->dev->pci->dev;
364 /* initial keymap */
365 memcpy(av7110->ir.key_map, default_key_map, sizeof av7110->ir.key_map);
366 input_register_keys(&av7110->ir);
367 err = input_register_device(input_dev);
368 if (err) {
369 input_free_device(input_dev);
370 return err;
371 }
372 input_dev->timer.function = input_repeat_key;
373 input_dev->timer.data = (unsigned long) &av7110->ir;
374
375 if (av_cnt == 1) {
376 e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops);
377 if (e)
378 e->size = 4 + 256 * sizeof(u16);
379 }
380
381 tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir);
382 av7110->ir.ir_handler = ir_handler;
383
384 return 0;
385}
386
387
388void __devexit av7110_ir_exit(struct av7110 *av7110)
389{
390 int i;
391
392 if (av_cnt == 0)
393 return;
394
395 del_timer_sync(&av7110->ir.keyup_timer);
396 av7110->ir.ir_handler = NULL;
397 tasklet_kill(&av7110->ir.ir_tasklet);
398
399 for (i = 0; i < av_cnt; i++)
400 if (av_list[i] == av7110) {
401 av_list[i] = av_list[av_cnt-1];
402 av_list[av_cnt-1] = NULL;
403 break;
404 }
405
406 if (av_cnt == 1)
407 remove_proc_entry("av7110_ir", NULL);
408
409 input_unregister_device(av7110->ir.input_dev);
410
411 av_cnt--;
412}
413
414//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>, Oliver Endriss <o.endriss@gmx.de>");
415//MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
deleted file mode 100644
index 1b2d15140a1d..000000000000
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ /dev/null
@@ -1,966 +0,0 @@
1/*
2 * av7110_v4l.c: av7110 video4linux interface for DVB and Siemens DVB-C analog module
3 *
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
6 *
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 *
25 * the project's page is at http://www.linuxtv.org/
26 */
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/delay.h>
33#include <linux/fs.h>
34#include <linux/timer.h>
35#include <linux/poll.h>
36
37#include "av7110.h"
38#include "av7110_hw.h"
39#include "av7110_av.h"
40
41int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val)
42{
43 u8 msg[5] = { dev, reg >> 8, reg & 0xff, val >> 8 , val & 0xff };
44 struct i2c_msg msgs = { .flags = 0, .len = 5, .buf = msg };
45
46 switch (av7110->adac_type) {
47 case DVB_ADAC_MSP34x0:
48 msgs.addr = 0x40;
49 break;
50 case DVB_ADAC_MSP34x5:
51 msgs.addr = 0x42;
52 break;
53 default:
54 return 0;
55 }
56
57 if (i2c_transfer(&av7110->i2c_adap, &msgs, 1) != 1) {
58 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
59 av7110->dvb_adapter.num, reg, val);
60 return -EIO;
61 }
62 return 0;
63}
64
65static int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
66{
67 u8 msg1[3] = { dev, reg >> 8, reg & 0xff };
68 u8 msg2[2];
69 struct i2c_msg msgs[2] = {
70 { .flags = 0 , .len = 3, .buf = msg1 },
71 { .flags = I2C_M_RD, .len = 2, .buf = msg2 }
72 };
73
74 switch (av7110->adac_type) {
75 case DVB_ADAC_MSP34x0:
76 msgs[0].addr = 0x40;
77 msgs[1].addr = 0x40;
78 break;
79 case DVB_ADAC_MSP34x5:
80 msgs[0].addr = 0x42;
81 msgs[1].addr = 0x42;
82 break;
83 default:
84 return 0;
85 }
86
87 if (i2c_transfer(&av7110->i2c_adap, &msgs[0], 2) != 2) {
88 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
89 av7110->dvb_adapter.num, reg);
90 return -EIO;
91 }
92 *val = (msg2[0] << 8) | msg2[1];
93 return 0;
94}
95
96static struct v4l2_input inputs[4] = {
97 {
98 .index = 0,
99 .name = "DVB",
100 .type = V4L2_INPUT_TYPE_CAMERA,
101 .audioset = 1,
102 .tuner = 0, /* ignored */
103 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
104 .status = 0,
105 .capabilities = V4L2_IN_CAP_STD,
106 }, {
107 .index = 1,
108 .name = "Television",
109 .type = V4L2_INPUT_TYPE_TUNER,
110 .audioset = 1,
111 .tuner = 0,
112 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
113 .status = 0,
114 .capabilities = V4L2_IN_CAP_STD,
115 }, {
116 .index = 2,
117 .name = "Video",
118 .type = V4L2_INPUT_TYPE_CAMERA,
119 .audioset = 0,
120 .tuner = 0,
121 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
122 .status = 0,
123 .capabilities = V4L2_IN_CAP_STD,
124 }, {
125 .index = 3,
126 .name = "Y/C",
127 .type = V4L2_INPUT_TYPE_CAMERA,
128 .audioset = 0,
129 .tuner = 0,
130 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
131 .status = 0,
132 .capabilities = V4L2_IN_CAP_STD,
133 }
134};
135
136static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
137{
138 struct av7110 *av7110 = dev->ext_priv;
139 u8 buf[] = { 0x00, reg, data };
140 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 };
141
142 dprintk(4, "dev: %p\n", dev);
143
144 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
145 return -1;
146 return 0;
147}
148
149static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
150{
151 struct av7110 *av7110 = dev->ext_priv;
152 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
153
154 dprintk(4, "dev: %p\n", dev);
155
156 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
157 return -1;
158 return 0;
159}
160
161static int ves1820_set_tv_freq(struct saa7146_dev *dev, u32 freq)
162{
163 u32 div;
164 u8 config;
165 u8 buf[4];
166
167 dprintk(4, "freq: 0x%08x\n", freq);
168
169 /* magic number: 614. tuning with the frequency given by v4l2
170 is always off by 614*62.5 = 38375 kHz...*/
171 div = freq + 614;
172
173 buf[0] = (div >> 8) & 0x7f;
174 buf[1] = div & 0xff;
175 buf[2] = 0x8e;
176
177 if (freq < (u32) (16 * 168.25))
178 config = 0xa0;
179 else if (freq < (u32) (16 * 447.25))
180 config = 0x90;
181 else
182 config = 0x30;
183 config &= ~0x02;
184
185 buf[3] = config;
186
187 return tuner_write(dev, 0x61, buf);
188}
189
190static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
191{
192 struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
193 u32 div;
194 u8 data[4];
195
196 div = (freq + 38900000 + 31250) / 62500;
197
198 data[0] = (div >> 8) & 0x7f;
199 data[1] = div & 0xff;
200 data[2] = 0xce;
201
202 if (freq < 45000000)
203 return -EINVAL;
204 else if (freq < 137000000)
205 data[3] = 0x01;
206 else if (freq < 403000000)
207 data[3] = 0x02;
208 else if (freq < 860000000)
209 data[3] = 0x04;
210 else
211 return -EINVAL;
212
213 if (av7110->fe->ops.i2c_gate_ctrl)
214 av7110->fe->ops.i2c_gate_ctrl(av7110->fe, 1);
215 return tuner_write(dev, 0x63, data);
216}
217
218
219
220static struct saa7146_standard analog_standard[];
221static struct saa7146_standard dvb_standard[];
222static struct saa7146_standard standard[];
223
224static struct v4l2_audio msp3400_v4l2_audio = {
225 .index = 0,
226 .name = "Television",
227 .capability = V4L2_AUDCAP_STEREO
228};
229
230static int av7110_dvb_c_switch(struct saa7146_fh *fh)
231{
232 struct saa7146_dev *dev = fh->dev;
233 struct saa7146_vv *vv = dev->vv_data;
234 struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
235 u16 adswitch;
236 int source, sync, err;
237
238 dprintk(4, "%p\n", av7110);
239
240 if ((vv->video_status & STATUS_OVERLAY) != 0) {
241 vv->ov_suspend = vv->video_fh;
242 err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
243 if (err != 0) {
244 dprintk(2, "suspending video failed\n");
245 vv->ov_suspend = NULL;
246 }
247 }
248
249 if (0 != av7110->current_input) {
250 dprintk(1, "switching to analog TV:\n");
251 adswitch = 1;
252 source = SAA7146_HPS_SOURCE_PORT_B;
253 sync = SAA7146_HPS_SYNC_PORT_B;
254 memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2);
255
256 switch (av7110->current_input) {
257 case 1:
258 dprintk(1, "switching SAA7113 to Analog Tuner Input\n");
259 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
260 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
261 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
262 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
263 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
264 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
265
266 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
267 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
268 dprintk(1, "setting band in demodulator failed\n");
269 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
270 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9819 pin9(STD)
271 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9819 pin30(VIF)
272 }
273 if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1)
274 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
275 break;
276 case 2:
277 dprintk(1, "switching SAA7113 to Video AV CVBS Input\n");
278 if (i2c_writereg(av7110, 0x48, 0x02, 0xd2) != 1)
279 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
280 break;
281 case 3:
282 dprintk(1, "switching SAA7113 to Video AV Y/C Input\n");
283 if (i2c_writereg(av7110, 0x48, 0x02, 0xd9) != 1)
284 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
285 break;
286 default:
287 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input\n");
288 }
289 } else {
290 adswitch = 0;
291 source = SAA7146_HPS_SOURCE_PORT_A;
292 sync = SAA7146_HPS_SYNC_PORT_A;
293 memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
294 dprintk(1, "switching DVB mode\n");
295 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
296 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
297 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
298 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
299 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
300 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
301
302 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
303 if (ves1820_writereg(dev, 0x09, 0x0f, 0x20))
304 dprintk(1, "setting band in demodulator failed\n");
305 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
306 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
307 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
308 }
309 }
310
311 /* hmm, this does not do anything!? */
312 if (av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, adswitch))
313 dprintk(1, "ADSwitch error\n");
314
315 saa7146_set_hps_source_and_sync(dev, source, sync);
316
317 if (vv->ov_suspend != NULL) {
318 saa7146_start_preview(vv->ov_suspend);
319 vv->ov_suspend = NULL;
320 }
321
322 return 0;
323}
324
325static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
326{
327 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
328 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
329 u16 stereo_det;
330 s8 stereo;
331
332 dprintk(2, "VIDIOC_G_TUNER: %d\n", t->index);
333
334 if (!av7110->analog_tuner_flags || t->index != 0)
335 return -EINVAL;
336
337 memset(t, 0, sizeof(*t));
338 strcpy((char *)t->name, "Television");
339
340 t->type = V4L2_TUNER_ANALOG_TV;
341 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
342 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
343 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
344 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
345 /* FIXME: add the real signal strength here */
346 t->signal = 0xffff;
347 t->afc = 0;
348
349 /* FIXME: standard / stereo detection is still broken */
350 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
351 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);
352 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
353 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);
354 stereo = (s8)(stereo_det >> 8);
355 if (stereo > 0x10) {
356 /* stereo */
357 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
358 t->audmode = V4L2_TUNER_MODE_STEREO;
359 } else if (stereo < -0x10) {
360 /* bilingual */
361 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
362 t->audmode = V4L2_TUNER_MODE_LANG1;
363 } else /* mono */
364 t->rxsubchans = V4L2_TUNER_SUB_MONO;
365
366 return 0;
367}
368
369static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
370{
371 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
372 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
373 u16 fm_matrix, src;
374 dprintk(2, "VIDIOC_S_TUNER: %d\n", t->index);
375
376 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
377 return -EINVAL;
378
379 switch (t->audmode) {
380 case V4L2_TUNER_MODE_STEREO:
381 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
382 fm_matrix = 0x3001; /* stereo */
383 src = 0x0020;
384 break;
385 case V4L2_TUNER_MODE_LANG1_LANG2:
386 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
387 fm_matrix = 0x3000; /* bilingual */
388 src = 0x0020;
389 break;
390 case V4L2_TUNER_MODE_LANG1:
391 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
392 fm_matrix = 0x3000; /* mono */
393 src = 0x0000;
394 break;
395 case V4L2_TUNER_MODE_LANG2:
396 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
397 fm_matrix = 0x3000; /* mono */
398 src = 0x0010;
399 break;
400 default: /* case V4L2_TUNER_MODE_MONO: */
401 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
402 fm_matrix = 0x3000; /* mono */
403 src = 0x0030;
404 break;
405 }
406 msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);
407 msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);
408 msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);
409 msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);
410 return 0;
411}
412
413static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
414{
415 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
416 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
417
418 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x\n", f->frequency);
419
420 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
421 return -EINVAL;
422
423 memset(f, 0, sizeof(*f));
424 f->type = V4L2_TUNER_ANALOG_TV;
425 f->frequency = av7110->current_freq;
426 return 0;
427}
428
429static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
430{
431 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
432 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
433
434 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x\n", f->frequency);
435
436 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
437 return -EINVAL;
438
439 if (V4L2_TUNER_ANALOG_TV != f->type)
440 return -EINVAL;
441
442 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); /* fast mute */
443 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0);
444
445 /* tune in desired frequency */
446 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820)
447 ves1820_set_tv_freq(dev, f->frequency);
448 else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297)
449 stv0297_set_tv_freq(dev, f->frequency);
450 av7110->current_freq = f->frequency;
451
452 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); /* start stereo detection */
453 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000);
454 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); /* loudspeaker + headphone */
455 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); /* SCART 1 volume */
456 return 0;
457}
458
459static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
460{
461 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
462 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
463
464 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index);
465
466 if (av7110->analog_tuner_flags) {
467 if (i->index >= 4)
468 return -EINVAL;
469 } else {
470 if (i->index != 0)
471 return -EINVAL;
472 }
473
474 memcpy(i, &inputs[i->index], sizeof(struct v4l2_input));
475
476 return 0;
477}
478
479static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
480{
481 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
482 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
483
484 *input = av7110->current_input;
485 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input);
486 return 0;
487}
488
489static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
490{
491 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
492 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
493
494 dprintk(2, "VIDIOC_S_INPUT: %d\n", input);
495
496 if (!av7110->analog_tuner_flags)
497 return input ? -EINVAL : 0;
498
499 if (input >= 4)
500 return -EINVAL;
501
502 av7110->current_input = input;
503 return av7110_dvb_c_switch(fh);
504}
505
506static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
507{
508 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a->index);
509 if (a->index != 0)
510 return -EINVAL;
511 *a = msp3400_v4l2_audio;
512 return 0;
513}
514
515static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
516{
517 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
518 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
519
520 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a->index);
521 if (a->index != 0)
522 return -EINVAL;
523 if (av7110->current_input >= 2)
524 return -EINVAL;
525 *a = msp3400_v4l2_audio;
526 return 0;
527}
528
529static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
530{
531 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
532 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
533
534 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a->index);
535 if (av7110->current_input >= 2)
536 return -EINVAL;
537 return a->index ? -EINVAL : 0;
538}
539
540static int vidioc_g_sliced_vbi_cap(struct file *file, void *fh,
541 struct v4l2_sliced_vbi_cap *cap)
542{
543 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
544 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
545
546 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
547 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
548 return -EINVAL;
549 if (FW_VERSION(av7110->arm_app) >= 0x2623) {
550 cap->service_set = V4L2_SLICED_WSS_625;
551 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
552 }
553 return 0;
554}
555
556static int vidioc_g_fmt_sliced_vbi_out(struct file *file, void *fh,
557 struct v4l2_format *f)
558{
559 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
560 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
561
562 dprintk(2, "VIDIOC_G_FMT:\n");
563 if (FW_VERSION(av7110->arm_app) < 0x2623)
564 return -EINVAL;
565 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced);
566 if (av7110->wssMode) {
567 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
568 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
569 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
570 }
571 return 0;
572}
573
574static int vidioc_s_fmt_sliced_vbi_out(struct file *file, void *fh,
575 struct v4l2_format *f)
576{
577 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
578 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
579
580 dprintk(2, "VIDIOC_S_FMT\n");
581 if (FW_VERSION(av7110->arm_app) < 0x2623)
582 return -EINVAL;
583 if (f->fmt.sliced.service_set != V4L2_SLICED_WSS_625 &&
584 f->fmt.sliced.service_lines[0][23] != V4L2_SLICED_WSS_625) {
585 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
586 /* WSS controlled by firmware */
587 av7110->wssMode = 0;
588 av7110->wssData = 0;
589 return av7110_fw_cmd(av7110, COMTYPE_ENCODER,
590 SetWSSConfig, 1, 0);
591 } else {
592 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
593 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
594 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
595 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
596 /* WSS controlled by userspace */
597 av7110->wssMode = 1;
598 av7110->wssData = 0;
599 }
600 return 0;
601}
602
603static int av7110_vbi_reset(struct file *file)
604{
605 struct saa7146_fh *fh = file->private_data;
606 struct saa7146_dev *dev = fh->dev;
607 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
608
609 dprintk(2, "%s\n", __func__);
610 av7110->wssMode = 0;
611 av7110->wssData = 0;
612 if (FW_VERSION(av7110->arm_app) < 0x2623)
613 return 0;
614 else
615 return av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 1, 0);
616}
617
618static ssize_t av7110_vbi_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
619{
620 struct saa7146_fh *fh = file->private_data;
621 struct saa7146_dev *dev = fh->dev;
622 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
623 struct v4l2_sliced_vbi_data d;
624 int rc;
625
626 dprintk(2, "%s\n", __func__);
627 if (FW_VERSION(av7110->arm_app) < 0x2623 || !av7110->wssMode || count != sizeof d)
628 return -EINVAL;
629 if (copy_from_user(&d, data, count))
630 return -EFAULT;
631 if ((d.id != 0 && d.id != V4L2_SLICED_WSS_625) || d.field != 0 || d.line != 23)
632 return -EINVAL;
633 if (d.id)
634 av7110->wssData = ((d.data[1] << 8) & 0x3f00) | d.data[0];
635 else
636 av7110->wssData = 0x8000;
637 rc = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 1, av7110->wssData);
638 return (rc < 0) ? rc : count;
639}
640
641/****************************************************************************
642 * INITIALIZATION
643 ****************************************************************************/
644
645static u8 saa7113_init_regs[] = {
646 0x02, 0xd0,
647 0x03, 0x23,
648 0x04, 0x00,
649 0x05, 0x00,
650 0x06, 0xe9,
651 0x07, 0x0d,
652 0x08, 0x98,
653 0x09, 0x02,
654 0x0a, 0x80,
655 0x0b, 0x40,
656 0x0c, 0x40,
657 0x0d, 0x00,
658 0x0e, 0x01,
659 0x0f, 0x7c,
660 0x10, 0x48,
661 0x11, 0x0c,
662 0x12, 0x8b,
663 0x13, 0x1a,
664 0x14, 0x00,
665 0x15, 0x00,
666 0x16, 0x00,
667 0x17, 0x00,
668 0x18, 0x00,
669 0x19, 0x00,
670 0x1a, 0x00,
671 0x1b, 0x00,
672 0x1c, 0x00,
673 0x1d, 0x00,
674 0x1e, 0x00,
675
676 0x41, 0x77,
677 0x42, 0x77,
678 0x43, 0x77,
679 0x44, 0x77,
680 0x45, 0x77,
681 0x46, 0x77,
682 0x47, 0x77,
683 0x48, 0x77,
684 0x49, 0x77,
685 0x4a, 0x77,
686 0x4b, 0x77,
687 0x4c, 0x77,
688 0x4d, 0x77,
689 0x4e, 0x77,
690 0x4f, 0x77,
691 0x50, 0x77,
692 0x51, 0x77,
693 0x52, 0x77,
694 0x53, 0x77,
695 0x54, 0x77,
696 0x55, 0x77,
697 0x56, 0x77,
698 0x57, 0xff,
699
700 0xff
701};
702
703
704static struct saa7146_ext_vv av7110_vv_data_st;
705static struct saa7146_ext_vv av7110_vv_data_c;
706
707int av7110_init_analog_module(struct av7110 *av7110)
708{
709 u16 version1, version2;
710
711 if (i2c_writereg(av7110, 0x80, 0x0, 0x80) == 1 &&
712 i2c_writereg(av7110, 0x80, 0x0, 0) == 1) {
713 pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
714 av7110->dvb_adapter.num);
715 av7110->adac_type = DVB_ADAC_MSP34x0;
716 } else if (i2c_writereg(av7110, 0x84, 0x0, 0x80) == 1 &&
717 i2c_writereg(av7110, 0x84, 0x0, 0) == 1) {
718 pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
719 av7110->dvb_adapter.num);
720 av7110->adac_type = DVB_ADAC_MSP34x5;
721 } else
722 return -ENODEV;
723
724 msleep(100); // the probing above resets the msp...
725 msp_readreg(av7110, MSP_RD_DSP, 0x001e, &version1);
726 msp_readreg(av7110, MSP_RD_DSP, 0x001f, &version2);
727 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
728 av7110->dvb_adapter.num, version1, version2);
729 msp_writereg(av7110, MSP_WR_DSP, 0x0013, 0x0c00);
730 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
731 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
732 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
733 msp_writereg(av7110, MSP_WR_DSP, 0x0004, 0x7f00); // loudspeaker volume
734 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
735 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
736 msp_writereg(av7110, MSP_WR_DSP, 0x000d, 0x1900); // prescale SCART
737
738 if (i2c_writereg(av7110, 0x48, 0x01, 0x00)!=1) {
739 pr_info("saa7113 not accessible\n");
740 } else {
741 u8 *i = saa7113_init_regs;
742
743 if ((av7110->dev->pci->subsystem_vendor == 0x110a) && (av7110->dev->pci->subsystem_device == 0x0000)) {
744 /* Fujitsu/Siemens DVB-Cable */
745 av7110->analog_tuner_flags |= ANALOG_TUNER_VES1820;
746 } else if ((av7110->dev->pci->subsystem_vendor == 0x13c2) && (av7110->dev->pci->subsystem_device == 0x0002)) {
747 /* Hauppauge/TT DVB-C premium */
748 av7110->analog_tuner_flags |= ANALOG_TUNER_VES1820;
749 } else if ((av7110->dev->pci->subsystem_vendor == 0x13c2) && (av7110->dev->pci->subsystem_device == 0x000A)) {
750 /* Hauppauge/TT DVB-C premium */
751 av7110->analog_tuner_flags |= ANALOG_TUNER_STV0297;
752 }
753
754 /* setup for DVB by default */
755 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
756 if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20))
757 dprintk(1, "setting band in demodulator failed\n");
758 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
759 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
760 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
761 }
762
763 /* init the saa7113 */
764 while (*i != 0xff) {
765 if (i2c_writereg(av7110, 0x48, i[0], i[1]) != 1) {
766 dprintk(1, "saa7113 initialization failed @ card %d", av7110->dvb_adapter.num);
767 break;
768 }
769 i += 2;
770 }
771 /* setup msp for analog sound: B/G Dual-FM */
772 msp_writereg(av7110, MSP_WR_DEM, 0x00bb, 0x02d0); // AD_CV
773 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 3); // FIR1
774 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 18); // FIR1
775 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 27); // FIR1
776 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 48); // FIR1
777 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 66); // FIR1
778 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 72); // FIR1
779 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 4); // FIR2
780 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 64); // FIR2
781 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 0); // FIR2
782 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 3); // FIR2
783 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 18); // FIR2
784 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 27); // FIR2
785 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 48); // FIR2
786 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 66); // FIR2
787 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 72); // FIR2
788 msp_writereg(av7110, MSP_WR_DEM, 0x0083, 0xa000); // MODE_REG
789 msp_writereg(av7110, MSP_WR_DEM, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
790 msp_writereg(av7110, MSP_WR_DEM, 0x009b, 0x04fc); // DCO1_HI
791 msp_writereg(av7110, MSP_WR_DEM, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
792 msp_writereg(av7110, MSP_WR_DEM, 0x00ab, 0x04c6); // DCO2_HI
793 msp_writereg(av7110, MSP_WR_DEM, 0x0056, 0); // LOAD_REG 1/2
794 }
795
796 memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
797 /* set dd1 stream a & b */
798 saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
799 saa7146_write(av7110->dev, DD1_INIT, 0x03000700);
800 saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
801
802 return 0;
803}
804
805int av7110_init_v4l(struct av7110 *av7110)
806{
807 struct saa7146_dev* dev = av7110->dev;
808 struct saa7146_ext_vv *vv_data;
809 int ret;
810
811 /* special case DVB-C: these cards have an analog tuner
812 plus need some special handling, so we have separate
813 saa7146_ext_vv data for these... */
814 if (av7110->analog_tuner_flags)
815 vv_data = &av7110_vv_data_c;
816 else
817 vv_data = &av7110_vv_data_st;
818 ret = saa7146_vv_init(dev, vv_data);
819
820 if (ret) {
821 ERR("cannot init capture device. skipping\n");
822 return -ENODEV;
823 }
824 vv_data->vid_ops.vidioc_enum_input = vidioc_enum_input;
825 vv_data->vid_ops.vidioc_g_input = vidioc_g_input;
826 vv_data->vid_ops.vidioc_s_input = vidioc_s_input;
827 vv_data->vid_ops.vidioc_g_tuner = vidioc_g_tuner;
828 vv_data->vid_ops.vidioc_s_tuner = vidioc_s_tuner;
829 vv_data->vid_ops.vidioc_g_frequency = vidioc_g_frequency;
830 vv_data->vid_ops.vidioc_s_frequency = vidioc_s_frequency;
831 vv_data->vid_ops.vidioc_enumaudio = vidioc_enumaudio;
832 vv_data->vid_ops.vidioc_g_audio = vidioc_g_audio;
833 vv_data->vid_ops.vidioc_s_audio = vidioc_s_audio;
834 vv_data->vid_ops.vidioc_g_fmt_vbi_cap = NULL;
835
836 vv_data->vbi_ops.vidioc_g_tuner = vidioc_g_tuner;
837 vv_data->vbi_ops.vidioc_s_tuner = vidioc_s_tuner;
838 vv_data->vbi_ops.vidioc_g_frequency = vidioc_g_frequency;
839 vv_data->vbi_ops.vidioc_s_frequency = vidioc_s_frequency;
840 vv_data->vbi_ops.vidioc_g_fmt_vbi_cap = NULL;
841 vv_data->vbi_ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
842 vv_data->vbi_ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
843 vv_data->vbi_ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
844
845 if (FW_VERSION(av7110->arm_app) < 0x2623)
846 vv_data->capabilities &= ~V4L2_CAP_SLICED_VBI_OUTPUT;
847
848 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
849 ERR("cannot register capture device. skipping\n");
850 saa7146_vv_release(dev);
851 return -ENODEV;
852 }
853 if (FW_VERSION(av7110->arm_app) >= 0x2623) {
854 if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI))
855 ERR("cannot register vbi v4l2 device. skipping\n");
856 }
857 return 0;
858}
859
860int av7110_exit_v4l(struct av7110 *av7110)
861{
862 struct saa7146_dev* dev = av7110->dev;
863
864 saa7146_unregister_device(&av7110->v4l_dev, av7110->dev);
865 saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
866
867 saa7146_vv_release(dev);
868
869 return 0;
870}
871
872
873
874/* FIXME: these values are experimental values that look better than the
875 values from the latest "official" driver -- at least for me... (MiHu) */
876static struct saa7146_standard standard[] = {
877 {
878 .name = "PAL", .id = V4L2_STD_PAL_BG,
879 .v_offset = 0x15, .v_field = 288,
880 .h_offset = 0x48, .h_pixels = 708,
881 .v_max_out = 576, .h_max_out = 768,
882 }, {
883 .name = "NTSC", .id = V4L2_STD_NTSC,
884 .v_offset = 0x10, .v_field = 244,
885 .h_offset = 0x40, .h_pixels = 708,
886 .v_max_out = 480, .h_max_out = 640,
887 }
888};
889
890static struct saa7146_standard analog_standard[] = {
891 {
892 .name = "PAL", .id = V4L2_STD_PAL_BG,
893 .v_offset = 0x1b, .v_field = 288,
894 .h_offset = 0x08, .h_pixels = 708,
895 .v_max_out = 576, .h_max_out = 768,
896 }, {
897 .name = "NTSC", .id = V4L2_STD_NTSC,
898 .v_offset = 0x10, .v_field = 244,
899 .h_offset = 0x40, .h_pixels = 708,
900 .v_max_out = 480, .h_max_out = 640,
901 }
902};
903
904static struct saa7146_standard dvb_standard[] = {
905 {
906 .name = "PAL", .id = V4L2_STD_PAL_BG,
907 .v_offset = 0x14, .v_field = 288,
908 .h_offset = 0x48, .h_pixels = 708,
909 .v_max_out = 576, .h_max_out = 768,
910 }, {
911 .name = "NTSC", .id = V4L2_STD_NTSC,
912 .v_offset = 0x10, .v_field = 244,
913 .h_offset = 0x40, .h_pixels = 708,
914 .v_max_out = 480, .h_max_out = 640,
915 }
916};
917
918static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
919{
920 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
921
922 if (std->id & V4L2_STD_PAL) {
923 av7110->vidmode = AV7110_VIDEO_MODE_PAL;
924 av7110_set_vidmode(av7110, av7110->vidmode);
925 }
926 else if (std->id & V4L2_STD_NTSC) {
927 av7110->vidmode = AV7110_VIDEO_MODE_NTSC;
928 av7110_set_vidmode(av7110, av7110->vidmode);
929 }
930 else
931 return -1;
932
933 return 0;
934}
935
936
937static struct saa7146_ext_vv av7110_vv_data_st = {
938 .inputs = 1,
939 .audios = 1,
940 .capabilities = V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_AUDIO,
941 .flags = 0,
942
943 .stds = &standard[0],
944 .num_stds = ARRAY_SIZE(standard),
945 .std_callback = &std_callback,
946
947 .vbi_fops.open = av7110_vbi_reset,
948 .vbi_fops.release = av7110_vbi_reset,
949 .vbi_fops.write = av7110_vbi_write,
950};
951
952static struct saa7146_ext_vv av7110_vv_data_c = {
953 .inputs = 1,
954 .audios = 1,
955 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_AUDIO,
956 .flags = SAA7146_USE_PORT_B_FOR_VBI,
957
958 .stds = &standard[0],
959 .num_stds = ARRAY_SIZE(standard),
960 .std_callback = &std_callback,
961
962 .vbi_fops.open = av7110_vbi_reset,
963 .vbi_fops.release = av7110_vbi_reset,
964 .vbi_fops.write = av7110_vbi_write,
965};
966
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
deleted file mode 100644
index 12ddb53c58dc..000000000000
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ /dev/null
@@ -1,1640 +0,0 @@
1/*
2 * budget-av.c: driver for the SAA7146 based Budget DVB cards
3 * with analog video in
4 *
5 * Compiled from various sources by Michael Hunold <michael@mihu.de>
6 *
7 * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
8 * Andrew de Quincey <adq_dvb@lidskialf.net>
9 *
10 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
11 *
12 * Copyright (C) 1999-2002 Ralph Metzler
13 * & Marcus Metzler for convergence integrated media GmbH
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
31 *
32 *
33 * the project's page is at http://www.linuxtv.org/
34 */
35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
38#include "budget.h"
39#include "stv0299.h"
40#include "stb0899_drv.h"
41#include "stb0899_reg.h"
42#include "stb0899_cfg.h"
43#include "tda8261.h"
44#include "tda8261_cfg.h"
45#include "tda1002x.h"
46#include "tda1004x.h"
47#include "tua6100.h"
48#include "dvb-pll.h"
49#include <media/saa7146_vv.h>
50#include <linux/module.h>
51#include <linux/errno.h>
52#include <linux/slab.h>
53#include <linux/interrupt.h>
54#include <linux/input.h>
55#include <linux/spinlock.h>
56
57#include "dvb_ca_en50221.h"
58
59#define DEBICICAM 0x02420000
60
61#define SLOTSTATUS_NONE 1
62#define SLOTSTATUS_PRESENT 2
63#define SLOTSTATUS_RESET 4
64#define SLOTSTATUS_READY 8
65#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
66
67DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
68
69struct budget_av {
70 struct budget budget;
71 struct video_device *vd;
72 int cur_input;
73 int has_saa7113;
74 struct tasklet_struct ciintf_irq_tasklet;
75 int slot_status;
76 struct dvb_ca_en50221 ca;
77 u8 reinitialise_demod:1;
78};
79
80static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot);
81
82
83/* GPIO Connections:
84 * 0 - Vcc/Reset (Reset is controlled by capacitor). Resets the frontend *AS WELL*!
85 * 1 - CI memory select 0=>IO memory, 1=>Attribute Memory
86 * 2 - CI Card Enable (Active Low)
87 * 3 - CI Card Detect
88 */
89
90/****************************************************************************
91 * INITIALIZATION
92 ****************************************************************************/
93
94static u8 i2c_readreg(struct i2c_adapter *i2c, u8 id, u8 reg)
95{
96 u8 mm1[] = { 0x00 };
97 u8 mm2[] = { 0x00 };
98 struct i2c_msg msgs[2];
99
100 msgs[0].flags = 0;
101 msgs[1].flags = I2C_M_RD;
102 msgs[0].addr = msgs[1].addr = id / 2;
103 mm1[0] = reg;
104 msgs[0].len = 1;
105 msgs[1].len = 1;
106 msgs[0].buf = mm1;
107 msgs[1].buf = mm2;
108
109 i2c_transfer(i2c, msgs, 2);
110
111 return mm2[0];
112}
113
114static int i2c_readregs(struct i2c_adapter *i2c, u8 id, u8 reg, u8 * buf, u8 len)
115{
116 u8 mm1[] = { reg };
117 struct i2c_msg msgs[2] = {
118 {.addr = id / 2,.flags = 0,.buf = mm1,.len = 1},
119 {.addr = id / 2,.flags = I2C_M_RD,.buf = buf,.len = len}
120 };
121
122 if (i2c_transfer(i2c, msgs, 2) != 2)
123 return -EIO;
124
125 return 0;
126}
127
128static int i2c_writereg(struct i2c_adapter *i2c, u8 id, u8 reg, u8 val)
129{
130 u8 msg[2] = { reg, val };
131 struct i2c_msg msgs;
132
133 msgs.flags = 0;
134 msgs.addr = id / 2;
135 msgs.len = 2;
136 msgs.buf = msg;
137 return i2c_transfer(i2c, &msgs, 1);
138}
139
140static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
141{
142 struct budget_av *budget_av = (struct budget_av *) ca->data;
143 int result;
144
145 if (slot != 0)
146 return -EINVAL;
147
148 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI);
149 udelay(1);
150
151 result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 0xfff, 1, 0, 1);
152 if (result == -ETIMEDOUT) {
153 ciintf_slot_shutdown(ca, slot);
154 pr_info("cam ejected 1\n");
155 }
156 return result;
157}
158
159static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
160{
161 struct budget_av *budget_av = (struct budget_av *) ca->data;
162 int result;
163
164 if (slot != 0)
165 return -EINVAL;
166
167 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI);
168 udelay(1);
169
170 result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 0xfff, 1, value, 0, 1);
171 if (result == -ETIMEDOUT) {
172 ciintf_slot_shutdown(ca, slot);
173 pr_info("cam ejected 2\n");
174 }
175 return result;
176}
177
178static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
179{
180 struct budget_av *budget_av = (struct budget_av *) ca->data;
181 int result;
182
183 if (slot != 0)
184 return -EINVAL;
185
186 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO);
187 udelay(1);
188
189 result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 3, 1, 0, 0);
190 if (result == -ETIMEDOUT) {
191 ciintf_slot_shutdown(ca, slot);
192 pr_info("cam ejected 3\n");
193 return -ETIMEDOUT;
194 }
195 return result;
196}
197
198static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
199{
200 struct budget_av *budget_av = (struct budget_av *) ca->data;
201 int result;
202
203 if (slot != 0)
204 return -EINVAL;
205
206 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO);
207 udelay(1);
208
209 result = ttpci_budget_debiwrite(&budget_av->budget, DEBICICAM, address & 3, 1, value, 0, 0);
210 if (result == -ETIMEDOUT) {
211 ciintf_slot_shutdown(ca, slot);
212 pr_info("cam ejected 5\n");
213 }
214 return result;
215}
216
217static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
218{
219 struct budget_av *budget_av = (struct budget_av *) ca->data;
220 struct saa7146_dev *saa = budget_av->budget.dev;
221
222 if (slot != 0)
223 return -EINVAL;
224
225 dprintk(1, "ciintf_slot_reset\n");
226 budget_av->slot_status = SLOTSTATUS_RESET;
227
228 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTHI); /* disable card */
229
230 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI); /* Vcc off */
231 msleep(2);
232 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); /* Vcc on */
233 msleep(20); /* 20 ms Vcc settling time */
234
235 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO); /* enable card */
236 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
237 msleep(20);
238
239 /* reinitialise the frontend if necessary */
240 if (budget_av->reinitialise_demod)
241 dvb_frontend_reinitialise(budget_av->budget.dvb_frontend);
242
243 return 0;
244}
245
246static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
247{
248 struct budget_av *budget_av = (struct budget_av *) ca->data;
249 struct saa7146_dev *saa = budget_av->budget.dev;
250
251 if (slot != 0)
252 return -EINVAL;
253
254 dprintk(1, "ciintf_slot_shutdown\n");
255
256 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
257 budget_av->slot_status = SLOTSTATUS_NONE;
258
259 return 0;
260}
261
262static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
263{
264 struct budget_av *budget_av = (struct budget_av *) ca->data;
265 struct saa7146_dev *saa = budget_av->budget.dev;
266
267 if (slot != 0)
268 return -EINVAL;
269
270 dprintk(1, "ciintf_slot_ts_enable: %d\n", budget_av->slot_status);
271
272 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
273
274 return 0;
275}
276
277static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
278{
279 struct budget_av *budget_av = (struct budget_av *) ca->data;
280 struct saa7146_dev *saa = budget_av->budget.dev;
281 int result;
282
283 if (slot != 0)
284 return -EINVAL;
285
286 /* test the card detect line - needs to be done carefully
287 * since it never goes high for some CAMs on this interface (e.g. topuptv) */
288 if (budget_av->slot_status == SLOTSTATUS_NONE) {
289 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
290 udelay(1);
291 if (saa7146_read(saa, PSR) & MASK_06) {
292 if (budget_av->slot_status == SLOTSTATUS_NONE) {
293 budget_av->slot_status = SLOTSTATUS_PRESENT;
294 pr_info("cam inserted A\n");
295 }
296 }
297 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
298 }
299
300 /* We also try and read from IO memory to work round the above detection bug. If
301 * there is no CAM, we will get a timeout. Only done if there is no cam
302 * present, since this test actually breaks some cams :(
303 *
304 * if the CI interface is not open, we also do the above test since we
305 * don't care if the cam has problems - we'll be resetting it on open() anyway */
306 if ((budget_av->slot_status == SLOTSTATUS_NONE) || (!open)) {
307 saa7146_setgpio(budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO);
308 result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, 0, 1, 0, 1);
309 if ((result >= 0) && (budget_av->slot_status == SLOTSTATUS_NONE)) {
310 budget_av->slot_status = SLOTSTATUS_PRESENT;
311 pr_info("cam inserted B\n");
312 } else if (result < 0) {
313 if (budget_av->slot_status != SLOTSTATUS_NONE) {
314 ciintf_slot_shutdown(ca, slot);
315 pr_info("cam ejected 5\n");
316 return 0;
317 }
318 }
319 }
320
321 /* read from attribute memory in reset/ready state to know when the CAM is ready */
322 if (budget_av->slot_status == SLOTSTATUS_RESET) {
323 result = ciintf_read_attribute_mem(ca, slot, 0);
324 if (result == 0x1d) {
325 budget_av->slot_status = SLOTSTATUS_READY;
326 }
327 }
328
329 /* work out correct return code */
330 if (budget_av->slot_status != SLOTSTATUS_NONE) {
331 if (budget_av->slot_status & SLOTSTATUS_READY) {
332 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
333 }
334 return DVB_CA_EN50221_POLL_CAM_PRESENT;
335 }
336 return 0;
337}
338
339static int ciintf_init(struct budget_av *budget_av)
340{
341 struct saa7146_dev *saa = budget_av->budget.dev;
342 int result;
343
344 memset(&budget_av->ca, 0, sizeof(struct dvb_ca_en50221));
345
346 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
347 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
348 saa7146_setgpio(saa, 2, SAA7146_GPIO_OUTLO);
349 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
350
351 /* Enable DEBI pins */
352 saa7146_write(saa, MC1, MASK_27 | MASK_11);
353
354 /* register CI interface */
355 budget_av->ca.owner = THIS_MODULE;
356 budget_av->ca.read_attribute_mem = ciintf_read_attribute_mem;
357 budget_av->ca.write_attribute_mem = ciintf_write_attribute_mem;
358 budget_av->ca.read_cam_control = ciintf_read_cam_control;
359 budget_av->ca.write_cam_control = ciintf_write_cam_control;
360 budget_av->ca.slot_reset = ciintf_slot_reset;
361 budget_av->ca.slot_shutdown = ciintf_slot_shutdown;
362 budget_av->ca.slot_ts_enable = ciintf_slot_ts_enable;
363 budget_av->ca.poll_slot_status = ciintf_poll_slot_status;
364 budget_av->ca.data = budget_av;
365 budget_av->budget.ci_present = 1;
366 budget_av->slot_status = SLOTSTATUS_NONE;
367
368 if ((result = dvb_ca_en50221_init(&budget_av->budget.dvb_adapter,
369 &budget_av->ca, 0, 1)) != 0) {
370 pr_err("ci initialisation failed\n");
371 goto error;
372 }
373
374 pr_info("ci interface initialised\n");
375 return 0;
376
377error:
378 saa7146_write(saa, MC1, MASK_27);
379 return result;
380}
381
382static void ciintf_deinit(struct budget_av *budget_av)
383{
384 struct saa7146_dev *saa = budget_av->budget.dev;
385
386 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
387 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
388 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
389 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
390
391 /* release the CA device */
392 dvb_ca_en50221_release(&budget_av->ca);
393
394 /* disable DEBI pins */
395 saa7146_write(saa, MC1, MASK_27);
396}
397
398
399static const u8 saa7113_tab[] = {
400 0x01, 0x08,
401 0x02, 0xc0,
402 0x03, 0x33,
403 0x04, 0x00,
404 0x05, 0x00,
405 0x06, 0xeb,
406 0x07, 0xe0,
407 0x08, 0x28,
408 0x09, 0x00,
409 0x0a, 0x80,
410 0x0b, 0x47,
411 0x0c, 0x40,
412 0x0d, 0x00,
413 0x0e, 0x01,
414 0x0f, 0x44,
415
416 0x10, 0x08,
417 0x11, 0x0c,
418 0x12, 0x7b,
419 0x13, 0x00,
420 0x15, 0x00, 0x16, 0x00, 0x17, 0x00,
421
422 0x57, 0xff,
423 0x40, 0x82, 0x58, 0x00, 0x59, 0x54, 0x5a, 0x07,
424 0x5b, 0x83, 0x5e, 0x00,
425 0xff
426};
427
428static int saa7113_init(struct budget_av *budget_av)
429{
430 struct budget *budget = &budget_av->budget;
431 struct saa7146_dev *saa = budget->dev;
432 const u8 *data = saa7113_tab;
433
434 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTHI);
435 msleep(200);
436
437 if (i2c_writereg(&budget->i2c_adap, 0x4a, 0x01, 0x08) != 1) {
438 dprintk(1, "saa7113 not found on KNC card\n");
439 return -ENODEV;
440 }
441
442 dprintk(1, "saa7113 detected and initializing\n");
443
444 while (*data != 0xff) {
445 i2c_writereg(&budget->i2c_adap, 0x4a, *data, *(data + 1));
446 data += 2;
447 }
448
449 dprintk(1, "saa7113 status=%02x\n", i2c_readreg(&budget->i2c_adap, 0x4a, 0x1f));
450
451 return 0;
452}
453
454static int saa7113_setinput(struct budget_av *budget_av, int input)
455{
456 struct budget *budget = &budget_av->budget;
457
458 if (1 != budget_av->has_saa7113)
459 return -ENODEV;
460
461 if (input == 1) {
462 i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc7);
463 i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x80);
464 } else if (input == 0) {
465 i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc0);
466 i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x00);
467 } else
468 return -EINVAL;
469
470 budget_av->cur_input = input;
471 return 0;
472}
473
474
475static int philips_su1278_ty_ci_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
476{
477 u8 aclk = 0;
478 u8 bclk = 0;
479 u8 m1;
480
481 aclk = 0xb5;
482 if (srate < 2000000)
483 bclk = 0x86;
484 else if (srate < 5000000)
485 bclk = 0x89;
486 else if (srate < 15000000)
487 bclk = 0x8f;
488 else if (srate < 45000000)
489 bclk = 0x95;
490
491 m1 = 0x14;
492 if (srate < 4000000)
493 m1 = 0x10;
494
495 stv0299_writereg(fe, 0x13, aclk);
496 stv0299_writereg(fe, 0x14, bclk);
497 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
498 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
499 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
500 stv0299_writereg(fe, 0x0f, 0x80 | m1);
501
502 return 0;
503}
504
505static int philips_su1278_ty_ci_tuner_set_params(struct dvb_frontend *fe)
506{
507 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
508 u32 div;
509 u8 buf[4];
510 struct budget *budget = (struct budget *) fe->dvb->priv;
511 struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) };
512
513 if ((c->frequency < 950000) || (c->frequency > 2150000))
514 return -EINVAL;
515
516 div = (c->frequency + (125 - 1)) / 125; /* round correctly */
517 buf[0] = (div >> 8) & 0x7f;
518 buf[1] = div & 0xff;
519 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
520 buf[3] = 0x20;
521
522 if (c->symbol_rate < 4000000)
523 buf[3] |= 1;
524
525 if (c->frequency < 1250000)
526 buf[3] |= 0;
527 else if (c->frequency < 1550000)
528 buf[3] |= 0x40;
529 else if (c->frequency < 2050000)
530 buf[3] |= 0x80;
531 else if (c->frequency < 2150000)
532 buf[3] |= 0xC0;
533
534 if (fe->ops.i2c_gate_ctrl)
535 fe->ops.i2c_gate_ctrl(fe, 1);
536 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
537 return -EIO;
538 return 0;
539}
540
541static u8 typhoon_cinergy1200s_inittab[] = {
542 0x01, 0x15,
543 0x02, 0x30,
544 0x03, 0x00,
545 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
546 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
547 0x06, 0x40, /* DAC not used, set to high impendance mode */
548 0x07, 0x00, /* DAC LSB */
549 0x08, 0x40, /* DiSEqC off */
550 0x09, 0x00, /* FIFO */
551 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
552 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
553 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
554 0x10, 0x3f, // AGC2 0x3d
555 0x11, 0x84,
556 0x12, 0xb9,
557 0x15, 0xc9, // lock detector threshold
558 0x16, 0x00,
559 0x17, 0x00,
560 0x18, 0x00,
561 0x19, 0x00,
562 0x1a, 0x00,
563 0x1f, 0x50,
564 0x20, 0x00,
565 0x21, 0x00,
566 0x22, 0x00,
567 0x23, 0x00,
568 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
569 0x29, 0x1e, // 1/2 threshold
570 0x2a, 0x14, // 2/3 threshold
571 0x2b, 0x0f, // 3/4 threshold
572 0x2c, 0x09, // 5/6 threshold
573 0x2d, 0x05, // 7/8 threshold
574 0x2e, 0x01,
575 0x31, 0x1f, // test all FECs
576 0x32, 0x19, // viterbi and synchro search
577 0x33, 0xfc, // rs control
578 0x34, 0x93, // error control
579 0x0f, 0x92,
580 0xff, 0xff
581};
582
583static struct stv0299_config typhoon_config = {
584 .demod_address = 0x68,
585 .inittab = typhoon_cinergy1200s_inittab,
586 .mclk = 88000000UL,
587 .invert = 0,
588 .skip_reinit = 0,
589 .lock_output = STV0299_LOCKOUTPUT_1,
590 .volt13_op0_op1 = STV0299_VOLT13_OP0,
591 .min_delay_ms = 100,
592 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
593};
594
595
596static struct stv0299_config cinergy_1200s_config = {
597 .demod_address = 0x68,
598 .inittab = typhoon_cinergy1200s_inittab,
599 .mclk = 88000000UL,
600 .invert = 0,
601 .skip_reinit = 0,
602 .lock_output = STV0299_LOCKOUTPUT_0,
603 .volt13_op0_op1 = STV0299_VOLT13_OP0,
604 .min_delay_ms = 100,
605 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
606};
607
608static struct stv0299_config cinergy_1200s_1894_0010_config = {
609 .demod_address = 0x68,
610 .inittab = typhoon_cinergy1200s_inittab,
611 .mclk = 88000000UL,
612 .invert = 1,
613 .skip_reinit = 0,
614 .lock_output = STV0299_LOCKOUTPUT_1,
615 .volt13_op0_op1 = STV0299_VOLT13_OP0,
616 .min_delay_ms = 100,
617 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
618};
619
620static int philips_cu1216_tuner_set_params(struct dvb_frontend *fe)
621{
622 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
623 struct budget *budget = (struct budget *) fe->dvb->priv;
624 u8 buf[6];
625 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
626 int i;
627
628#define CU1216_IF 36125000
629#define TUNER_MUL 62500
630
631 u32 div = (c->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
632
633 buf[0] = (div >> 8) & 0x7f;
634 buf[1] = div & 0xff;
635 buf[2] = 0xce;
636 buf[3] = (c->frequency < 150000000 ? 0x01 :
637 c->frequency < 445000000 ? 0x02 : 0x04);
638 buf[4] = 0xde;
639 buf[5] = 0x20;
640
641 if (fe->ops.i2c_gate_ctrl)
642 fe->ops.i2c_gate_ctrl(fe, 1);
643 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
644 return -EIO;
645
646 /* wait for the pll lock */
647 msg.flags = I2C_M_RD;
648 msg.len = 1;
649 for (i = 0; i < 20; i++) {
650 if (fe->ops.i2c_gate_ctrl)
651 fe->ops.i2c_gate_ctrl(fe, 1);
652 if (i2c_transfer(&budget->i2c_adap, &msg, 1) == 1 && (buf[0] & 0x40))
653 break;
654 msleep(10);
655 }
656
657 /* switch the charge pump to the lower current */
658 msg.flags = 0;
659 msg.len = 2;
660 msg.buf = &buf[2];
661 buf[2] &= ~0x40;
662 if (fe->ops.i2c_gate_ctrl)
663 fe->ops.i2c_gate_ctrl(fe, 1);
664 if (i2c_transfer(&budget->i2c_adap, &msg, 1) != 1)
665 return -EIO;
666
667 return 0;
668}
669
670static struct tda1002x_config philips_cu1216_config = {
671 .demod_address = 0x0c,
672 .invert = 1,
673};
674
675static struct tda1002x_config philips_cu1216_config_altaddress = {
676 .demod_address = 0x0d,
677 .invert = 0,
678};
679
680static struct tda10023_config philips_cu1216_tda10023_config = {
681 .demod_address = 0x0c,
682 .invert = 1,
683};
684
685static int philips_tu1216_tuner_init(struct dvb_frontend *fe)
686{
687 struct budget *budget = (struct budget *) fe->dvb->priv;
688 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
689 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
690
691 // setup PLL configuration
692 if (fe->ops.i2c_gate_ctrl)
693 fe->ops.i2c_gate_ctrl(fe, 1);
694 if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1)
695 return -EIO;
696 msleep(1);
697
698 return 0;
699}
700
701static int philips_tu1216_tuner_set_params(struct dvb_frontend *fe)
702{
703 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
704 struct budget *budget = (struct budget *) fe->dvb->priv;
705 u8 tuner_buf[4];
706 struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len =
707 sizeof(tuner_buf) };
708 int tuner_frequency = 0;
709 u8 band, cp, filter;
710
711 // determine charge pump
712 tuner_frequency = c->frequency + 36166000;
713 if (tuner_frequency < 87000000)
714 return -EINVAL;
715 else if (tuner_frequency < 130000000)
716 cp = 3;
717 else if (tuner_frequency < 160000000)
718 cp = 5;
719 else if (tuner_frequency < 200000000)
720 cp = 6;
721 else if (tuner_frequency < 290000000)
722 cp = 3;
723 else if (tuner_frequency < 420000000)
724 cp = 5;
725 else if (tuner_frequency < 480000000)
726 cp = 6;
727 else if (tuner_frequency < 620000000)
728 cp = 3;
729 else if (tuner_frequency < 830000000)
730 cp = 5;
731 else if (tuner_frequency < 895000000)
732 cp = 7;
733 else
734 return -EINVAL;
735
736 // determine band
737 if (c->frequency < 49000000)
738 return -EINVAL;
739 else if (c->frequency < 161000000)
740 band = 1;
741 else if (c->frequency < 444000000)
742 band = 2;
743 else if (c->frequency < 861000000)
744 band = 4;
745 else
746 return -EINVAL;
747
748 // setup PLL filter
749 switch (c->bandwidth_hz) {
750 case 6000000:
751 filter = 0;
752 break;
753
754 case 7000000:
755 filter = 0;
756 break;
757
758 case 8000000:
759 filter = 1;
760 break;
761
762 default:
763 return -EINVAL;
764 }
765
766 // calculate divisor
767 // ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
768 tuner_frequency = (((c->frequency / 1000) * 6) + 217496) / 1000;
769
770 // setup tuner buffer
771 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
772 tuner_buf[1] = tuner_frequency & 0xff;
773 tuner_buf[2] = 0xca;
774 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
775
776 if (fe->ops.i2c_gate_ctrl)
777 fe->ops.i2c_gate_ctrl(fe, 1);
778 if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1)
779 return -EIO;
780
781 msleep(1);
782 return 0;
783}
784
785static int philips_tu1216_request_firmware(struct dvb_frontend *fe,
786 const struct firmware **fw, char *name)
787{
788 struct budget *budget = (struct budget *) fe->dvb->priv;
789
790 return request_firmware(fw, name, &budget->dev->pci->dev);
791}
792
793static struct tda1004x_config philips_tu1216_config = {
794
795 .demod_address = 0x8,
796 .invert = 1,
797 .invert_oclk = 1,
798 .xtal_freq = TDA10046_XTAL_4M,
799 .agc_config = TDA10046_AGC_DEFAULT,
800 .if_freq = TDA10046_FREQ_3617,
801 .request_firmware = philips_tu1216_request_firmware,
802};
803
804static u8 philips_sd1878_inittab[] = {
805 0x01, 0x15,
806 0x02, 0x30,
807 0x03, 0x00,
808 0x04, 0x7d,
809 0x05, 0x35,
810 0x06, 0x40,
811 0x07, 0x00,
812 0x08, 0x43,
813 0x09, 0x02,
814 0x0C, 0x51,
815 0x0D, 0x82,
816 0x0E, 0x23,
817 0x10, 0x3f,
818 0x11, 0x84,
819 0x12, 0xb9,
820 0x15, 0xc9,
821 0x16, 0x19,
822 0x17, 0x8c,
823 0x18, 0x59,
824 0x19, 0xf8,
825 0x1a, 0xfe,
826 0x1c, 0x7f,
827 0x1d, 0x00,
828 0x1e, 0x00,
829 0x1f, 0x50,
830 0x20, 0x00,
831 0x21, 0x00,
832 0x22, 0x00,
833 0x23, 0x00,
834 0x28, 0x00,
835 0x29, 0x28,
836 0x2a, 0x14,
837 0x2b, 0x0f,
838 0x2c, 0x09,
839 0x2d, 0x09,
840 0x31, 0x1f,
841 0x32, 0x19,
842 0x33, 0xfc,
843 0x34, 0x93,
844 0xff, 0xff
845};
846
847static int philips_sd1878_ci_set_symbol_rate(struct dvb_frontend *fe,
848 u32 srate, u32 ratio)
849{
850 u8 aclk = 0;
851 u8 bclk = 0;
852 u8 m1;
853
854 aclk = 0xb5;
855 if (srate < 2000000)
856 bclk = 0x86;
857 else if (srate < 5000000)
858 bclk = 0x89;
859 else if (srate < 15000000)
860 bclk = 0x8f;
861 else if (srate < 45000000)
862 bclk = 0x95;
863
864 m1 = 0x14;
865 if (srate < 4000000)
866 m1 = 0x10;
867
868 stv0299_writereg(fe, 0x0e, 0x23);
869 stv0299_writereg(fe, 0x0f, 0x94);
870 stv0299_writereg(fe, 0x10, 0x39);
871 stv0299_writereg(fe, 0x13, aclk);
872 stv0299_writereg(fe, 0x14, bclk);
873 stv0299_writereg(fe, 0x15, 0xc9);
874 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
875 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
876 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
877 stv0299_writereg(fe, 0x0f, 0x80 | m1);
878
879 return 0;
880}
881
882static struct stv0299_config philips_sd1878_config = {
883 .demod_address = 0x68,
884 .inittab = philips_sd1878_inittab,
885 .mclk = 88000000UL,
886 .invert = 0,
887 .skip_reinit = 0,
888 .lock_output = STV0299_LOCKOUTPUT_1,
889 .volt13_op0_op1 = STV0299_VOLT13_OP0,
890 .min_delay_ms = 100,
891 .set_symbol_rate = philips_sd1878_ci_set_symbol_rate,
892};
893
894/* KNC1 DVB-S (STB0899) Inittab */
895static const struct stb0899_s1_reg knc1_stb0899_s1_init_1[] = {
896
897 { STB0899_DEV_ID , 0x81 },
898 { STB0899_DISCNTRL1 , 0x32 },
899 { STB0899_DISCNTRL2 , 0x80 },
900 { STB0899_DISRX_ST0 , 0x04 },
901 { STB0899_DISRX_ST1 , 0x00 },
902 { STB0899_DISPARITY , 0x00 },
903 { STB0899_DISSTATUS , 0x20 },
904 { STB0899_DISF22 , 0x8c },
905 { STB0899_DISF22RX , 0x9a },
906 { STB0899_SYSREG , 0x0b },
907 { STB0899_ACRPRESC , 0x11 },
908 { STB0899_ACRDIV1 , 0x0a },
909 { STB0899_ACRDIV2 , 0x05 },
910 { STB0899_DACR1 , 0x00 },
911 { STB0899_DACR2 , 0x00 },
912 { STB0899_OUTCFG , 0x00 },
913 { STB0899_MODECFG , 0x00 },
914 { STB0899_IRQSTATUS_3 , 0x30 },
915 { STB0899_IRQSTATUS_2 , 0x00 },
916 { STB0899_IRQSTATUS_1 , 0x00 },
917 { STB0899_IRQSTATUS_0 , 0x00 },
918 { STB0899_IRQMSK_3 , 0xf3 },
919 { STB0899_IRQMSK_2 , 0xfc },
920 { STB0899_IRQMSK_1 , 0xff },
921 { STB0899_IRQMSK_0 , 0xff },
922 { STB0899_IRQCFG , 0x00 },
923 { STB0899_I2CCFG , 0x88 },
924 { STB0899_I2CRPT , 0x58 }, /* Repeater=8, Stop=disabled */
925 { STB0899_IOPVALUE5 , 0x00 },
926 { STB0899_IOPVALUE4 , 0x20 },
927 { STB0899_IOPVALUE3 , 0xc9 },
928 { STB0899_IOPVALUE2 , 0x90 },
929 { STB0899_IOPVALUE1 , 0x40 },
930 { STB0899_IOPVALUE0 , 0x00 },
931 { STB0899_GPIO00CFG , 0x82 },
932 { STB0899_GPIO01CFG , 0x82 },
933 { STB0899_GPIO02CFG , 0x82 },
934 { STB0899_GPIO03CFG , 0x82 },
935 { STB0899_GPIO04CFG , 0x82 },
936 { STB0899_GPIO05CFG , 0x82 },
937 { STB0899_GPIO06CFG , 0x82 },
938 { STB0899_GPIO07CFG , 0x82 },
939 { STB0899_GPIO08CFG , 0x82 },
940 { STB0899_GPIO09CFG , 0x82 },
941 { STB0899_GPIO10CFG , 0x82 },
942 { STB0899_GPIO11CFG , 0x82 },
943 { STB0899_GPIO12CFG , 0x82 },
944 { STB0899_GPIO13CFG , 0x82 },
945 { STB0899_GPIO14CFG , 0x82 },
946 { STB0899_GPIO15CFG , 0x82 },
947 { STB0899_GPIO16CFG , 0x82 },
948 { STB0899_GPIO17CFG , 0x82 },
949 { STB0899_GPIO18CFG , 0x82 },
950 { STB0899_GPIO19CFG , 0x82 },
951 { STB0899_GPIO20CFG , 0x82 },
952 { STB0899_SDATCFG , 0xb8 },
953 { STB0899_SCLTCFG , 0xba },
954 { STB0899_AGCRFCFG , 0x08 }, /* 0x1c */
955 { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
956 { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
957 { STB0899_DIRCLKCFG , 0x82 },
958 { STB0899_CLKOUT27CFG , 0x7e },
959 { STB0899_STDBYCFG , 0x82 },
960 { STB0899_CS0CFG , 0x82 },
961 { STB0899_CS1CFG , 0x82 },
962 { STB0899_DISEQCOCFG , 0x20 },
963 { STB0899_GPIO32CFG , 0x82 },
964 { STB0899_GPIO33CFG , 0x82 },
965 { STB0899_GPIO34CFG , 0x82 },
966 { STB0899_GPIO35CFG , 0x82 },
967 { STB0899_GPIO36CFG , 0x82 },
968 { STB0899_GPIO37CFG , 0x82 },
969 { STB0899_GPIO38CFG , 0x82 },
970 { STB0899_GPIO39CFG , 0x82 },
971 { STB0899_NCOARSE , 0x15 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
972 { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
973 { STB0899_FILTCTRL , 0x00 },
974 { STB0899_SYSCTRL , 0x00 },
975 { STB0899_STOPCLK1 , 0x20 },
976 { STB0899_STOPCLK2 , 0x00 },
977 { STB0899_INTBUFSTATUS , 0x00 },
978 { STB0899_INTBUFCTRL , 0x0a },
979 { 0xffff , 0xff },
980};
981
982static const struct stb0899_s1_reg knc1_stb0899_s1_init_3[] = {
983 { STB0899_DEMOD , 0x00 },
984 { STB0899_RCOMPC , 0xc9 },
985 { STB0899_AGC1CN , 0x41 },
986 { STB0899_AGC1REF , 0x08 },
987 { STB0899_RTC , 0x7a },
988 { STB0899_TMGCFG , 0x4e },
989 { STB0899_AGC2REF , 0x33 },
990 { STB0899_TLSR , 0x84 },
991 { STB0899_CFD , 0xee },
992 { STB0899_ACLC , 0x87 },
993 { STB0899_BCLC , 0x94 },
994 { STB0899_EQON , 0x41 },
995 { STB0899_LDT , 0xdd },
996 { STB0899_LDT2 , 0xc9 },
997 { STB0899_EQUALREF , 0xb4 },
998 { STB0899_TMGRAMP , 0x10 },
999 { STB0899_TMGTHD , 0x30 },
1000 { STB0899_IDCCOMP , 0xfb },
1001 { STB0899_QDCCOMP , 0x03 },
1002 { STB0899_POWERI , 0x3b },
1003 { STB0899_POWERQ , 0x3d },
1004 { STB0899_RCOMP , 0x81 },
1005 { STB0899_AGCIQIN , 0x80 },
1006 { STB0899_AGC2I1 , 0x04 },
1007 { STB0899_AGC2I2 , 0xf5 },
1008 { STB0899_TLIR , 0x25 },
1009 { STB0899_RTF , 0x80 },
1010 { STB0899_DSTATUS , 0x00 },
1011 { STB0899_LDI , 0xca },
1012 { STB0899_CFRM , 0xf1 },
1013 { STB0899_CFRL , 0xf3 },
1014 { STB0899_NIRM , 0x2a },
1015 { STB0899_NIRL , 0x05 },
1016 { STB0899_ISYMB , 0x17 },
1017 { STB0899_QSYMB , 0xfa },
1018 { STB0899_SFRH , 0x2f },
1019 { STB0899_SFRM , 0x68 },
1020 { STB0899_SFRL , 0x40 },
1021 { STB0899_SFRUPH , 0x2f },
1022 { STB0899_SFRUPM , 0x68 },
1023 { STB0899_SFRUPL , 0x40 },
1024 { STB0899_EQUAI1 , 0xfd },
1025 { STB0899_EQUAQ1 , 0x04 },
1026 { STB0899_EQUAI2 , 0x0f },
1027 { STB0899_EQUAQ2 , 0xff },
1028 { STB0899_EQUAI3 , 0xdf },
1029 { STB0899_EQUAQ3 , 0xfa },
1030 { STB0899_EQUAI4 , 0x37 },
1031 { STB0899_EQUAQ4 , 0x0d },
1032 { STB0899_EQUAI5 , 0xbd },
1033 { STB0899_EQUAQ5 , 0xf7 },
1034 { STB0899_DSTATUS2 , 0x00 },
1035 { STB0899_VSTATUS , 0x00 },
1036 { STB0899_VERROR , 0xff },
1037 { STB0899_IQSWAP , 0x2a },
1038 { STB0899_ECNT1M , 0x00 },
1039 { STB0899_ECNT1L , 0x00 },
1040 { STB0899_ECNT2M , 0x00 },
1041 { STB0899_ECNT2L , 0x00 },
1042 { STB0899_ECNT3M , 0x00 },
1043 { STB0899_ECNT3L , 0x00 },
1044 { STB0899_FECAUTO1 , 0x06 },
1045 { STB0899_FECM , 0x01 },
1046 { STB0899_VTH12 , 0xf0 },
1047 { STB0899_VTH23 , 0xa0 },
1048 { STB0899_VTH34 , 0x78 },
1049 { STB0899_VTH56 , 0x4e },
1050 { STB0899_VTH67 , 0x48 },
1051 { STB0899_VTH78 , 0x38 },
1052 { STB0899_PRVIT , 0xff },
1053 { STB0899_VITSYNC , 0x19 },
1054 { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
1055 { STB0899_TSULC , 0x42 },
1056 { STB0899_RSLLC , 0x40 },
1057 { STB0899_TSLPL , 0x12 },
1058 { STB0899_TSCFGH , 0x0c },
1059 { STB0899_TSCFGM , 0x00 },
1060 { STB0899_TSCFGL , 0x0c },
1061 { STB0899_TSOUT , 0x4d }, /* 0x0d for CAM */
1062 { STB0899_RSSYNCDEL , 0x00 },
1063 { STB0899_TSINHDELH , 0x02 },
1064 { STB0899_TSINHDELM , 0x00 },
1065 { STB0899_TSINHDELL , 0x00 },
1066 { STB0899_TSLLSTKM , 0x00 },
1067 { STB0899_TSLLSTKL , 0x00 },
1068 { STB0899_TSULSTKM , 0x00 },
1069 { STB0899_TSULSTKL , 0xab },
1070 { STB0899_PCKLENUL , 0x00 },
1071 { STB0899_PCKLENLL , 0xcc },
1072 { STB0899_RSPCKLEN , 0xcc },
1073 { STB0899_TSSTATUS , 0x80 },
1074 { STB0899_ERRCTRL1 , 0xb6 },
1075 { STB0899_ERRCTRL2 , 0x96 },
1076 { STB0899_ERRCTRL3 , 0x89 },
1077 { STB0899_DMONMSK1 , 0x27 },
1078 { STB0899_DMONMSK0 , 0x03 },
1079 { STB0899_DEMAPVIT , 0x5c },
1080 { STB0899_PLPARM , 0x1f },
1081 { STB0899_PDELCTRL , 0x48 },
1082 { STB0899_PDELCTRL2 , 0x00 },
1083 { STB0899_BBHCTRL1 , 0x00 },
1084 { STB0899_BBHCTRL2 , 0x00 },
1085 { STB0899_HYSTTHRESH , 0x77 },
1086 { STB0899_MATCSTM , 0x00 },
1087 { STB0899_MATCSTL , 0x00 },
1088 { STB0899_UPLCSTM , 0x00 },
1089 { STB0899_UPLCSTL , 0x00 },
1090 { STB0899_DFLCSTM , 0x00 },
1091 { STB0899_DFLCSTL , 0x00 },
1092 { STB0899_SYNCCST , 0x00 },
1093 { STB0899_SYNCDCSTM , 0x00 },
1094 { STB0899_SYNCDCSTL , 0x00 },
1095 { STB0899_ISI_ENTRY , 0x00 },
1096 { STB0899_ISI_BIT_EN , 0x00 },
1097 { STB0899_MATSTRM , 0x00 },
1098 { STB0899_MATSTRL , 0x00 },
1099 { STB0899_UPLSTRM , 0x00 },
1100 { STB0899_UPLSTRL , 0x00 },
1101 { STB0899_DFLSTRM , 0x00 },
1102 { STB0899_DFLSTRL , 0x00 },
1103 { STB0899_SYNCSTR , 0x00 },
1104 { STB0899_SYNCDSTRM , 0x00 },
1105 { STB0899_SYNCDSTRL , 0x00 },
1106 { STB0899_CFGPDELSTATUS1 , 0x10 },
1107 { STB0899_CFGPDELSTATUS2 , 0x00 },
1108 { STB0899_BBFERRORM , 0x00 },
1109 { STB0899_BBFERRORL , 0x00 },
1110 { STB0899_UPKTERRORM , 0x00 },
1111 { STB0899_UPKTERRORL , 0x00 },
1112 { 0xffff , 0xff },
1113};
1114
1115/* STB0899 demodulator config for the KNC1 and clones */
1116static struct stb0899_config knc1_dvbs2_config = {
1117 .init_dev = knc1_stb0899_s1_init_1,
1118 .init_s2_demod = stb0899_s2_init_2,
1119 .init_s1_demod = knc1_stb0899_s1_init_3,
1120 .init_s2_fec = stb0899_s2_init_4,
1121 .init_tst = stb0899_s1_init_5,
1122
1123 .postproc = NULL,
1124
1125 .demod_address = 0x68,
1126// .ts_output_mode = STB0899_OUT_PARALLEL, /* types = SERIAL/PARALLEL */
1127 .block_sync_mode = STB0899_SYNC_FORCED, /* DSS, SYNC_FORCED/UNSYNCED */
1128// .ts_pfbit_toggle = STB0899_MPEG_NORMAL, /* DirecTV, MPEG toggling seq */
1129
1130 .xtal_freq = 27000000,
1131 .inversion = IQ_SWAP_OFF, /* 1 */
1132
1133 .lo_clk = 76500000,
1134 .hi_clk = 90000000,
1135
1136 .esno_ave = STB0899_DVBS2_ESNO_AVE,
1137 .esno_quant = STB0899_DVBS2_ESNO_QUANT,
1138 .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
1139 .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
1140 .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
1141 .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
1142 .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
1143 .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
1144 .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
1145
1146 .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
1147 .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
1148 .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
1149 .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
1150
1151 .tuner_get_frequency = tda8261_get_frequency,
1152 .tuner_set_frequency = tda8261_set_frequency,
1153 .tuner_set_bandwidth = NULL,
1154 .tuner_get_bandwidth = tda8261_get_bandwidth,
1155 .tuner_set_rfsiggain = NULL
1156};
1157
1158/*
1159 * SD1878/SHA tuner config
1160 * 1F, Single I/P, Horizontal mount, High Sensitivity
1161 */
1162static const struct tda8261_config sd1878c_config = {
1163// .name = "SD1878/SHA",
1164 .addr = 0x60,
1165 .step_size = TDA8261_STEP_1000 /* kHz */
1166};
1167
1168static u8 read_pwm(struct budget_av *budget_av)
1169{
1170 u8 b = 0xff;
1171 u8 pwm;
1172 struct i2c_msg msg[] = { {.addr = 0x50,.flags = 0,.buf = &b,.len = 1},
1173 {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1}
1174 };
1175
1176 if ((i2c_transfer(&budget_av->budget.i2c_adap, msg, 2) != 2)
1177 || (pwm == 0xff))
1178 pwm = 0x48;
1179
1180 return pwm;
1181}
1182
1183#define SUBID_DVBS_KNC1 0x0010
1184#define SUBID_DVBS_KNC1_PLUS 0x0011
1185#define SUBID_DVBS_TYPHOON 0x4f56
1186#define SUBID_DVBS_CINERGY1200 0x1154
1187#define SUBID_DVBS_CYNERGY1200N 0x1155
1188#define SUBID_DVBS_TV_STAR 0x0014
1189#define SUBID_DVBS_TV_STAR_PLUS_X4 0x0015
1190#define SUBID_DVBS_TV_STAR_CI 0x0016
1191#define SUBID_DVBS2_KNC1 0x0018
1192#define SUBID_DVBS2_KNC1_OEM 0x0019
1193#define SUBID_DVBS_EASYWATCH_1 0x001a
1194#define SUBID_DVBS_EASYWATCH_2 0x001b
1195#define SUBID_DVBS2_EASYWATCH 0x001d
1196#define SUBID_DVBS_EASYWATCH 0x001e
1197
1198#define SUBID_DVBC_EASYWATCH 0x002a
1199#define SUBID_DVBC_EASYWATCH_MK3 0x002c
1200#define SUBID_DVBC_KNC1 0x0020
1201#define SUBID_DVBC_KNC1_PLUS 0x0021
1202#define SUBID_DVBC_KNC1_MK3 0x0022
1203#define SUBID_DVBC_KNC1_TDA10024 0x0028
1204#define SUBID_DVBC_KNC1_PLUS_MK3 0x0023
1205#define SUBID_DVBC_CINERGY1200 0x1156
1206#define SUBID_DVBC_CINERGY1200_MK3 0x1176
1207
1208#define SUBID_DVBT_EASYWATCH 0x003a
1209#define SUBID_DVBT_KNC1_PLUS 0x0031
1210#define SUBID_DVBT_KNC1 0x0030
1211#define SUBID_DVBT_CINERGY1200 0x1157
1212
1213static void frontend_init(struct budget_av *budget_av)
1214{
1215 struct saa7146_dev * saa = budget_av->budget.dev;
1216 struct dvb_frontend * fe = NULL;
1217
1218 /* Enable / PowerON Frontend */
1219 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
1220
1221 /* Wait for PowerON */
1222 msleep(100);
1223
1224 /* additional setup necessary for the PLUS cards */
1225 switch (saa->pci->subsystem_device) {
1226 case SUBID_DVBS_KNC1_PLUS:
1227 case SUBID_DVBC_KNC1_PLUS:
1228 case SUBID_DVBT_KNC1_PLUS:
1229 case SUBID_DVBC_EASYWATCH:
1230 case SUBID_DVBC_KNC1_PLUS_MK3:
1231 case SUBID_DVBS2_KNC1:
1232 case SUBID_DVBS2_KNC1_OEM:
1233 case SUBID_DVBS2_EASYWATCH:
1234 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI);
1235 break;
1236 }
1237
1238 switch (saa->pci->subsystem_device) {
1239
1240 case SUBID_DVBS_KNC1:
1241 /*
1242 * maybe that setting is needed for other dvb-s cards as well,
1243 * but so far it has been only confirmed for this type
1244 */
1245 budget_av->reinitialise_demod = 1;
1246 /* fall through */
1247 case SUBID_DVBS_KNC1_PLUS:
1248 case SUBID_DVBS_EASYWATCH_1:
1249 if (saa->pci->subsystem_vendor == 0x1894) {
1250 fe = dvb_attach(stv0299_attach, &cinergy_1200s_1894_0010_config,
1251 &budget_av->budget.i2c_adap);
1252 if (fe) {
1253 dvb_attach(tua6100_attach, fe, 0x60, &budget_av->budget.i2c_adap);
1254 }
1255 } else {
1256 fe = dvb_attach(stv0299_attach, &typhoon_config,
1257 &budget_av->budget.i2c_adap);
1258 if (fe) {
1259 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1260 }
1261 }
1262 break;
1263
1264 case SUBID_DVBS_TV_STAR:
1265 case SUBID_DVBS_TV_STAR_PLUS_X4:
1266 case SUBID_DVBS_TV_STAR_CI:
1267 case SUBID_DVBS_CYNERGY1200N:
1268 case SUBID_DVBS_EASYWATCH:
1269 case SUBID_DVBS_EASYWATCH_2:
1270 fe = dvb_attach(stv0299_attach, &philips_sd1878_config,
1271 &budget_av->budget.i2c_adap);
1272 if (fe) {
1273 dvb_attach(dvb_pll_attach, fe, 0x60,
1274 &budget_av->budget.i2c_adap,
1275 DVB_PLL_PHILIPS_SD1878_TDA8261);
1276 }
1277 break;
1278
1279 case SUBID_DVBS_TYPHOON:
1280 fe = dvb_attach(stv0299_attach, &typhoon_config,
1281 &budget_av->budget.i2c_adap);
1282 if (fe) {
1283 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1284 }
1285 break;
1286 case SUBID_DVBS2_KNC1:
1287 case SUBID_DVBS2_KNC1_OEM:
1288 case SUBID_DVBS2_EASYWATCH:
1289 budget_av->reinitialise_demod = 1;
1290 if ((fe = dvb_attach(stb0899_attach, &knc1_dvbs2_config, &budget_av->budget.i2c_adap)))
1291 dvb_attach(tda8261_attach, fe, &sd1878c_config, &budget_av->budget.i2c_adap);
1292
1293 break;
1294 case SUBID_DVBS_CINERGY1200:
1295 fe = dvb_attach(stv0299_attach, &cinergy_1200s_config,
1296 &budget_av->budget.i2c_adap);
1297 if (fe) {
1298 fe->ops.tuner_ops.set_params = philips_su1278_ty_ci_tuner_set_params;
1299 }
1300 break;
1301
1302 case SUBID_DVBC_KNC1:
1303 case SUBID_DVBC_KNC1_PLUS:
1304 case SUBID_DVBC_CINERGY1200:
1305 case SUBID_DVBC_EASYWATCH:
1306 budget_av->reinitialise_demod = 1;
1307 budget_av->budget.dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
1308 fe = dvb_attach(tda10021_attach, &philips_cu1216_config,
1309 &budget_av->budget.i2c_adap,
1310 read_pwm(budget_av));
1311 if (fe == NULL)
1312 fe = dvb_attach(tda10021_attach, &philips_cu1216_config_altaddress,
1313 &budget_av->budget.i2c_adap,
1314 read_pwm(budget_av));
1315 if (fe) {
1316 fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set_params;
1317 }
1318 break;
1319
1320 case SUBID_DVBC_EASYWATCH_MK3:
1321 case SUBID_DVBC_CINERGY1200_MK3:
1322 case SUBID_DVBC_KNC1_MK3:
1323 case SUBID_DVBC_KNC1_TDA10024:
1324 case SUBID_DVBC_KNC1_PLUS_MK3:
1325 budget_av->reinitialise_demod = 1;
1326 budget_av->budget.dev->i2c_bitrate = SAA7146_I2C_BUS_BIT_RATE_240;
1327 fe = dvb_attach(tda10023_attach,
1328 &philips_cu1216_tda10023_config,
1329 &budget_av->budget.i2c_adap,
1330 read_pwm(budget_av));
1331 if (fe) {
1332 fe->ops.tuner_ops.set_params = philips_cu1216_tuner_set_params;
1333 }
1334 break;
1335
1336 case SUBID_DVBT_EASYWATCH:
1337 case SUBID_DVBT_KNC1:
1338 case SUBID_DVBT_KNC1_PLUS:
1339 case SUBID_DVBT_CINERGY1200:
1340 budget_av->reinitialise_demod = 1;
1341 fe = dvb_attach(tda10046_attach, &philips_tu1216_config,
1342 &budget_av->budget.i2c_adap);
1343 if (fe) {
1344 fe->ops.tuner_ops.init = philips_tu1216_tuner_init;
1345 fe->ops.tuner_ops.set_params = philips_tu1216_tuner_set_params;
1346 }
1347 break;
1348 }
1349
1350 if (fe == NULL) {
1351 pr_err("A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
1352 saa->pci->vendor,
1353 saa->pci->device,
1354 saa->pci->subsystem_vendor,
1355 saa->pci->subsystem_device);
1356 return;
1357 }
1358
1359 budget_av->budget.dvb_frontend = fe;
1360
1361 if (dvb_register_frontend(&budget_av->budget.dvb_adapter,
1362 budget_av->budget.dvb_frontend)) {
1363 pr_err("Frontend registration failed!\n");
1364 dvb_frontend_detach(budget_av->budget.dvb_frontend);
1365 budget_av->budget.dvb_frontend = NULL;
1366 }
1367}
1368
1369
1370static void budget_av_irq(struct saa7146_dev *dev, u32 * isr)
1371{
1372 struct budget_av *budget_av = (struct budget_av *) dev->ext_priv;
1373
1374 dprintk(8, "dev: %p, budget_av: %p\n", dev, budget_av);
1375
1376 if (*isr & MASK_10)
1377 ttpci_budget_irq10_handler(dev, isr);
1378}
1379
1380static int budget_av_detach(struct saa7146_dev *dev)
1381{
1382 struct budget_av *budget_av = (struct budget_av *) dev->ext_priv;
1383 int err;
1384
1385 dprintk(2, "dev: %p\n", dev);
1386
1387 if (1 == budget_av->has_saa7113) {
1388 saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTLO);
1389
1390 msleep(200);
1391
1392 saa7146_unregister_device(&budget_av->vd, dev);
1393
1394 saa7146_vv_release(dev);
1395 }
1396
1397 if (budget_av->budget.ci_present)
1398 ciintf_deinit(budget_av);
1399
1400 if (budget_av->budget.dvb_frontend != NULL) {
1401 dvb_unregister_frontend(budget_av->budget.dvb_frontend);
1402 dvb_frontend_detach(budget_av->budget.dvb_frontend);
1403 }
1404 err = ttpci_budget_deinit(&budget_av->budget);
1405
1406 kfree(budget_av);
1407
1408 return err;
1409}
1410
1411#define KNC1_INPUTS 2
1412static struct v4l2_input knc1_inputs[KNC1_INPUTS] = {
1413 { 0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0,
1414 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1415 { 1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0,
1416 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1417};
1418
1419static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
1420{
1421 dprintk(1, "VIDIOC_ENUMINPUT %d\n", i->index);
1422 if (i->index >= KNC1_INPUTS)
1423 return -EINVAL;
1424 memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input));
1425 return 0;
1426}
1427
1428static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
1429{
1430 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
1431 struct budget_av *budget_av = (struct budget_av *)dev->ext_priv;
1432
1433 *i = budget_av->cur_input;
1434
1435 dprintk(1, "VIDIOC_G_INPUT %d\n", *i);
1436 return 0;
1437}
1438
1439static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
1440{
1441 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
1442 struct budget_av *budget_av = (struct budget_av *)dev->ext_priv;
1443
1444 dprintk(1, "VIDIOC_S_INPUT %d\n", input);
1445 return saa7113_setinput(budget_av, input);
1446}
1447
1448static struct saa7146_ext_vv vv_data;
1449
1450static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
1451{
1452 struct budget_av *budget_av;
1453 u8 *mac;
1454 int err;
1455
1456 dprintk(2, "dev: %p\n", dev);
1457
1458 if (!(budget_av = kzalloc(sizeof(struct budget_av), GFP_KERNEL)))
1459 return -ENOMEM;
1460
1461 budget_av->has_saa7113 = 0;
1462 budget_av->budget.ci_present = 0;
1463
1464 dev->ext_priv = budget_av;
1465
1466 err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE,
1467 adapter_nr);
1468 if (err) {
1469 kfree(budget_av);
1470 return err;
1471 }
1472
1473 /* knc1 initialization */
1474 saa7146_write(dev, DD1_STREAM_B, 0x04000000);
1475 saa7146_write(dev, DD1_INIT, 0x07000600);
1476 saa7146_write(dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26);
1477
1478 if (saa7113_init(budget_av) == 0) {
1479 budget_av->has_saa7113 = 1;
1480
1481 if (0 != saa7146_vv_init(dev, &vv_data)) {
1482 /* fixme: proper cleanup here */
1483 ERR("cannot init vv subsystem\n");
1484 return err;
1485 }
1486 vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input;
1487 vv_data.vid_ops.vidioc_g_input = vidioc_g_input;
1488 vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
1489
1490 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
1491 /* fixme: proper cleanup here */
1492 ERR("cannot register capture v4l2 device\n");
1493 saa7146_vv_release(dev);
1494 return err;
1495 }
1496
1497 /* beware: this modifies dev->vv ... */
1498 saa7146_set_hps_source_and_sync(dev, SAA7146_HPS_SOURCE_PORT_A,
1499 SAA7146_HPS_SYNC_PORT_A);
1500
1501 saa7113_setinput(budget_av, 0);
1502 }
1503
1504 /* fixme: find some sane values here... */
1505 saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
1506
1507 mac = budget_av->budget.dvb_adapter.proposed_mac;
1508 if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) {
1509 pr_err("KNC1-%d: Could not read MAC from KNC1 card\n",
1510 budget_av->budget.dvb_adapter.num);
1511 memset(mac, 0, 6);
1512 } else {
1513 pr_info("KNC1-%d: MAC addr = %pM\n",
1514 budget_av->budget.dvb_adapter.num, mac);
1515 }
1516
1517 budget_av->budget.dvb_adapter.priv = budget_av;
1518 frontend_init(budget_av);
1519 ciintf_init(budget_av);
1520
1521 ttpci_budget_init_hooks(&budget_av->budget);
1522
1523 return 0;
1524}
1525
1526static struct saa7146_standard standard[] = {
1527 {.name = "PAL",.id = V4L2_STD_PAL,
1528 .v_offset = 0x17,.v_field = 288,
1529 .h_offset = 0x14,.h_pixels = 680,
1530 .v_max_out = 576,.h_max_out = 768 },
1531
1532 {.name = "NTSC",.id = V4L2_STD_NTSC,
1533 .v_offset = 0x16,.v_field = 240,
1534 .h_offset = 0x06,.h_pixels = 708,
1535 .v_max_out = 480,.h_max_out = 640, },
1536};
1537
1538static struct saa7146_ext_vv vv_data = {
1539 .inputs = 2,
1540 .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113
1541 .flags = 0,
1542 .stds = &standard[0],
1543 .num_stds = ARRAY_SIZE(standard),
1544};
1545
1546static struct saa7146_extension budget_extension;
1547
1548MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S);
1549MAKE_BUDGET_INFO(knc1s2,"KNC1 DVB-S2", BUDGET_KNC1S2);
1550MAKE_BUDGET_INFO(sates2,"Satelco EasyWatch DVB-S2", BUDGET_KNC1S2);
1551MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C);
1552MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T);
1553MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR);
1554MAKE_BUDGET_INFO(satewpls, "Satelco EasyWatch DVB-S light", BUDGET_TVSTAR);
1555MAKE_BUDGET_INFO(satewpls1, "Satelco EasyWatch DVB-S light", BUDGET_KNC1S);
1556MAKE_BUDGET_INFO(satewps, "Satelco EasyWatch DVB-S", BUDGET_KNC1S);
1557MAKE_BUDGET_INFO(satewplc, "Satelco EasyWatch DVB-C", BUDGET_KNC1CP);
1558MAKE_BUDGET_INFO(satewcmk3, "Satelco EasyWatch DVB-C MK3", BUDGET_KNC1C_MK3);
1559MAKE_BUDGET_INFO(satewt, "Satelco EasyWatch DVB-T", BUDGET_KNC1T);
1560MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
1561MAKE_BUDGET_INFO(knc1spx4, "KNC1 DVB-S Plus X4", BUDGET_KNC1SP);
1562MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
1563MAKE_BUDGET_INFO(knc1cmk3, "KNC1 DVB-C MK3", BUDGET_KNC1C_MK3);
1564MAKE_BUDGET_INFO(knc1ctda10024, "KNC1 DVB-C TDA10024", BUDGET_KNC1C_TDA10024);
1565MAKE_BUDGET_INFO(knc1cpmk3, "KNC1 DVB-C Plus MK3", BUDGET_KNC1CP_MK3);
1566MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
1567MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
1568MAKE_BUDGET_INFO(cin1200sn, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
1569MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C);
1570MAKE_BUDGET_INFO(cin1200cmk3, "Terratec Cinergy 1200 DVB-C MK3", BUDGET_CIN1200C_MK3);
1571MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T);
1572
1573static struct pci_device_id pci_tbl[] = {
1574 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56),
1575 MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010),
1576 MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010),
1577 MAKE_EXTENSION_PCI(knc1sp, 0x1131, 0x0011),
1578 MAKE_EXTENSION_PCI(knc1sp, 0x1894, 0x0011),
1579 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0014),
1580 MAKE_EXTENSION_PCI(knc1spx4, 0x1894, 0x0015),
1581 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016),
1582 MAKE_EXTENSION_PCI(knc1s2, 0x1894, 0x0018),
1583 MAKE_EXTENSION_PCI(knc1s2, 0x1894, 0x0019),
1584 MAKE_EXTENSION_PCI(sates2, 0x1894, 0x001d),
1585 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e),
1586 MAKE_EXTENSION_PCI(satewpls1, 0x1894, 0x001a),
1587 MAKE_EXTENSION_PCI(satewps, 0x1894, 0x001b),
1588 MAKE_EXTENSION_PCI(satewplc, 0x1894, 0x002a),
1589 MAKE_EXTENSION_PCI(satewcmk3, 0x1894, 0x002c),
1590 MAKE_EXTENSION_PCI(satewt, 0x1894, 0x003a),
1591 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
1592 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
1593 MAKE_EXTENSION_PCI(knc1cmk3, 0x1894, 0x0022),
1594 MAKE_EXTENSION_PCI(knc1ctda10024, 0x1894, 0x0028),
1595 MAKE_EXTENSION_PCI(knc1cpmk3, 0x1894, 0x0023),
1596 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
1597 MAKE_EXTENSION_PCI(knc1tp, 0x1894, 0x0031),
1598 MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154),
1599 MAKE_EXTENSION_PCI(cin1200sn, 0x153b, 0x1155),
1600 MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156),
1601 MAKE_EXTENSION_PCI(cin1200cmk3, 0x153b, 0x1176),
1602 MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157),
1603 {
1604 .vendor = 0,
1605 }
1606};
1607
1608MODULE_DEVICE_TABLE(pci, pci_tbl);
1609
1610static struct saa7146_extension budget_extension = {
1611 .name = "budget_av",
1612 .flags = SAA7146_USE_I2C_IRQ,
1613
1614 .pci_tbl = pci_tbl,
1615
1616 .module = THIS_MODULE,
1617 .attach = budget_av_attach,
1618 .detach = budget_av_detach,
1619
1620 .irq_mask = MASK_10,
1621 .irq_func = budget_av_irq,
1622};
1623
1624static int __init budget_av_init(void)
1625{
1626 return saa7146_register_extension(&budget_extension);
1627}
1628
1629static void __exit budget_av_exit(void)
1630{
1631 saa7146_unregister_extension(&budget_extension);
1632}
1633
1634module_init(budget_av_init);
1635module_exit(budget_av_exit);
1636
1637MODULE_LICENSE("GPL");
1638MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
1639MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1640 "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)");
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
deleted file mode 100644
index 98e524178765..000000000000
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ /dev/null
@@ -1,1591 +0,0 @@
1/*
2 * budget-ci.c: driver for the SAA7146 based Budget DVB cards
3 *
4 * Compiled from various sources by Michael Hunold <michael@mihu.de>
5 *
6 * msp430 IR support contributed by Jack Thomasson <jkt@Helius.COM>
7 * partially based on the Siemens DVB driver by Ralph+Marcus Metzler
8 *
9 * CI interface support (c) 2004 Andrew de Quincey <adq_dvb@lidskialf.net>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 *
28 *
29 * the project's page is at http://www.linuxtv.org/
30 */
31
32#include <linux/module.h>
33#include <linux/errno.h>
34#include <linux/slab.h>
35#include <linux/interrupt.h>
36#include <linux/spinlock.h>
37#include <media/rc-core.h>
38
39#include "budget.h"
40
41#include "dvb_ca_en50221.h"
42#include "stv0299.h"
43#include "stv0297.h"
44#include "tda1004x.h"
45#include "stb0899_drv.h"
46#include "stb0899_reg.h"
47#include "stb0899_cfg.h"
48#include "stb6100.h"
49#include "stb6100_cfg.h"
50#include "lnbp21.h"
51#include "bsbe1.h"
52#include "bsru6.h"
53#include "tda1002x.h"
54#include "tda827x.h"
55#include "bsbe1-d01a.h"
56
57#define MODULE_NAME "budget_ci"
58
59/*
60 * Regarding DEBIADDR_IR:
61 * Some CI modules hang if random addresses are read.
62 * Using address 0x4000 for the IR read means that we
63 * use the same address as for CI version, which should
64 * be a safe default.
65 */
66#define DEBIADDR_IR 0x4000
67#define DEBIADDR_CICONTROL 0x0000
68#define DEBIADDR_CIVERSION 0x4000
69#define DEBIADDR_IO 0x1000
70#define DEBIADDR_ATTR 0x3000
71
72#define CICONTROL_RESET 0x01
73#define CICONTROL_ENABLETS 0x02
74#define CICONTROL_CAMDETECT 0x08
75
76#define DEBICICTL 0x00420000
77#define DEBICICAM 0x02420000
78
79#define SLOTSTATUS_NONE 1
80#define SLOTSTATUS_PRESENT 2
81#define SLOTSTATUS_RESET 4
82#define SLOTSTATUS_READY 8
83#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
84
85/* RC5 device wildcard */
86#define IR_DEVICE_ANY 255
87
88static int rc5_device = -1;
89module_param(rc5_device, int, 0644);
90MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
91
92static int ir_debug;
93module_param(ir_debug, int, 0644);
94MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
95
96DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
97
98struct budget_ci_ir {
99 struct rc_dev *dev;
100 struct tasklet_struct msp430_irq_tasklet;
101 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
102 char phys[32];
103 int rc5_device;
104 u32 ir_key;
105 bool have_command;
106 bool full_rc5; /* Outputs a full RC5 code */
107};
108
109struct budget_ci {
110 struct budget budget;
111 struct tasklet_struct ciintf_irq_tasklet;
112 int slot_status;
113 int ci_irq;
114 struct dvb_ca_en50221 ca;
115 struct budget_ci_ir ir;
116 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
117};
118
119static void msp430_ir_interrupt(unsigned long data)
120{
121 struct budget_ci *budget_ci = (struct budget_ci *) data;
122 struct rc_dev *dev = budget_ci->ir.dev;
123 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
124
125 /*
126 * The msp430 chip can generate two different bytes, command and device
127 *
128 * type1: X1CCCCCC, C = command bits (0 - 63)
129 * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
130 *
131 * Each signal from the remote control can generate one or more command
132 * bytes and one or more device bytes. For the repeated bytes, the
133 * highest bit (X) is set. The first command byte is always generated
134 * before the first device byte. Other than that, no specific order
135 * seems to apply. To make life interesting, bytes can also be lost.
136 *
137 * Only when we have a command and device byte, a keypress is
138 * generated.
139 */
140
141 if (ir_debug)
142 printk("budget_ci: received byte 0x%02x\n", command);
143
144 /* Remove repeat bit, we use every command */
145 command = command & 0x7f;
146
147 /* Is this a RC5 command byte? */
148 if (command & 0x40) {
149 budget_ci->ir.have_command = true;
150 budget_ci->ir.ir_key = command & 0x3f;
151 return;
152 }
153
154 /* It's a RC5 device byte */
155 if (!budget_ci->ir.have_command)
156 return;
157 budget_ci->ir.have_command = false;
158
159 if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
160 budget_ci->ir.rc5_device != (command & 0x1f))
161 return;
162
163 if (budget_ci->ir.full_rc5) {
164 rc_keydown(dev,
165 budget_ci->ir.rc5_device <<8 | budget_ci->ir.ir_key,
166 (command & 0x20) ? 1 : 0);
167 return;
168 }
169
170 /* FIXME: We should generate complete scancodes for all devices */
171 rc_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
172}
173
174static int msp430_ir_init(struct budget_ci *budget_ci)
175{
176 struct saa7146_dev *saa = budget_ci->budget.dev;
177 struct rc_dev *dev;
178 int error;
179
180 dev = rc_allocate_device();
181 if (!dev) {
182 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
183 return -ENOMEM;
184 }
185
186 snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
187 "Budget-CI dvb ir receiver %s", saa->name);
188 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
189 "pci-%s/ir0", pci_name(saa->pci));
190
191 dev->driver_name = MODULE_NAME;
192 dev->input_name = budget_ci->ir.name;
193 dev->input_phys = budget_ci->ir.phys;
194 dev->input_id.bustype = BUS_PCI;
195 dev->input_id.version = 1;
196 if (saa->pci->subsystem_vendor) {
197 dev->input_id.vendor = saa->pci->subsystem_vendor;
198 dev->input_id.product = saa->pci->subsystem_device;
199 } else {
200 dev->input_id.vendor = saa->pci->vendor;
201 dev->input_id.product = saa->pci->device;
202 }
203 dev->dev.parent = &saa->pci->dev;
204
205 if (rc5_device < 0)
206 budget_ci->ir.rc5_device = IR_DEVICE_ANY;
207 else
208 budget_ci->ir.rc5_device = rc5_device;
209
210 /* Select keymap and address */
211 switch (budget_ci->budget.dev->pci->subsystem_device) {
212 case 0x100c:
213 case 0x100f:
214 case 0x1011:
215 case 0x1012:
216 /* The hauppauge keymap is a superset of these remotes */
217 dev->map_name = RC_MAP_HAUPPAUGE;
218 budget_ci->ir.full_rc5 = true;
219
220 if (rc5_device < 0)
221 budget_ci->ir.rc5_device = 0x1f;
222 break;
223 case 0x1010:
224 case 0x1017:
225 case 0x1019:
226 case 0x101a:
227 case 0x101b:
228 /* for the Technotrend 1500 bundled remote */
229 dev->map_name = RC_MAP_TT_1500;
230 break;
231 default:
232 /* unknown remote */
233 dev->map_name = RC_MAP_BUDGET_CI_OLD;
234 break;
235 }
236 if (!budget_ci->ir.full_rc5)
237 dev->scanmask = 0xff;
238
239 error = rc_register_device(dev);
240 if (error) {
241 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
242 rc_free_device(dev);
243 return error;
244 }
245
246 budget_ci->ir.dev = dev;
247
248 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
249 (unsigned long) budget_ci);
250
251 SAA7146_IER_ENABLE(saa, MASK_06);
252 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
253
254 return 0;
255}
256
257static void msp430_ir_deinit(struct budget_ci *budget_ci)
258{
259 struct saa7146_dev *saa = budget_ci->budget.dev;
260
261 SAA7146_IER_DISABLE(saa, MASK_06);
262 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
263 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
264
265 rc_unregister_device(budget_ci->ir.dev);
266}
267
268static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
269{
270 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
271
272 if (slot != 0)
273 return -EINVAL;
274
275 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
276 DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
277}
278
279static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
280{
281 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
282
283 if (slot != 0)
284 return -EINVAL;
285
286 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
287 DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
288}
289
290static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
291{
292 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
293
294 if (slot != 0)
295 return -EINVAL;
296
297 return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
298 DEBIADDR_IO | (address & 3), 1, 1, 0);
299}
300
301static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
302{
303 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
304
305 if (slot != 0)
306 return -EINVAL;
307
308 return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
309 DEBIADDR_IO | (address & 3), 1, value, 1, 0);
310}
311
312static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
313{
314 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
315 struct saa7146_dev *saa = budget_ci->budget.dev;
316
317 if (slot != 0)
318 return -EINVAL;
319
320 if (budget_ci->ci_irq) {
321 // trigger on RISING edge during reset so we know when READY is re-asserted
322 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
323 }
324 budget_ci->slot_status = SLOTSTATUS_RESET;
325 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
326 msleep(1);
327 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
328 CICONTROL_RESET, 1, 0);
329
330 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
331 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
332 return 0;
333}
334
335static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
336{
337 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
338 struct saa7146_dev *saa = budget_ci->budget.dev;
339
340 if (slot != 0)
341 return -EINVAL;
342
343 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
344 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
345 return 0;
346}
347
348static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
349{
350 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
351 struct saa7146_dev *saa = budget_ci->budget.dev;
352 int tmp;
353
354 if (slot != 0)
355 return -EINVAL;
356
357 saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
358
359 tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
360 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
361 tmp | CICONTROL_ENABLETS, 1, 0);
362
363 ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
364 return 0;
365}
366
367static void ciintf_interrupt(unsigned long data)
368{
369 struct budget_ci *budget_ci = (struct budget_ci *) data;
370 struct saa7146_dev *saa = budget_ci->budget.dev;
371 unsigned int flags;
372
373 // ensure we don't get spurious IRQs during initialisation
374 if (!budget_ci->budget.ci_present)
375 return;
376
377 // read the CAM status
378 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
379 if (flags & CICONTROL_CAMDETECT) {
380
381 // GPIO should be set to trigger on falling edge if a CAM is present
382 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
383
384 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
385 // CAM insertion IRQ
386 budget_ci->slot_status = SLOTSTATUS_PRESENT;
387 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
388 DVB_CA_EN50221_CAMCHANGE_INSERTED);
389
390 } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
391 // CAM ready (reset completed)
392 budget_ci->slot_status = SLOTSTATUS_READY;
393 dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
394
395 } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
396 // FR/DA IRQ
397 dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
398 }
399 } else {
400
401 // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
402 // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
403 // the CAM might not actually be ready yet.
404 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
405
406 // generate a CAM removal IRQ if we haven't already
407 if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
408 // CAM removal IRQ
409 budget_ci->slot_status = SLOTSTATUS_NONE;
410 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
411 DVB_CA_EN50221_CAMCHANGE_REMOVED);
412 }
413 }
414}
415
416static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
417{
418 struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
419 unsigned int flags;
420
421 // ensure we don't get spurious IRQs during initialisation
422 if (!budget_ci->budget.ci_present)
423 return -EINVAL;
424
425 // read the CAM status
426 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
427 if (flags & CICONTROL_CAMDETECT) {
428 // mark it as present if it wasn't before
429 if (budget_ci->slot_status & SLOTSTATUS_NONE) {
430 budget_ci->slot_status = SLOTSTATUS_PRESENT;
431 }
432
433 // during a RESET, we check if we can read from IO memory to see when CAM is ready
434 if (budget_ci->slot_status & SLOTSTATUS_RESET) {
435 if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
436 budget_ci->slot_status = SLOTSTATUS_READY;
437 }
438 }
439 } else {
440 budget_ci->slot_status = SLOTSTATUS_NONE;
441 }
442
443 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
444 if (budget_ci->slot_status & SLOTSTATUS_READY) {
445 return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
446 }
447 return DVB_CA_EN50221_POLL_CAM_PRESENT;
448 }
449
450 return 0;
451}
452
453static int ciintf_init(struct budget_ci *budget_ci)
454{
455 struct saa7146_dev *saa = budget_ci->budget.dev;
456 int flags;
457 int result;
458 int ci_version;
459 int ca_flags;
460
461 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
462
463 // enable DEBI pins
464 saa7146_write(saa, MC1, MASK_27 | MASK_11);
465
466 // test if it is there
467 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
468 if ((ci_version & 0xa0) != 0xa0) {
469 result = -ENODEV;
470 goto error;
471 }
472
473 // determine whether a CAM is present or not
474 flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
475 budget_ci->slot_status = SLOTSTATUS_NONE;
476 if (flags & CICONTROL_CAMDETECT)
477 budget_ci->slot_status = SLOTSTATUS_PRESENT;
478
479 // version 0xa2 of the CI firmware doesn't generate interrupts
480 if (ci_version == 0xa2) {
481 ca_flags = 0;
482 budget_ci->ci_irq = 0;
483 } else {
484 ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
485 DVB_CA_EN50221_FLAG_IRQ_FR |
486 DVB_CA_EN50221_FLAG_IRQ_DA;
487 budget_ci->ci_irq = 1;
488 }
489
490 // register CI interface
491 budget_ci->ca.owner = THIS_MODULE;
492 budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
493 budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
494 budget_ci->ca.read_cam_control = ciintf_read_cam_control;
495 budget_ci->ca.write_cam_control = ciintf_write_cam_control;
496 budget_ci->ca.slot_reset = ciintf_slot_reset;
497 budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
498 budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
499 budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
500 budget_ci->ca.data = budget_ci;
501 if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
502 &budget_ci->ca,
503 ca_flags, 1)) != 0) {
504 printk("budget_ci: CI interface detected, but initialisation failed.\n");
505 goto error;
506 }
507
508 // Setup CI slot IRQ
509 if (budget_ci->ci_irq) {
510 tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
511 if (budget_ci->slot_status != SLOTSTATUS_NONE) {
512 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
513 } else {
514 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
515 }
516 SAA7146_IER_ENABLE(saa, MASK_03);
517 }
518
519 // enable interface
520 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
521 CICONTROL_RESET, 1, 0);
522
523 // success!
524 printk("budget_ci: CI interface initialised\n");
525 budget_ci->budget.ci_present = 1;
526
527 // forge a fake CI IRQ so the CAM state is setup correctly
528 if (budget_ci->ci_irq) {
529 flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
530 if (budget_ci->slot_status != SLOTSTATUS_NONE)
531 flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
532 dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
533 }
534
535 return 0;
536
537error:
538 saa7146_write(saa, MC1, MASK_27);
539 return result;
540}
541
542static void ciintf_deinit(struct budget_ci *budget_ci)
543{
544 struct saa7146_dev *saa = budget_ci->budget.dev;
545
546 // disable CI interrupts
547 if (budget_ci->ci_irq) {
548 SAA7146_IER_DISABLE(saa, MASK_03);
549 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
550 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
551 }
552
553 // reset interface
554 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
555 msleep(1);
556 ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
557 CICONTROL_RESET, 1, 0);
558
559 // disable TS data stream to CI interface
560 saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
561
562 // release the CA device
563 dvb_ca_en50221_release(&budget_ci->ca);
564
565 // disable DEBI pins
566 saa7146_write(saa, MC1, MASK_27);
567}
568
569static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
570{
571 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
572
573 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
574
575 if (*isr & MASK_06)
576 tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
577
578 if (*isr & MASK_10)
579 ttpci_budget_irq10_handler(dev, isr);
580
581 if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
582 tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
583}
584
585static u8 philips_su1278_tt_inittab[] = {
586 0x01, 0x0f,
587 0x02, 0x30,
588 0x03, 0x00,
589 0x04, 0x5b,
590 0x05, 0x85,
591 0x06, 0x02,
592 0x07, 0x00,
593 0x08, 0x02,
594 0x09, 0x00,
595 0x0C, 0x01,
596 0x0D, 0x81,
597 0x0E, 0x44,
598 0x0f, 0x14,
599 0x10, 0x3c,
600 0x11, 0x84,
601 0x12, 0xda,
602 0x13, 0x97,
603 0x14, 0x95,
604 0x15, 0xc9,
605 0x16, 0x19,
606 0x17, 0x8c,
607 0x18, 0x59,
608 0x19, 0xf8,
609 0x1a, 0xfe,
610 0x1c, 0x7f,
611 0x1d, 0x00,
612 0x1e, 0x00,
613 0x1f, 0x50,
614 0x20, 0x00,
615 0x21, 0x00,
616 0x22, 0x00,
617 0x23, 0x00,
618 0x28, 0x00,
619 0x29, 0x28,
620 0x2a, 0x14,
621 0x2b, 0x0f,
622 0x2c, 0x09,
623 0x2d, 0x09,
624 0x31, 0x1f,
625 0x32, 0x19,
626 0x33, 0xfc,
627 0x34, 0x93,
628 0xff, 0xff
629};
630
631static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
632{
633 stv0299_writereg(fe, 0x0e, 0x44);
634 if (srate >= 10000000) {
635 stv0299_writereg(fe, 0x13, 0x97);
636 stv0299_writereg(fe, 0x14, 0x95);
637 stv0299_writereg(fe, 0x15, 0xc9);
638 stv0299_writereg(fe, 0x17, 0x8c);
639 stv0299_writereg(fe, 0x1a, 0xfe);
640 stv0299_writereg(fe, 0x1c, 0x7f);
641 stv0299_writereg(fe, 0x2d, 0x09);
642 } else {
643 stv0299_writereg(fe, 0x13, 0x99);
644 stv0299_writereg(fe, 0x14, 0x8d);
645 stv0299_writereg(fe, 0x15, 0xce);
646 stv0299_writereg(fe, 0x17, 0x43);
647 stv0299_writereg(fe, 0x1a, 0x1d);
648 stv0299_writereg(fe, 0x1c, 0x12);
649 stv0299_writereg(fe, 0x2d, 0x05);
650 }
651 stv0299_writereg(fe, 0x0e, 0x23);
652 stv0299_writereg(fe, 0x0f, 0x94);
653 stv0299_writereg(fe, 0x10, 0x39);
654 stv0299_writereg(fe, 0x15, 0xc9);
655
656 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
657 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
658 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
659
660 return 0;
661}
662
663static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe)
664{
665 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
666 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
667 u32 div;
668 u8 buf[4];
669 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
670
671 if ((p->frequency < 950000) || (p->frequency > 2150000))
672 return -EINVAL;
673
674 div = (p->frequency + (500 - 1)) / 500; /* round correctly */
675 buf[0] = (div >> 8) & 0x7f;
676 buf[1] = div & 0xff;
677 buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
678 buf[3] = 0x20;
679
680 if (p->symbol_rate < 4000000)
681 buf[3] |= 1;
682
683 if (p->frequency < 1250000)
684 buf[3] |= 0;
685 else if (p->frequency < 1550000)
686 buf[3] |= 0x40;
687 else if (p->frequency < 2050000)
688 buf[3] |= 0x80;
689 else if (p->frequency < 2150000)
690 buf[3] |= 0xC0;
691
692 if (fe->ops.i2c_gate_ctrl)
693 fe->ops.i2c_gate_ctrl(fe, 1);
694 if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
695 return -EIO;
696 return 0;
697}
698
699static struct stv0299_config philips_su1278_tt_config = {
700
701 .demod_address = 0x68,
702 .inittab = philips_su1278_tt_inittab,
703 .mclk = 64000000UL,
704 .invert = 0,
705 .skip_reinit = 1,
706 .lock_output = STV0299_LOCKOUTPUT_1,
707 .volt13_op0_op1 = STV0299_VOLT13_OP1,
708 .min_delay_ms = 50,
709 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
710};
711
712
713
714static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
715{
716 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
717 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
718 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
719 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
720 sizeof(td1316_init) };
721
722 // setup PLL configuration
723 if (fe->ops.i2c_gate_ctrl)
724 fe->ops.i2c_gate_ctrl(fe, 1);
725 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
726 return -EIO;
727 msleep(1);
728
729 // disable the mc44BC374c (do not check for errors)
730 tuner_msg.addr = 0x65;
731 tuner_msg.buf = disable_mc44BC374c;
732 tuner_msg.len = sizeof(disable_mc44BC374c);
733 if (fe->ops.i2c_gate_ctrl)
734 fe->ops.i2c_gate_ctrl(fe, 1);
735 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
736 if (fe->ops.i2c_gate_ctrl)
737 fe->ops.i2c_gate_ctrl(fe, 1);
738 i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
739 }
740
741 return 0;
742}
743
744static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
745{
746 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
747 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
748 u8 tuner_buf[4];
749 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
750 int tuner_frequency = 0;
751 u8 band, cp, filter;
752
753 // determine charge pump
754 tuner_frequency = p->frequency + 36130000;
755 if (tuner_frequency < 87000000)
756 return -EINVAL;
757 else if (tuner_frequency < 130000000)
758 cp = 3;
759 else if (tuner_frequency < 160000000)
760 cp = 5;
761 else if (tuner_frequency < 200000000)
762 cp = 6;
763 else if (tuner_frequency < 290000000)
764 cp = 3;
765 else if (tuner_frequency < 420000000)
766 cp = 5;
767 else if (tuner_frequency < 480000000)
768 cp = 6;
769 else if (tuner_frequency < 620000000)
770 cp = 3;
771 else if (tuner_frequency < 830000000)
772 cp = 5;
773 else if (tuner_frequency < 895000000)
774 cp = 7;
775 else
776 return -EINVAL;
777
778 // determine band
779 if (p->frequency < 49000000)
780 return -EINVAL;
781 else if (p->frequency < 159000000)
782 band = 1;
783 else if (p->frequency < 444000000)
784 band = 2;
785 else if (p->frequency < 861000000)
786 band = 4;
787 else
788 return -EINVAL;
789
790 // setup PLL filter and TDA9889
791 switch (p->bandwidth_hz) {
792 case 6000000:
793 tda1004x_writereg(fe, 0x0C, 0x14);
794 filter = 0;
795 break;
796
797 case 7000000:
798 tda1004x_writereg(fe, 0x0C, 0x80);
799 filter = 0;
800 break;
801
802 case 8000000:
803 tda1004x_writereg(fe, 0x0C, 0x14);
804 filter = 1;
805 break;
806
807 default:
808 return -EINVAL;
809 }
810
811 // calculate divisor
812 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
813 tuner_frequency = (((p->frequency / 1000) * 6) + 217280) / 1000;
814
815 // setup tuner buffer
816 tuner_buf[0] = tuner_frequency >> 8;
817 tuner_buf[1] = tuner_frequency & 0xff;
818 tuner_buf[2] = 0xca;
819 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
820
821 if (fe->ops.i2c_gate_ctrl)
822 fe->ops.i2c_gate_ctrl(fe, 1);
823 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
824 return -EIO;
825
826 msleep(1);
827 return 0;
828}
829
830static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
831 const struct firmware **fw, char *name)
832{
833 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
834
835 return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
836}
837
838static struct tda1004x_config philips_tdm1316l_config = {
839
840 .demod_address = 0x8,
841 .invert = 0,
842 .invert_oclk = 0,
843 .xtal_freq = TDA10046_XTAL_4M,
844 .agc_config = TDA10046_AGC_DEFAULT,
845 .if_freq = TDA10046_FREQ_3617,
846 .request_firmware = philips_tdm1316l_request_firmware,
847};
848
849static struct tda1004x_config philips_tdm1316l_config_invert = {
850
851 .demod_address = 0x8,
852 .invert = 1,
853 .invert_oclk = 0,
854 .xtal_freq = TDA10046_XTAL_4M,
855 .agc_config = TDA10046_AGC_DEFAULT,
856 .if_freq = TDA10046_FREQ_3617,
857 .request_firmware = philips_tdm1316l_request_firmware,
858};
859
860static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
861{
862 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
863 struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
864 u8 tuner_buf[5];
865 struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
866 .flags = 0,
867 .buf = tuner_buf,
868 .len = sizeof(tuner_buf) };
869 int tuner_frequency = 0;
870 u8 band, cp, filter;
871
872 // determine charge pump
873 tuner_frequency = p->frequency + 36125000;
874 if (tuner_frequency < 87000000)
875 return -EINVAL;
876 else if (tuner_frequency < 130000000) {
877 cp = 3;
878 band = 1;
879 } else if (tuner_frequency < 160000000) {
880 cp = 5;
881 band = 1;
882 } else if (tuner_frequency < 200000000) {
883 cp = 6;
884 band = 1;
885 } else if (tuner_frequency < 290000000) {
886 cp = 3;
887 band = 2;
888 } else if (tuner_frequency < 420000000) {
889 cp = 5;
890 band = 2;
891 } else if (tuner_frequency < 480000000) {
892 cp = 6;
893 band = 2;
894 } else if (tuner_frequency < 620000000) {
895 cp = 3;
896 band = 4;
897 } else if (tuner_frequency < 830000000) {
898 cp = 5;
899 band = 4;
900 } else if (tuner_frequency < 895000000) {
901 cp = 7;
902 band = 4;
903 } else
904 return -EINVAL;
905
906 // assume PLL filter should always be 8MHz for the moment.
907 filter = 1;
908
909 // calculate divisor
910 tuner_frequency = (p->frequency + 36125000 + (62500/2)) / 62500;
911
912 // setup tuner buffer
913 tuner_buf[0] = tuner_frequency >> 8;
914 tuner_buf[1] = tuner_frequency & 0xff;
915 tuner_buf[2] = 0xc8;
916 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
917 tuner_buf[4] = 0x80;
918
919 if (fe->ops.i2c_gate_ctrl)
920 fe->ops.i2c_gate_ctrl(fe, 1);
921 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
922 return -EIO;
923
924 msleep(50);
925
926 if (fe->ops.i2c_gate_ctrl)
927 fe->ops.i2c_gate_ctrl(fe, 1);
928 if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
929 return -EIO;
930
931 msleep(1);
932
933 return 0;
934}
935
936static u8 dvbc_philips_tdm1316l_inittab[] = {
937 0x80, 0x01,
938 0x80, 0x00,
939 0x81, 0x01,
940 0x81, 0x00,
941 0x00, 0x09,
942 0x01, 0x69,
943 0x03, 0x00,
944 0x04, 0x00,
945 0x07, 0x00,
946 0x08, 0x00,
947 0x20, 0x00,
948 0x21, 0x40,
949 0x22, 0x00,
950 0x23, 0x00,
951 0x24, 0x40,
952 0x25, 0x88,
953 0x30, 0xff,
954 0x31, 0x00,
955 0x32, 0xff,
956 0x33, 0x00,
957 0x34, 0x50,
958 0x35, 0x7f,
959 0x36, 0x00,
960 0x37, 0x20,
961 0x38, 0x00,
962 0x40, 0x1c,
963 0x41, 0xff,
964 0x42, 0x29,
965 0x43, 0x20,
966 0x44, 0xff,
967 0x45, 0x00,
968 0x46, 0x00,
969 0x49, 0x04,
970 0x4a, 0x00,
971 0x4b, 0x7b,
972 0x52, 0x30,
973 0x55, 0xae,
974 0x56, 0x47,
975 0x57, 0xe1,
976 0x58, 0x3a,
977 0x5a, 0x1e,
978 0x5b, 0x34,
979 0x60, 0x00,
980 0x63, 0x00,
981 0x64, 0x00,
982 0x65, 0x00,
983 0x66, 0x00,
984 0x67, 0x00,
985 0x68, 0x00,
986 0x69, 0x00,
987 0x6a, 0x02,
988 0x6b, 0x00,
989 0x70, 0xff,
990 0x71, 0x00,
991 0x72, 0x00,
992 0x73, 0x00,
993 0x74, 0x0c,
994 0x80, 0x00,
995 0x81, 0x00,
996 0x82, 0x00,
997 0x83, 0x00,
998 0x84, 0x04,
999 0x85, 0x80,
1000 0x86, 0x24,
1001 0x87, 0x78,
1002 0x88, 0x10,
1003 0x89, 0x00,
1004 0x90, 0x01,
1005 0x91, 0x01,
1006 0xa0, 0x04,
1007 0xa1, 0x00,
1008 0xa2, 0x00,
1009 0xb0, 0x91,
1010 0xb1, 0x0b,
1011 0xc0, 0x53,
1012 0xc1, 0x70,
1013 0xc2, 0x12,
1014 0xd0, 0x00,
1015 0xd1, 0x00,
1016 0xd2, 0x00,
1017 0xd3, 0x00,
1018 0xd4, 0x00,
1019 0xd5, 0x00,
1020 0xde, 0x00,
1021 0xdf, 0x00,
1022 0x61, 0x38,
1023 0x62, 0x0a,
1024 0x53, 0x13,
1025 0x59, 0x08,
1026 0xff, 0xff,
1027};
1028
1029static struct stv0297_config dvbc_philips_tdm1316l_config = {
1030 .demod_address = 0x1c,
1031 .inittab = dvbc_philips_tdm1316l_inittab,
1032 .invert = 0,
1033 .stop_during_read = 1,
1034};
1035
1036static struct tda10023_config tda10023_config = {
1037 .demod_address = 0xc,
1038 .invert = 0,
1039 .xtal = 16000000,
1040 .pll_m = 11,
1041 .pll_p = 3,
1042 .pll_n = 1,
1043 .deltaf = 0xa511,
1044};
1045
1046static struct tda827x_config tda827x_config = {
1047 .config = 0,
1048};
1049
1050/* TT S2-3200 DVB-S (STB0899) Inittab */
1051static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
1052
1053 { STB0899_DEV_ID , 0x81 },
1054 { STB0899_DISCNTRL1 , 0x32 },
1055 { STB0899_DISCNTRL2 , 0x80 },
1056 { STB0899_DISRX_ST0 , 0x04 },
1057 { STB0899_DISRX_ST1 , 0x00 },
1058 { STB0899_DISPARITY , 0x00 },
1059 { STB0899_DISSTATUS , 0x20 },
1060 { STB0899_DISF22 , 0x8c },
1061 { STB0899_DISF22RX , 0x9a },
1062 { STB0899_SYSREG , 0x0b },
1063 { STB0899_ACRPRESC , 0x11 },
1064 { STB0899_ACRDIV1 , 0x0a },
1065 { STB0899_ACRDIV2 , 0x05 },
1066 { STB0899_DACR1 , 0x00 },
1067 { STB0899_DACR2 , 0x00 },
1068 { STB0899_OUTCFG , 0x00 },
1069 { STB0899_MODECFG , 0x00 },
1070 { STB0899_IRQSTATUS_3 , 0x30 },
1071 { STB0899_IRQSTATUS_2 , 0x00 },
1072 { STB0899_IRQSTATUS_1 , 0x00 },
1073 { STB0899_IRQSTATUS_0 , 0x00 },
1074 { STB0899_IRQMSK_3 , 0xf3 },
1075 { STB0899_IRQMSK_2 , 0xfc },
1076 { STB0899_IRQMSK_1 , 0xff },
1077 { STB0899_IRQMSK_0 , 0xff },
1078 { STB0899_IRQCFG , 0x00 },
1079 { STB0899_I2CCFG , 0x88 },
1080 { STB0899_I2CRPT , 0x48 }, /* 12k Pullup, Repeater=16, Stop=disabled */
1081 { STB0899_IOPVALUE5 , 0x00 },
1082 { STB0899_IOPVALUE4 , 0x20 },
1083 { STB0899_IOPVALUE3 , 0xc9 },
1084 { STB0899_IOPVALUE2 , 0x90 },
1085 { STB0899_IOPVALUE1 , 0x40 },
1086 { STB0899_IOPVALUE0 , 0x00 },
1087 { STB0899_GPIO00CFG , 0x82 },
1088 { STB0899_GPIO01CFG , 0x82 },
1089 { STB0899_GPIO02CFG , 0x82 },
1090 { STB0899_GPIO03CFG , 0x82 },
1091 { STB0899_GPIO04CFG , 0x82 },
1092 { STB0899_GPIO05CFG , 0x82 },
1093 { STB0899_GPIO06CFG , 0x82 },
1094 { STB0899_GPIO07CFG , 0x82 },
1095 { STB0899_GPIO08CFG , 0x82 },
1096 { STB0899_GPIO09CFG , 0x82 },
1097 { STB0899_GPIO10CFG , 0x82 },
1098 { STB0899_GPIO11CFG , 0x82 },
1099 { STB0899_GPIO12CFG , 0x82 },
1100 { STB0899_GPIO13CFG , 0x82 },
1101 { STB0899_GPIO14CFG , 0x82 },
1102 { STB0899_GPIO15CFG , 0x82 },
1103 { STB0899_GPIO16CFG , 0x82 },
1104 { STB0899_GPIO17CFG , 0x82 },
1105 { STB0899_GPIO18CFG , 0x82 },
1106 { STB0899_GPIO19CFG , 0x82 },
1107 { STB0899_GPIO20CFG , 0x82 },
1108 { STB0899_SDATCFG , 0xb8 },
1109 { STB0899_SCLTCFG , 0xba },
1110 { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */
1111 { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
1112 { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
1113 { STB0899_DIRCLKCFG , 0x82 },
1114 { STB0899_CLKOUT27CFG , 0x7e },
1115 { STB0899_STDBYCFG , 0x82 },
1116 { STB0899_CS0CFG , 0x82 },
1117 { STB0899_CS1CFG , 0x82 },
1118 { STB0899_DISEQCOCFG , 0x20 },
1119 { STB0899_GPIO32CFG , 0x82 },
1120 { STB0899_GPIO33CFG , 0x82 },
1121 { STB0899_GPIO34CFG , 0x82 },
1122 { STB0899_GPIO35CFG , 0x82 },
1123 { STB0899_GPIO36CFG , 0x82 },
1124 { STB0899_GPIO37CFG , 0x82 },
1125 { STB0899_GPIO38CFG , 0x82 },
1126 { STB0899_GPIO39CFG , 0x82 },
1127 { STB0899_NCOARSE , 0x15 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
1128 { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
1129 { STB0899_FILTCTRL , 0x00 },
1130 { STB0899_SYSCTRL , 0x00 },
1131 { STB0899_STOPCLK1 , 0x20 },
1132 { STB0899_STOPCLK2 , 0x00 },
1133 { STB0899_INTBUFSTATUS , 0x00 },
1134 { STB0899_INTBUFCTRL , 0x0a },
1135 { 0xffff , 0xff },
1136};
1137
1138static const struct stb0899_s1_reg tt3200_stb0899_s1_init_3[] = {
1139 { STB0899_DEMOD , 0x00 },
1140 { STB0899_RCOMPC , 0xc9 },
1141 { STB0899_AGC1CN , 0x41 },
1142 { STB0899_AGC1REF , 0x10 },
1143 { STB0899_RTC , 0x7a },
1144 { STB0899_TMGCFG , 0x4e },
1145 { STB0899_AGC2REF , 0x34 },
1146 { STB0899_TLSR , 0x84 },
1147 { STB0899_CFD , 0xc7 },
1148 { STB0899_ACLC , 0x87 },
1149 { STB0899_BCLC , 0x94 },
1150 { STB0899_EQON , 0x41 },
1151 { STB0899_LDT , 0xdd },
1152 { STB0899_LDT2 , 0xc9 },
1153 { STB0899_EQUALREF , 0xb4 },
1154 { STB0899_TMGRAMP , 0x10 },
1155 { STB0899_TMGTHD , 0x30 },
1156 { STB0899_IDCCOMP , 0xfb },
1157 { STB0899_QDCCOMP , 0x03 },
1158 { STB0899_POWERI , 0x3b },
1159 { STB0899_POWERQ , 0x3d },
1160 { STB0899_RCOMP , 0x81 },
1161 { STB0899_AGCIQIN , 0x80 },
1162 { STB0899_AGC2I1 , 0x04 },
1163 { STB0899_AGC2I2 , 0xf5 },
1164 { STB0899_TLIR , 0x25 },
1165 { STB0899_RTF , 0x80 },
1166 { STB0899_DSTATUS , 0x00 },
1167 { STB0899_LDI , 0xca },
1168 { STB0899_CFRM , 0xf1 },
1169 { STB0899_CFRL , 0xf3 },
1170 { STB0899_NIRM , 0x2a },
1171 { STB0899_NIRL , 0x05 },
1172 { STB0899_ISYMB , 0x17 },
1173 { STB0899_QSYMB , 0xfa },
1174 { STB0899_SFRH , 0x2f },
1175 { STB0899_SFRM , 0x68 },
1176 { STB0899_SFRL , 0x40 },
1177 { STB0899_SFRUPH , 0x2f },
1178 { STB0899_SFRUPM , 0x68 },
1179 { STB0899_SFRUPL , 0x40 },
1180 { STB0899_EQUAI1 , 0xfd },
1181 { STB0899_EQUAQ1 , 0x04 },
1182 { STB0899_EQUAI2 , 0x0f },
1183 { STB0899_EQUAQ2 , 0xff },
1184 { STB0899_EQUAI3 , 0xdf },
1185 { STB0899_EQUAQ3 , 0xfa },
1186 { STB0899_EQUAI4 , 0x37 },
1187 { STB0899_EQUAQ4 , 0x0d },
1188 { STB0899_EQUAI5 , 0xbd },
1189 { STB0899_EQUAQ5 , 0xf7 },
1190 { STB0899_DSTATUS2 , 0x00 },
1191 { STB0899_VSTATUS , 0x00 },
1192 { STB0899_VERROR , 0xff },
1193 { STB0899_IQSWAP , 0x2a },
1194 { STB0899_ECNT1M , 0x00 },
1195 { STB0899_ECNT1L , 0x00 },
1196 { STB0899_ECNT2M , 0x00 },
1197 { STB0899_ECNT2L , 0x00 },
1198 { STB0899_ECNT3M , 0x00 },
1199 { STB0899_ECNT3L , 0x00 },
1200 { STB0899_FECAUTO1 , 0x06 },
1201 { STB0899_FECM , 0x01 },
1202 { STB0899_VTH12 , 0xf0 },
1203 { STB0899_VTH23 , 0xa0 },
1204 { STB0899_VTH34 , 0x78 },
1205 { STB0899_VTH56 , 0x4e },
1206 { STB0899_VTH67 , 0x48 },
1207 { STB0899_VTH78 , 0x38 },
1208 { STB0899_PRVIT , 0xff },
1209 { STB0899_VITSYNC , 0x19 },
1210 { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
1211 { STB0899_TSULC , 0x42 },
1212 { STB0899_RSLLC , 0x40 },
1213 { STB0899_TSLPL , 0x12 },
1214 { STB0899_TSCFGH , 0x0c },
1215 { STB0899_TSCFGM , 0x00 },
1216 { STB0899_TSCFGL , 0x0c },
1217 { STB0899_TSOUT , 0x4d }, /* 0x0d for CAM */
1218 { STB0899_RSSYNCDEL , 0x00 },
1219 { STB0899_TSINHDELH , 0x02 },
1220 { STB0899_TSINHDELM , 0x00 },
1221 { STB0899_TSINHDELL , 0x00 },
1222 { STB0899_TSLLSTKM , 0x00 },
1223 { STB0899_TSLLSTKL , 0x00 },
1224 { STB0899_TSULSTKM , 0x00 },
1225 { STB0899_TSULSTKL , 0xab },
1226 { STB0899_PCKLENUL , 0x00 },
1227 { STB0899_PCKLENLL , 0xcc },
1228 { STB0899_RSPCKLEN , 0xcc },
1229 { STB0899_TSSTATUS , 0x80 },
1230 { STB0899_ERRCTRL1 , 0xb6 },
1231 { STB0899_ERRCTRL2 , 0x96 },
1232 { STB0899_ERRCTRL3 , 0x89 },
1233 { STB0899_DMONMSK1 , 0x27 },
1234 { STB0899_DMONMSK0 , 0x03 },
1235 { STB0899_DEMAPVIT , 0x5c },
1236 { STB0899_PLPARM , 0x1f },
1237 { STB0899_PDELCTRL , 0x48 },
1238 { STB0899_PDELCTRL2 , 0x00 },
1239 { STB0899_BBHCTRL1 , 0x00 },
1240 { STB0899_BBHCTRL2 , 0x00 },
1241 { STB0899_HYSTTHRESH , 0x77 },
1242 { STB0899_MATCSTM , 0x00 },
1243 { STB0899_MATCSTL , 0x00 },
1244 { STB0899_UPLCSTM , 0x00 },
1245 { STB0899_UPLCSTL , 0x00 },
1246 { STB0899_DFLCSTM , 0x00 },
1247 { STB0899_DFLCSTL , 0x00 },
1248 { STB0899_SYNCCST , 0x00 },
1249 { STB0899_SYNCDCSTM , 0x00 },
1250 { STB0899_SYNCDCSTL , 0x00 },
1251 { STB0899_ISI_ENTRY , 0x00 },
1252 { STB0899_ISI_BIT_EN , 0x00 },
1253 { STB0899_MATSTRM , 0x00 },
1254 { STB0899_MATSTRL , 0x00 },
1255 { STB0899_UPLSTRM , 0x00 },
1256 { STB0899_UPLSTRL , 0x00 },
1257 { STB0899_DFLSTRM , 0x00 },
1258 { STB0899_DFLSTRL , 0x00 },
1259 { STB0899_SYNCSTR , 0x00 },
1260 { STB0899_SYNCDSTRM , 0x00 },
1261 { STB0899_SYNCDSTRL , 0x00 },
1262 { STB0899_CFGPDELSTATUS1 , 0x10 },
1263 { STB0899_CFGPDELSTATUS2 , 0x00 },
1264 { STB0899_BBFERRORM , 0x00 },
1265 { STB0899_BBFERRORL , 0x00 },
1266 { STB0899_UPKTERRORM , 0x00 },
1267 { STB0899_UPKTERRORL , 0x00 },
1268 { 0xffff , 0xff },
1269};
1270
1271static struct stb0899_config tt3200_config = {
1272 .init_dev = tt3200_stb0899_s1_init_1,
1273 .init_s2_demod = stb0899_s2_init_2,
1274 .init_s1_demod = tt3200_stb0899_s1_init_3,
1275 .init_s2_fec = stb0899_s2_init_4,
1276 .init_tst = stb0899_s1_init_5,
1277
1278 .postproc = NULL,
1279
1280 .demod_address = 0x68,
1281
1282 .xtal_freq = 27000000,
1283 .inversion = IQ_SWAP_ON, /* 1 */
1284
1285 .lo_clk = 76500000,
1286 .hi_clk = 99000000,
1287
1288 .esno_ave = STB0899_DVBS2_ESNO_AVE,
1289 .esno_quant = STB0899_DVBS2_ESNO_QUANT,
1290 .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
1291 .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
1292 .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
1293 .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
1294 .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
1295 .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
1296 .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
1297
1298 .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
1299 .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
1300 .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
1301 .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
1302
1303 .tuner_get_frequency = stb6100_get_frequency,
1304 .tuner_set_frequency = stb6100_set_frequency,
1305 .tuner_set_bandwidth = stb6100_set_bandwidth,
1306 .tuner_get_bandwidth = stb6100_get_bandwidth,
1307 .tuner_set_rfsiggain = NULL
1308};
1309
1310static struct stb6100_config tt3200_stb6100_config = {
1311 .tuner_address = 0x60,
1312 .refclock = 27000000,
1313};
1314
1315static void frontend_init(struct budget_ci *budget_ci)
1316{
1317 switch (budget_ci->budget.dev->pci->subsystem_device) {
1318 case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
1319 budget_ci->budget.dvb_frontend =
1320 dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
1321 if (budget_ci->budget.dvb_frontend) {
1322 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
1323 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1324 break;
1325 }
1326 break;
1327
1328 case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
1329 budget_ci->budget.dvb_frontend =
1330 dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
1331 if (budget_ci->budget.dvb_frontend) {
1332 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
1333 break;
1334 }
1335 break;
1336
1337 case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
1338 budget_ci->tuner_pll_address = 0x61;
1339 budget_ci->budget.dvb_frontend =
1340 dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1341 if (budget_ci->budget.dvb_frontend) {
1342 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
1343 break;
1344 }
1345 break;
1346
1347 case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
1348 budget_ci->tuner_pll_address = 0x63;
1349 budget_ci->budget.dvb_frontend =
1350 dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
1351 if (budget_ci->budget.dvb_frontend) {
1352 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1353 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1354 break;
1355 }
1356 break;
1357
1358 case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
1359 budget_ci->tuner_pll_address = 0x60;
1360 budget_ci->budget.dvb_frontend =
1361 dvb_attach(tda10046_attach, &philips_tdm1316l_config_invert, &budget_ci->budget.i2c_adap);
1362 if (budget_ci->budget.dvb_frontend) {
1363 budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
1364 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
1365 break;
1366 }
1367 break;
1368
1369 case 0x1017: // TT S-1500 PCI
1370 budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
1371 if (budget_ci->budget.dvb_frontend) {
1372 budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
1373 budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
1374
1375 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1376 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
1377 printk("%s: No LNBP21 found!\n", __func__);
1378 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1379 budget_ci->budget.dvb_frontend = NULL;
1380 }
1381 }
1382 break;
1383
1384 case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */
1385 budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48);
1386 if (budget_ci->budget.dvb_frontend) {
1387 if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, &tda827x_config) == NULL) {
1388 printk(KERN_ERR "%s: No tda827x found!\n", __func__);
1389 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1390 budget_ci->budget.dvb_frontend = NULL;
1391 }
1392 }
1393 break;
1394
1395 case 0x101b: /* TT S-1500B (BSBE1-D01A - STV0288/STB6000/LNBP21) */
1396 budget_ci->budget.dvb_frontend = dvb_attach(stv0288_attach, &stv0288_bsbe1_d01a_config, &budget_ci->budget.i2c_adap);
1397 if (budget_ci->budget.dvb_frontend) {
1398 if (dvb_attach(stb6000_attach, budget_ci->budget.dvb_frontend, 0x63, &budget_ci->budget.i2c_adap)) {
1399 if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
1400 printk(KERN_ERR "%s: No LNBP21 found!\n", __func__);
1401 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1402 budget_ci->budget.dvb_frontend = NULL;
1403 }
1404 } else {
1405 printk(KERN_ERR "%s: No STB6000 found!\n", __func__);
1406 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1407 budget_ci->budget.dvb_frontend = NULL;
1408 }
1409 }
1410 break;
1411
1412 case 0x1019: // TT S2-3200 PCI
1413 /*
1414 * NOTE! on some STB0899 versions, the internal PLL takes a longer time
1415 * to settle, aka LOCK. On the older revisions of the chip, we don't see
1416 * this, as a result on the newer chips the entire clock tree, will not
1417 * be stable after a freshly POWER 'ed up situation.
1418 * In this case, we should RESET the STB0899 (Active LOW) and wait for
1419 * PLL stabilization.
1420 *
1421 * On the TT S2 3200 and clones, the STB0899 demodulator's RESETB is
1422 * connected to the SAA7146 GPIO, GPIO2, Pin 142
1423 */
1424 /* Reset Demodulator */
1425 saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTLO);
1426 /* Wait for everything to die */
1427 msleep(50);
1428 /* Pull it up out of Reset state */
1429 saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTHI);
1430 /* Wait for PLL to stabilize */
1431 msleep(250);
1432 /*
1433 * PLL state should be stable now. Ideally, we should check
1434 * for PLL LOCK status. But well, never mind!
1435 */
1436 budget_ci->budget.dvb_frontend = dvb_attach(stb0899_attach, &tt3200_config, &budget_ci->budget.i2c_adap);
1437 if (budget_ci->budget.dvb_frontend) {
1438 if (dvb_attach(stb6100_attach, budget_ci->budget.dvb_frontend, &tt3200_stb6100_config, &budget_ci->budget.i2c_adap)) {
1439 if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
1440 printk("%s: No LNBP21 found!\n", __func__);
1441 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1442 budget_ci->budget.dvb_frontend = NULL;
1443 }
1444 } else {
1445 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1446 budget_ci->budget.dvb_frontend = NULL;
1447 }
1448 }
1449 break;
1450
1451 }
1452
1453 if (budget_ci->budget.dvb_frontend == NULL) {
1454 printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
1455 budget_ci->budget.dev->pci->vendor,
1456 budget_ci->budget.dev->pci->device,
1457 budget_ci->budget.dev->pci->subsystem_vendor,
1458 budget_ci->budget.dev->pci->subsystem_device);
1459 } else {
1460 if (dvb_register_frontend
1461 (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
1462 printk("budget-ci: Frontend registration failed!\n");
1463 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1464 budget_ci->budget.dvb_frontend = NULL;
1465 }
1466 }
1467}
1468
1469static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
1470{
1471 struct budget_ci *budget_ci;
1472 int err;
1473
1474 budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
1475 if (!budget_ci) {
1476 err = -ENOMEM;
1477 goto out1;
1478 }
1479
1480 dprintk(2, "budget_ci: %p\n", budget_ci);
1481
1482 dev->ext_priv = budget_ci;
1483
1484 err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
1485 adapter_nr);
1486 if (err)
1487 goto out2;
1488
1489 err = msp430_ir_init(budget_ci);
1490 if (err)
1491 goto out3;
1492
1493 ciintf_init(budget_ci);
1494
1495 budget_ci->budget.dvb_adapter.priv = budget_ci;
1496 frontend_init(budget_ci);
1497
1498 ttpci_budget_init_hooks(&budget_ci->budget);
1499
1500 return 0;
1501
1502out3:
1503 ttpci_budget_deinit(&budget_ci->budget);
1504out2:
1505 kfree(budget_ci);
1506out1:
1507 return err;
1508}
1509
1510static int budget_ci_detach(struct saa7146_dev *dev)
1511{
1512 struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
1513 struct saa7146_dev *saa = budget_ci->budget.dev;
1514 int err;
1515
1516 if (budget_ci->budget.ci_present)
1517 ciintf_deinit(budget_ci);
1518 msp430_ir_deinit(budget_ci);
1519 if (budget_ci->budget.dvb_frontend) {
1520 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1521 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1522 }
1523 err = ttpci_budget_deinit(&budget_ci->budget);
1524
1525 // disable frontend and CI interface
1526 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
1527
1528 kfree(budget_ci);
1529
1530 return err;
1531}
1532
1533static struct saa7146_extension budget_extension;
1534
1535MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
1536MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
1537MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
1538MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1539MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
1540MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT);
1541MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
1542MAKE_BUDGET_INFO(ttbs1500b, "TT-Budget S-1500B PCI", BUDGET_TT);
1543
1544static struct pci_device_id pci_tbl[] = {
1545 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
1546 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
1547 MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
1548 MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
1549 MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
1550 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1551 MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a),
1552 MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019),
1553 MAKE_EXTENSION_PCI(ttbs1500b, 0x13c2, 0x101b),
1554 {
1555 .vendor = 0,
1556 }
1557};
1558
1559MODULE_DEVICE_TABLE(pci, pci_tbl);
1560
1561static struct saa7146_extension budget_extension = {
1562 .name = "budget_ci dvb",
1563 .flags = SAA7146_USE_I2C_IRQ,
1564
1565 .module = THIS_MODULE,
1566 .pci_tbl = &pci_tbl[0],
1567 .attach = budget_ci_attach,
1568 .detach = budget_ci_detach,
1569
1570 .irq_mask = MASK_03 | MASK_06 | MASK_10,
1571 .irq_func = budget_ci_irq,
1572};
1573
1574static int __init budget_ci_init(void)
1575{
1576 return saa7146_register_extension(&budget_extension);
1577}
1578
1579static void __exit budget_ci_exit(void)
1580{
1581 saa7146_unregister_extension(&budget_extension);
1582}
1583
1584module_init(budget_ci_init);
1585module_exit(budget_ci_exit);
1586
1587MODULE_LICENSE("GPL");
1588MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
1589MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
1590 "budget PCI DVB cards w/ CI-module produced by "
1591 "Siemens, Technotrend, Hauppauge");
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
deleted file mode 100644
index 37d02fe09137..000000000000
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ /dev/null
@@ -1,602 +0,0 @@
1/*
2 * budget-core.c: driver for the SAA7146 based Budget DVB cards
3 *
4 * Compiled from various sources by Michael Hunold <michael@mihu.de>
5 *
6 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
7 *
8 * Copyright (C) 1999-2002 Ralph Metzler
9 * & Marcus Metzler for convergence integrated media GmbH
10 *
11 * 26feb2004 Support for FS Activy Card (Grundig tuner) by
12 * Michael Dreher <michael@5dot1.de>,
13 * Oliver Endriss <o.endriss@gmx.de>,
14 * Andreas 'randy' Weinberger
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
20 *
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
32 *
33 *
34 * the project's page is at http://www.linuxtv.org/
35 */
36
37
38#include "budget.h"
39#include "ttpci-eeprom.h"
40
41#define TS_WIDTH (2 * TS_SIZE)
42#define TS_WIDTH_ACTIVY TS_SIZE
43#define TS_WIDTH_DVBC TS_SIZE
44#define TS_HEIGHT_MASK 0xf00
45#define TS_HEIGHT_MASK_ACTIVY 0xc00
46#define TS_HEIGHT_MASK_DVBC 0xe00
47#define TS_MIN_BUFSIZE_K 188
48#define TS_MAX_BUFSIZE_K 1410
49#define TS_MAX_BUFSIZE_K_ACTIVY 564
50#define TS_MAX_BUFSIZE_K_DVBC 1316
51#define BUFFER_WARNING_WAIT (30*HZ)
52
53int budget_debug;
54static int dma_buffer_size = TS_MIN_BUFSIZE_K;
55module_param_named(debug, budget_debug, int, 0644);
56module_param_named(bufsize, dma_buffer_size, int, 0444);
57MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
58MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
59
60/****************************************************************************
61 * TT budget / WinTV Nova
62 ****************************************************************************/
63
64static int stop_ts_capture(struct budget *budget)
65{
66 dprintk(2, "budget: %p\n", budget);
67
68 saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off
69 SAA7146_IER_DISABLE(budget->dev, MASK_10);
70 return 0;
71}
72
73static int start_ts_capture(struct budget *budget)
74{
75 struct saa7146_dev *dev = budget->dev;
76
77 dprintk(2, "budget: %p\n", budget);
78
79 if (!budget->feeding || !budget->fe_synced)
80 return 0;
81
82 saa7146_write(dev, MC1, MASK_20); // DMA3 off
83
84 memset(budget->grabbing, 0x00, budget->buffer_size);
85
86 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
87
88 budget->ttbp = 0;
89
90 /*
91 * Signal path on the Activy:
92 *
93 * tuner -> SAA7146 port A -> SAA7146 BRS -> SAA7146 DMA3 -> memory
94 *
95 * Since the tuner feeds 204 bytes packets into the SAA7146,
96 * DMA3 is configured to strip the trailing 16 FEC bytes:
97 * Pitch: 188, NumBytes3: 188, NumLines3: 1024
98 */
99
100 switch(budget->card->type) {
101 case BUDGET_FS_ACTIVY:
102 saa7146_write(dev, DD1_INIT, 0x04000000);
103 saa7146_write(dev, MC2, (MASK_09 | MASK_25));
104 saa7146_write(dev, BRS_CTRL, 0x00000000);
105 break;
106 case BUDGET_PATCH:
107 saa7146_write(dev, DD1_INIT, 0x00000200);
108 saa7146_write(dev, MC2, (MASK_10 | MASK_26));
109 saa7146_write(dev, BRS_CTRL, 0x60000000);
110 break;
111 case BUDGET_CIN1200C_MK3:
112 case BUDGET_KNC1C_MK3:
113 case BUDGET_KNC1C_TDA10024:
114 case BUDGET_KNC1CP_MK3:
115 if (budget->video_port == BUDGET_VIDEO_PORTA) {
116 saa7146_write(dev, DD1_INIT, 0x06000200);
117 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
118 saa7146_write(dev, BRS_CTRL, 0x00000000);
119 } else {
120 saa7146_write(dev, DD1_INIT, 0x00000600);
121 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
122 saa7146_write(dev, BRS_CTRL, 0x60000000);
123 }
124 break;
125 default:
126 if (budget->video_port == BUDGET_VIDEO_PORTA) {
127 saa7146_write(dev, DD1_INIT, 0x06000200);
128 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
129 saa7146_write(dev, BRS_CTRL, 0x00000000);
130 } else {
131 saa7146_write(dev, DD1_INIT, 0x02000600);
132 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
133 saa7146_write(dev, BRS_CTRL, 0x60000000);
134 }
135 }
136
137 saa7146_write(dev, MC2, (MASK_08 | MASK_24));
138 mdelay(10);
139
140 saa7146_write(dev, BASE_ODD3, 0);
141 if (budget->buffer_size > budget->buffer_height * budget->buffer_width) {
142 // using odd/even buffers
143 saa7146_write(dev, BASE_EVEN3, budget->buffer_height * budget->buffer_width);
144 } else {
145 // using a single buffer
146 saa7146_write(dev, BASE_EVEN3, 0);
147 }
148 saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
149 saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);
150
151 saa7146_write(dev, PITCH3, budget->buffer_width);
152 saa7146_write(dev, NUM_LINE_BYTE3,
153 (budget->buffer_height << 16) | budget->buffer_width);
154
155 saa7146_write(dev, MC2, (MASK_04 | MASK_20));
156
157 SAA7146_ISR_CLEAR(budget->dev, MASK_10); /* VPE */
158 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
159 saa7146_write(dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */
160
161 return 0;
162}
163
164static int budget_read_fe_status(struct dvb_frontend *fe, fe_status_t *status)
165{
166 struct budget *budget = (struct budget *) fe->dvb->priv;
167 int synced;
168 int ret;
169
170 if (budget->read_fe_status)
171 ret = budget->read_fe_status(fe, status);
172 else
173 ret = -EINVAL;
174
175 if (!ret) {
176 synced = (*status & FE_HAS_LOCK);
177 if (synced != budget->fe_synced) {
178 budget->fe_synced = synced;
179 spin_lock(&budget->feedlock);
180 if (synced)
181 start_ts_capture(budget);
182 else
183 stop_ts_capture(budget);
184 spin_unlock(&budget->feedlock);
185 }
186 }
187 return ret;
188}
189
190static void vpeirq(unsigned long data)
191{
192 struct budget *budget = (struct budget *) data;
193 u8 *mem = (u8 *) (budget->grabbing);
194 u32 olddma = budget->ttbp;
195 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
196 u32 count;
197
198 /* Ensure streamed PCI data is synced to CPU */
199 pci_dma_sync_sg_for_cpu(budget->dev->pci, budget->pt.slist, budget->pt.nents, PCI_DMA_FROMDEVICE);
200
201 /* nearest lower position divisible by 188 */
202 newdma -= newdma % 188;
203
204 if (newdma >= budget->buffer_size)
205 return;
206
207 budget->ttbp = newdma;
208
209 if (budget->feeding == 0 || newdma == olddma)
210 return;
211
212 if (newdma > olddma) { /* no wraparound, dump olddma..newdma */
213 count = newdma - olddma;
214 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
215 } else { /* wraparound, dump olddma..buflen and 0..newdma */
216 count = budget->buffer_size - olddma;
217 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
218 count += newdma;
219 dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188);
220 }
221
222 if (count > budget->buffer_warning_threshold)
223 budget->buffer_warnings++;
224
225 if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) {
226 printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n",
227 budget->dev->name, __func__, budget->buffer_warnings, count);
228 budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT;
229 budget->buffer_warnings = 0;
230 }
231}
232
233
234int ttpci_budget_debiread(struct budget *budget, u32 config, int addr, int count,
235 int uselocks, int nobusyloop)
236{
237 struct saa7146_dev *saa = budget->dev;
238 int result = 0;
239 unsigned long flags = 0;
240
241 if (count > 4 || count <= 0)
242 return 0;
243
244 if (uselocks)
245 spin_lock_irqsave(&budget->debilock, flags);
246
247 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
248 if (uselocks)
249 spin_unlock_irqrestore(&budget->debilock, flags);
250 return result;
251 }
252
253 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
254 saa7146_write(saa, DEBI_CONFIG, config);
255 saa7146_write(saa, DEBI_PAGE, 0);
256 saa7146_write(saa, MC2, (2 << 16) | 2);
257
258 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
259 if (uselocks)
260 spin_unlock_irqrestore(&budget->debilock, flags);
261 return result;
262 }
263
264 result = saa7146_read(saa, DEBI_AD);
265 result &= (0xffffffffUL >> ((4 - count) * 8));
266
267 if (uselocks)
268 spin_unlock_irqrestore(&budget->debilock, flags);
269
270 return result;
271}
272
273int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr,
274 int count, u32 value, int uselocks, int nobusyloop)
275{
276 struct saa7146_dev *saa = budget->dev;
277 unsigned long flags = 0;
278 int result;
279
280 if (count > 4 || count <= 0)
281 return 0;
282
283 if (uselocks)
284 spin_lock_irqsave(&budget->debilock, flags);
285
286 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
287 if (uselocks)
288 spin_unlock_irqrestore(&budget->debilock, flags);
289 return result;
290 }
291
292 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x00000 | (addr & 0xffff));
293 saa7146_write(saa, DEBI_CONFIG, config);
294 saa7146_write(saa, DEBI_PAGE, 0);
295 saa7146_write(saa, DEBI_AD, value);
296 saa7146_write(saa, MC2, (2 << 16) | 2);
297
298 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) {
299 if (uselocks)
300 spin_unlock_irqrestore(&budget->debilock, flags);
301 return result;
302 }
303
304 if (uselocks)
305 spin_unlock_irqrestore(&budget->debilock, flags);
306 return 0;
307}
308
309
310/****************************************************************************
311 * DVB API SECTION
312 ****************************************************************************/
313
314static int budget_start_feed(struct dvb_demux_feed *feed)
315{
316 struct dvb_demux *demux = feed->demux;
317 struct budget *budget = (struct budget *) demux->priv;
318 int status = 0;
319
320 dprintk(2, "budget: %p\n", budget);
321
322 if (!demux->dmx.frontend)
323 return -EINVAL;
324
325 spin_lock(&budget->feedlock);
326 feed->pusi_seen = 0; /* have a clean section start */
327 if (budget->feeding++ == 0)
328 status = start_ts_capture(budget);
329 spin_unlock(&budget->feedlock);
330 return status;
331}
332
333static int budget_stop_feed(struct dvb_demux_feed *feed)
334{
335 struct dvb_demux *demux = feed->demux;
336 struct budget *budget = (struct budget *) demux->priv;
337 int status = 0;
338
339 dprintk(2, "budget: %p\n", budget);
340
341 spin_lock(&budget->feedlock);
342 if (--budget->feeding == 0)
343 status = stop_ts_capture(budget);
344 spin_unlock(&budget->feedlock);
345 return status;
346}
347
348static int budget_register(struct budget *budget)
349{
350 struct dvb_demux *dvbdemux = &budget->demux;
351 int ret;
352
353 dprintk(2, "budget: %p\n", budget);
354
355 dvbdemux->priv = (void *) budget;
356
357 dvbdemux->filternum = 256;
358 dvbdemux->feednum = 256;
359 dvbdemux->start_feed = budget_start_feed;
360 dvbdemux->stop_feed = budget_stop_feed;
361 dvbdemux->write_to_decoder = NULL;
362
363 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING |
364 DMX_MEMORY_BASED_FILTERING);
365
366 dvb_dmx_init(&budget->demux);
367
368 budget->dmxdev.filternum = 256;
369 budget->dmxdev.demux = &dvbdemux->dmx;
370 budget->dmxdev.capabilities = 0;
371
372 dvb_dmxdev_init(&budget->dmxdev, &budget->dvb_adapter);
373
374 budget->hw_frontend.source = DMX_FRONTEND_0;
375
376 ret = dvbdemux->dmx.add_frontend(&dvbdemux->dmx, &budget->hw_frontend);
377
378 if (ret < 0)
379 return ret;
380
381 budget->mem_frontend.source = DMX_MEMORY_FE;
382 ret = dvbdemux->dmx.add_frontend(&dvbdemux->dmx, &budget->mem_frontend);
383 if (ret < 0)
384 return ret;
385
386 ret = dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, &budget->hw_frontend);
387 if (ret < 0)
388 return ret;
389
390 dvb_net_init(&budget->dvb_adapter, &budget->dvb_net, &dvbdemux->dmx);
391
392 return 0;
393}
394
395static void budget_unregister(struct budget *budget)
396{
397 struct dvb_demux *dvbdemux = &budget->demux;
398
399 dprintk(2, "budget: %p\n", budget);
400
401 dvb_net_release(&budget->dvb_net);
402
403 dvbdemux->dmx.close(&dvbdemux->dmx);
404 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &budget->hw_frontend);
405 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &budget->mem_frontend);
406
407 dvb_dmxdev_release(&budget->dmxdev);
408 dvb_dmx_release(&budget->demux);
409}
410
411int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
412 struct saa7146_pci_extension_data *info,
413 struct module *owner, short *adapter_nums)
414{
415 int ret = 0;
416 struct budget_info *bi = info->ext_priv;
417 int max_bufsize;
418 int height_mask;
419
420 memset(budget, 0, sizeof(struct budget));
421
422 dprintk(2, "dev: %p, budget: %p\n", dev, budget);
423
424 budget->card = bi;
425 budget->dev = (struct saa7146_dev *) dev;
426
427 switch(budget->card->type) {
428 case BUDGET_FS_ACTIVY:
429 budget->buffer_width = TS_WIDTH_ACTIVY;
430 max_bufsize = TS_MAX_BUFSIZE_K_ACTIVY;
431 height_mask = TS_HEIGHT_MASK_ACTIVY;
432 break;
433
434 case BUDGET_KNC1C:
435 case BUDGET_KNC1CP:
436 case BUDGET_CIN1200C:
437 case BUDGET_KNC1C_MK3:
438 case BUDGET_KNC1C_TDA10024:
439 case BUDGET_KNC1CP_MK3:
440 case BUDGET_CIN1200C_MK3:
441 budget->buffer_width = TS_WIDTH_DVBC;
442 max_bufsize = TS_MAX_BUFSIZE_K_DVBC;
443 height_mask = TS_HEIGHT_MASK_DVBC;
444 break;
445
446 default:
447 budget->buffer_width = TS_WIDTH;
448 max_bufsize = TS_MAX_BUFSIZE_K;
449 height_mask = TS_HEIGHT_MASK;
450 }
451
452 if (dma_buffer_size < TS_MIN_BUFSIZE_K)
453 dma_buffer_size = TS_MIN_BUFSIZE_K;
454 else if (dma_buffer_size > max_bufsize)
455 dma_buffer_size = max_bufsize;
456
457 budget->buffer_height = dma_buffer_size * 1024 / budget->buffer_width;
458 if (budget->buffer_height > 0xfff) {
459 budget->buffer_height /= 2;
460 budget->buffer_height &= height_mask;
461 budget->buffer_size = 2 * budget->buffer_height * budget->buffer_width;
462 } else {
463 budget->buffer_height &= height_mask;
464 budget->buffer_size = budget->buffer_height * budget->buffer_width;
465 }
466 budget->buffer_warning_threshold = budget->buffer_size * 80/100;
467 budget->buffer_warnings = 0;
468 budget->buffer_warning_time = jiffies;
469
470 dprintk(2, "%s: buffer type = %s, width = %d, height = %d\n",
471 budget->dev->name,
472 budget->buffer_size > budget->buffer_width * budget->buffer_height ? "odd/even" : "single",
473 budget->buffer_width, budget->buffer_height);
474 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
475
476 ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name,
477 owner, &budget->dev->pci->dev, adapter_nums);
478 if (ret < 0)
479 return ret;
480
481 /* set dd1 stream a & b */
482 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
483 saa7146_write(dev, MC2, (MASK_09 | MASK_25));
484 saa7146_write(dev, MC2, (MASK_10 | MASK_26));
485 saa7146_write(dev, DD1_INIT, 0x02000000);
486 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
487
488 if (bi->type != BUDGET_FS_ACTIVY)
489 budget->video_port = BUDGET_VIDEO_PORTB;
490 else
491 budget->video_port = BUDGET_VIDEO_PORTA;
492 spin_lock_init(&budget->feedlock);
493 spin_lock_init(&budget->debilock);
494
495 /* the Siemens DVB needs this if you want to have the i2c chips
496 get recognized before the main driver is loaded */
497 if (bi->type != BUDGET_FS_ACTIVY)
498 saa7146_write(dev, GPIO_CTRL, 0x500000); /* GPIO 3 = 1 */
499
500 strlcpy(budget->i2c_adap.name, budget->card->name, sizeof(budget->i2c_adap.name));
501
502 saa7146_i2c_adapter_prepare(dev, &budget->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120);
503 strcpy(budget->i2c_adap.name, budget->card->name);
504
505 if (i2c_add_adapter(&budget->i2c_adap) < 0) {
506 ret = -ENOMEM;
507 goto err_dvb_unregister;
508 }
509
510 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
511
512 budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt);
513 if (NULL == budget->grabbing) {
514 ret = -ENOMEM;
515 goto err_del_i2c;
516 }
517
518 saa7146_write(dev, PCI_BT_V1, 0x001c0000);
519 /* upload all */
520 saa7146_write(dev, GPIO_CTRL, 0x000000);
521
522 tasklet_init(&budget->vpe_tasklet, vpeirq, (unsigned long) budget);
523
524 /* frontend power on */
525 if (bi->type != BUDGET_FS_ACTIVY)
526 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
527
528 if ((ret = budget_register(budget)) == 0)
529 return 0; /* Everything OK */
530
531 /* An error occurred, cleanup resources */
532 saa7146_vfree_destroy_pgtable(dev->pci, budget->grabbing, &budget->pt);
533
534err_del_i2c:
535 i2c_del_adapter(&budget->i2c_adap);
536
537err_dvb_unregister:
538 dvb_unregister_adapter(&budget->dvb_adapter);
539
540 return ret;
541}
542
543void ttpci_budget_init_hooks(struct budget *budget)
544{
545 if (budget->dvb_frontend && !budget->read_fe_status) {
546 budget->read_fe_status = budget->dvb_frontend->ops.read_status;
547 budget->dvb_frontend->ops.read_status = budget_read_fe_status;
548 }
549}
550
551int ttpci_budget_deinit(struct budget *budget)
552{
553 struct saa7146_dev *dev = budget->dev;
554
555 dprintk(2, "budget: %p\n", budget);
556
557 budget_unregister(budget);
558
559 tasklet_kill(&budget->vpe_tasklet);
560
561 saa7146_vfree_destroy_pgtable(dev->pci, budget->grabbing, &budget->pt);
562
563 i2c_del_adapter(&budget->i2c_adap);
564
565 dvb_unregister_adapter(&budget->dvb_adapter);
566
567 return 0;
568}
569
570void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr)
571{
572 struct budget *budget = (struct budget *) dev->ext_priv;
573
574 dprintk(8, "dev: %p, budget: %p\n", dev, budget);
575
576 if (*isr & MASK_10)
577 tasklet_schedule(&budget->vpe_tasklet);
578}
579
580void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port)
581{
582 struct budget *budget = (struct budget *) dev->ext_priv;
583
584 spin_lock(&budget->feedlock);
585 budget->video_port = video_port;
586 if (budget->feeding) {
587 stop_ts_capture(budget);
588 start_ts_capture(budget);
589 }
590 spin_unlock(&budget->feedlock);
591}
592
593EXPORT_SYMBOL_GPL(ttpci_budget_debiread);
594EXPORT_SYMBOL_GPL(ttpci_budget_debiwrite);
595EXPORT_SYMBOL_GPL(ttpci_budget_init);
596EXPORT_SYMBOL_GPL(ttpci_budget_init_hooks);
597EXPORT_SYMBOL_GPL(ttpci_budget_deinit);
598EXPORT_SYMBOL_GPL(ttpci_budget_irq10_handler);
599EXPORT_SYMBOL_GPL(ttpci_budget_set_video_port);
600EXPORT_SYMBOL_GPL(budget_debug);
601
602MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
deleted file mode 100644
index 2cb35c23d2ac..000000000000
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ /dev/null
@@ -1,680 +0,0 @@
1/*
2 * budget-patch.c: driver for Budget Patch,
3 * hardware modification of DVB-S cards enabling full TS
4 *
5 * Written by Emard <emard@softhome.net>
6 *
7 * Original idea by Roberto Deza <rdeza@unav.es>
8 *
9 * Special thanks to Holger Waechtler, Michael Hunold, Marian Durkovic
10 * and Metzlerbros
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 *
29 *
30 * the project's page is at http://www.linuxtv.org/
31 */
32
33#include "av7110.h"
34#include "av7110_hw.h"
35#include "budget.h"
36#include "stv0299.h"
37#include "ves1x93.h"
38#include "tda8083.h"
39
40#include "bsru6.h"
41
42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43
44#define budget_patch budget
45
46static struct saa7146_extension budget_extension;
47
48MAKE_BUDGET_INFO(ttbp, "TT-Budget/Patch DVB-S 1.x PCI", BUDGET_PATCH);
49//MAKE_BUDGET_INFO(satel,"TT-Budget/Patch SATELCO PCI", BUDGET_TT_HW_DISEQC);
50
51static struct pci_device_id pci_tbl[] = {
52 MAKE_EXTENSION_PCI(ttbp,0x13c2, 0x0000),
53// MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
54 {
55 .vendor = 0,
56 }
57};
58
59/* those lines are for budget-patch to be tried
60** on a true budget card and observe the
61** behaviour of VSYNC generated by rps1.
62** this code was shamelessly copy/pasted from budget.c
63*/
64static void gpio_Set22K (struct budget *budget, int state)
65{
66 struct saa7146_dev *dev=budget->dev;
67 dprintk(2, "budget: %p\n", budget);
68 saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
69}
70
71/* Diseqc functions only for TT Budget card */
72/* taken from the Skyvision DVB driver by
73 Ralph Metzler <rjkm@metzlerbros.de> */
74
75static void DiseqcSendBit (struct budget *budget, int data)
76{
77 struct saa7146_dev *dev=budget->dev;
78 dprintk(2, "budget: %p\n", budget);
79
80 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
81 udelay(data ? 500 : 1000);
82 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
83 udelay(data ? 1000 : 500);
84}
85
86static void DiseqcSendByte (struct budget *budget, int data)
87{
88 int i, par=1, d;
89
90 dprintk(2, "budget: %p\n", budget);
91
92 for (i=7; i>=0; i--) {
93 d = (data>>i)&1;
94 par ^= d;
95 DiseqcSendBit(budget, d);
96 }
97
98 DiseqcSendBit(budget, par);
99}
100
101static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
102{
103 struct saa7146_dev *dev=budget->dev;
104 int i;
105
106 dprintk(2, "budget: %p\n", budget);
107
108 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
109 mdelay(16);
110
111 for (i=0; i<len; i++)
112 DiseqcSendByte(budget, msg[i]);
113
114 mdelay(16);
115
116 if (burst!=-1) {
117 if (burst)
118 DiseqcSendByte(budget, 0xff);
119 else {
120 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
121 mdelay(12);
122 udelay(500);
123 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
124 }
125 msleep(20);
126 }
127
128 return 0;
129}
130
131/* shamelessly copy/pasted from budget.c
132*/
133static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
134{
135 struct budget* budget = (struct budget*) fe->dvb->priv;
136
137 switch (tone) {
138 case SEC_TONE_ON:
139 gpio_Set22K (budget, 1);
140 break;
141
142 case SEC_TONE_OFF:
143 gpio_Set22K (budget, 0);
144 break;
145
146 default:
147 return -EINVAL;
148 }
149
150 return 0;
151}
152
153static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
154{
155 struct budget* budget = (struct budget*) fe->dvb->priv;
156
157 SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
158
159 return 0;
160}
161
162static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
163{
164 struct budget* budget = (struct budget*) fe->dvb->priv;
165
166 SendDiSEqCMsg (budget, 0, NULL, minicmd);
167
168 return 0;
169}
170
171static int budget_av7110_send_fw_cmd(struct budget_patch *budget, u16* buf, int length)
172{
173 int i;
174
175 dprintk(2, "budget: %p\n", budget);
176
177 for (i = 2; i < length; i++)
178 {
179 ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2*i, 2, (u32) buf[i], 0,0);
180 msleep(5);
181 }
182 if (length)
183 ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, (u32) buf[1], 0,0);
184 else
185 ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, 0, 0,0);
186 msleep(5);
187 ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND, 2, (u32) buf[0], 0,0);
188 msleep(5);
189 return 0;
190}
191
192static void av7110_set22k(struct budget_patch *budget, int state)
193{
194 u16 buf[2] = {( COMTYPE_AUDIODAC << 8) | (state ? ON22K : OFF22K), 0};
195
196 dprintk(2, "budget: %p\n", budget);
197 budget_av7110_send_fw_cmd(budget, buf, 2);
198}
199
200static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg, int burst)
201{
202 int i;
203 u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) | SendDiSEqC),
204 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
205
206 dprintk(2, "budget: %p\n", budget);
207
208 if (len>10)
209 len=10;
210
211 buf[1] = len+2;
212 buf[2] = len;
213
214 if (burst != -1)
215 buf[3]=burst ? 0x01 : 0x00;
216 else
217 buf[3]=0xffff;
218
219 for (i=0; i<len; i++)
220 buf[i+4]=msg[i];
221
222 budget_av7110_send_fw_cmd(budget, buf, 18);
223 return 0;
224}
225
226static int budget_patch_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
227{
228 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
229
230 switch (tone) {
231 case SEC_TONE_ON:
232 av7110_set22k (budget, 1);
233 break;
234
235 case SEC_TONE_OFF:
236 av7110_set22k (budget, 0);
237 break;
238
239 default:
240 return -EINVAL;
241 }
242
243 return 0;
244}
245
246static int budget_patch_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
247{
248 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
249
250 av7110_send_diseqc_msg (budget, cmd->msg_len, cmd->msg, 0);
251
252 return 0;
253}
254
255static int budget_patch_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
256{
257 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
258
259 av7110_send_diseqc_msg (budget, 0, NULL, minicmd);
260
261 return 0;
262}
263
264static int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe)
265{
266 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
267 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
268 u8 pwr = 0;
269 u8 buf[4];
270 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
271 u32 div = (p->frequency + 479500) / 125;
272
273 if (p->frequency > 2000000)
274 pwr = 3;
275 else if (p->frequency > 1800000)
276 pwr = 2;
277 else if (p->frequency > 1600000)
278 pwr = 1;
279 else if (p->frequency > 1200000)
280 pwr = 0;
281 else if (p->frequency >= 1100000)
282 pwr = 1;
283 else pwr = 2;
284
285 buf[0] = (div >> 8) & 0x7f;
286 buf[1] = div & 0xff;
287 buf[2] = ((div & 0x18000) >> 10) | 0x95;
288 buf[3] = (pwr << 6) | 0x30;
289
290 // NOTE: since we're using a prescaler of 2, we set the
291 // divisor frequency to 62.5kHz and divide by 125 above
292
293 if (fe->ops.i2c_gate_ctrl)
294 fe->ops.i2c_gate_ctrl(fe, 1);
295 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1)
296 return -EIO;
297 return 0;
298}
299
300static struct ves1x93_config alps_bsrv2_config = {
301 .demod_address = 0x08,
302 .xin = 90100000UL,
303 .invert_pwm = 0,
304};
305
306static int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe)
307{
308 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
309 struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
310 u32 div;
311 u8 data[4];
312 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
313
314 div = p->frequency / 125;
315 data[0] = (div >> 8) & 0x7f;
316 data[1] = div & 0xff;
317 data[2] = 0x8e;
318 data[3] = 0x00;
319
320 if (fe->ops.i2c_gate_ctrl)
321 fe->ops.i2c_gate_ctrl(fe, 1);
322 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1)
323 return -EIO;
324 return 0;
325}
326
327static struct tda8083_config grundig_29504_451_config = {
328 .demod_address = 0x68,
329};
330
331static void frontend_init(struct budget_patch* budget)
332{
333 switch(budget->dev->pci->subsystem_device) {
334 case 0x0000: // Hauppauge/TT WinTV DVB-S rev1.X
335 case 0x1013: // SATELCO Multimedia PCI
336
337 // try the ALPS BSRV2 first of all
338 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
339 if (budget->dvb_frontend) {
340 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
341 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_patch_diseqc_send_master_cmd;
342 budget->dvb_frontend->ops.diseqc_send_burst = budget_patch_diseqc_send_burst;
343 budget->dvb_frontend->ops.set_tone = budget_patch_set_tone;
344 break;
345 }
346
347 // try the ALPS BSRU6 now
348 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
349 if (budget->dvb_frontend) {
350 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
351 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
352
353 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
354 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
355 budget->dvb_frontend->ops.set_tone = budget_set_tone;
356 break;
357 }
358
359 // Try the grundig 29504-451
360 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
361 if (budget->dvb_frontend) {
362 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
363 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
364 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
365 budget->dvb_frontend->ops.set_tone = budget_set_tone;
366 break;
367 }
368 break;
369 }
370
371 if (budget->dvb_frontend == NULL) {
372 printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
373 budget->dev->pci->vendor,
374 budget->dev->pci->device,
375 budget->dev->pci->subsystem_vendor,
376 budget->dev->pci->subsystem_device);
377 } else {
378 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
379 printk("budget-av: Frontend registration failed!\n");
380 dvb_frontend_detach(budget->dvb_frontend);
381 budget->dvb_frontend = NULL;
382 }
383 }
384}
385
386/* written by Emard */
387static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
388{
389 struct budget_patch *budget;
390 int err;
391 int count = 0;
392 int detected = 0;
393
394#define PATCH_RESET 0
395#define RPS_IRQ 0
396#define HPS_SETUP 0
397#if PATCH_RESET
398 saa7146_write(dev, MC1, MASK_31);
399 msleep(40);
400#endif
401#if HPS_SETUP
402 // initialize registers. Better to have it like this
403 // than leaving something unconfigured
404 saa7146_write(dev, DD1_STREAM_B, 0);
405 // port B VSYNC at rising edge
406 saa7146_write(dev, DD1_INIT, 0x00000200); // have this in budget-core too!
407 saa7146_write(dev, BRS_CTRL, 0x00000000); // VBI
408
409 // debi config
410 // saa7146_write(dev, DEBI_CONFIG, MASK_30|MASK_28|MASK_18);
411
412 // zero all HPS registers
413 saa7146_write(dev, HPS_H_PRESCALE, 0); // r68
414 saa7146_write(dev, HPS_H_SCALE, 0); // r6c
415 saa7146_write(dev, BCS_CTRL, 0); // r70
416 saa7146_write(dev, HPS_V_SCALE, 0); // r60
417 saa7146_write(dev, HPS_V_GAIN, 0); // r64
418 saa7146_write(dev, CHROMA_KEY_RANGE, 0); // r74
419 saa7146_write(dev, CLIP_FORMAT_CTRL, 0); // r78
420 // Set HPS prescaler for port B input
421 saa7146_write(dev, HPS_CTRL, (1<<30) | (0<<29) | (1<<28) | (0<<12) );
422 saa7146_write(dev, MC2,
423 0 * (MASK_08 | MASK_24) | // BRS control
424 0 * (MASK_09 | MASK_25) | // a
425 0 * (MASK_10 | MASK_26) | // b
426 1 * (MASK_06 | MASK_22) | // HPS_CTRL1
427 1 * (MASK_05 | MASK_21) | // HPS_CTRL2
428 0 * (MASK_01 | MASK_15) // DEBI
429 );
430#endif
431 // Disable RPS1 and RPS0
432 saa7146_write(dev, MC1, ( MASK_29 | MASK_28));
433 // RPS1 timeout disable
434 saa7146_write(dev, RPS_TOV1, 0);
435
436 // code for autodetection
437 // will wait for VBI_B event (vertical blank at port B)
438 // and will reset GPIO3 after VBI_B is detected.
439 // (GPIO3 should be raised high by CPU to
440 // test if GPIO3 will generate vertical blank signal
441 // in budget patch GPIO3 is connected to VSYNC_B
442 count = 0;
443#if 0
444 WRITE_RPS1(CMD_UPLOAD |
445 MASK_10 | MASK_09 | MASK_08 | MASK_06 | MASK_05 | MASK_04 | MASK_03 | MASK_02 );
446#endif
447 WRITE_RPS1(CMD_PAUSE | EVT_VBI_B);
448 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
449 WRITE_RPS1(GPIO3_MSK);
450 WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
451#if RPS_IRQ
452 // issue RPS1 interrupt to increment counter
453 WRITE_RPS1(CMD_INTERRUPT);
454 // at least a NOP is neede between two interrupts
455 WRITE_RPS1(CMD_NOP);
456 // interrupt again
457 WRITE_RPS1(CMD_INTERRUPT);
458#endif
459 WRITE_RPS1(CMD_STOP);
460
461#if RPS_IRQ
462 // set event counter 1 source as RPS1 interrupt (0x03) (rE4 p53)
463 // use 0x03 to track RPS1 interrupts - increase by 1 every gpio3 is toggled
464 // use 0x15 to track VPE interrupts - increase by 1 every vpeirq() is called
465 saa7146_write(dev, EC1SSR, (0x03<<2) | 3 );
466 // set event counter 1 threshold to maximum allowed value (rEC p55)
467 saa7146_write(dev, ECT1R, 0x3fff );
468#endif
469 // Fix VSYNC level
470 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
471 // Set RPS1 Address register to point to RPS code (r108 p42)
472 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
473 // Enable RPS1, (rFC p33)
474 saa7146_write(dev, MC1, (MASK_13 | MASK_29 ));
475
476
477 mdelay(50);
478 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
479 mdelay(150);
480
481
482 if( (saa7146_read(dev, GPIO_CTRL) & 0x10000000) == 0)
483 detected = 1;
484
485#if RPS_IRQ
486 printk("Event Counter 1 0x%04x\n", saa7146_read(dev, EC1R) & 0x3fff );
487#endif
488 // Disable RPS1
489 saa7146_write(dev, MC1, ( MASK_29 ));
490
491 if(detected == 0)
492 printk("budget-patch not detected or saa7146 in non-default state.\n"
493 "try enabling ressetting of 7146 with MASK_31 in MC1 register\n");
494
495 else
496 printk("BUDGET-PATCH DETECTED.\n");
497
498
499/* OLD (Original design by Roberto Deza):
500** This code will setup the SAA7146_RPS1 to generate a square
501** wave on GPIO3, changing when a field (TS_HEIGHT/2 "lines" of
502** TS_WIDTH packets) has been acquired on SAA7146_D1B video port;
503** then, this GPIO3 output which is connected to the D1B_VSYNC
504** input, will trigger the acquisition of the alternate field
505** and so on.
506** Currently, the TT_budget / WinTV_Nova cards have two ICs
507** (74HCT4040, LVC74) for the generation of this VSYNC signal,
508** which seems that can be done perfectly without this :-)).
509*/
510
511/* New design (By Emard)
512** this rps1 code will copy internal HS event to GPIO3 pin.
513** GPIO3 is in budget-patch hardware connected to port B VSYNC
514
515** HS is an internal event of 7146, accessible with RPS
516** and temporarily raised high every n lines
517** (n in defined in the RPS_THRESH1 counter threshold)
518** I think HS is raised high on the beginning of the n-th line
519** and remains high until this n-th line that triggered
520** it is completely received. When the reception of n-th line
521** ends, HS is lowered.
522
523** To transmit data over DMA, 7146 needs changing state at
524** port B VSYNC pin. Any changing of port B VSYNC will
525** cause some DMA data transfer, with more or less packets loss.
526** It depends on the phase and frequency of VSYNC and
527** the way of 7146 is instructed to trigger on port B (defined
528** in DD1_INIT register, 3rd nibble from the right valid
529** numbers are 0-7, see datasheet)
530**
531** The correct triggering can minimize packet loss,
532** dvbtraffic should give this stable bandwidths:
533** 22k transponder = 33814 kbit/s
534** 27.5k transponder = 38045 kbit/s
535** by experiment it is found that the best results
536** (stable bandwidths and almost no packet loss)
537** are obtained using DD1_INIT triggering number 2
538** (Va at rising edge of VS Fa = HS x VS-failing forced toggle)
539** and a VSYNC phase that occurs in the middle of DMA transfer
540** (about byte 188*512=96256 in the DMA window).
541**
542** Phase of HS is still not clear to me how to control,
543** It just happens to be so. It can be seen if one enables
544** RPS_IRQ and print Event Counter 1 in vpeirq(). Every
545** time RPS_INTERRUPT is called, the Event Counter 1 will
546** increment. That's how the 7146 is programmed to do event
547** counting in this budget-patch.c
548** I *think* HPS setting has something to do with the phase
549** of HS but I can't be 100% sure in that.
550
551** hardware debug note: a working budget card (including budget patch)
552** with vpeirq() interrupt setup in mode "0x90" (every 64K) will
553** generate 3 interrupts per 25-Hz DMA frame of 2*188*512 bytes
554** and that means 3*25=75 Hz of interrupt frequency, as seen by
555** watch cat /proc/interrupts
556**
557** If this frequency is 3x lower (and data received in the DMA
558** buffer don't start with 0x47, but in the middle of packets,
559** whose lengths appear to be like 188 292 188 104 etc.
560** this means VSYNC line is not connected in the hardware.
561** (check soldering pcb and pins)
562** The same behaviour of missing VSYNC can be duplicated on budget
563** cards, by setting DD1_INIT trigger mode 7 in 3rd nibble.
564*/
565
566 // Setup RPS1 "program" (p35)
567 count = 0;
568
569
570 // Wait Source Line Counter Threshold (p36)
571 WRITE_RPS1(CMD_PAUSE | EVT_HS);
572 // Set GPIO3=1 (p42)
573 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
574 WRITE_RPS1(GPIO3_MSK);
575 WRITE_RPS1(SAA7146_GPIO_OUTHI<<24);
576#if RPS_IRQ
577 // issue RPS1 interrupt
578 WRITE_RPS1(CMD_INTERRUPT);
579#endif
580 // Wait reset Source Line Counter Threshold (p36)
581 WRITE_RPS1(CMD_PAUSE | RPS_INV | EVT_HS);
582 // Set GPIO3=0 (p42)
583 WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
584 WRITE_RPS1(GPIO3_MSK);
585 WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
586#if RPS_IRQ
587 // issue RPS1 interrupt
588 WRITE_RPS1(CMD_INTERRUPT);
589#endif
590 // Jump to begin of RPS program (p37)
591 WRITE_RPS1(CMD_JUMP);
592 WRITE_RPS1(dev->d_rps1.dma_handle);
593
594 // Fix VSYNC level
595 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
596 // Set RPS1 Address register to point to RPS code (r108 p42)
597 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
598
599 if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
600 return -ENOMEM;
601
602 dprintk(2, "budget: %p\n", budget);
603
604 err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
605 if (err) {
606 kfree(budget);
607 return err;
608 }
609
610 // Set Source Line Counter Threshold, using BRS (rCC p43)
611 // It generates HS event every TS_HEIGHT lines
612 // this is related to TS_WIDTH set in register
613 // NUM_LINE_BYTE3 in budget-core.c. If NUM_LINE_BYTE
614 // low 16 bits are set to TS_WIDTH bytes (TS_WIDTH=2*188
615 //,then RPS_THRESH1
616 // should be set to trigger every TS_HEIGHT (512) lines.
617 //
618 saa7146_write(dev, RPS_THRESH1, budget->buffer_height | MASK_12 );
619
620 // saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
621 // Enable RPS1 (rFC p33)
622 saa7146_write(dev, MC1, (MASK_13 | MASK_29));
623
624
625 dev->ext_priv = budget;
626
627 budget->dvb_adapter.priv = budget;
628 frontend_init(budget);
629
630 ttpci_budget_init_hooks(budget);
631
632 return 0;
633}
634
635static int budget_patch_detach (struct saa7146_dev* dev)
636{
637 struct budget_patch *budget = (struct budget_patch*) dev->ext_priv;
638 int err;
639
640 if (budget->dvb_frontend) {
641 dvb_unregister_frontend(budget->dvb_frontend);
642 dvb_frontend_detach(budget->dvb_frontend);
643 }
644 err = ttpci_budget_deinit (budget);
645
646 kfree (budget);
647
648 return err;
649}
650
651static int __init budget_patch_init(void)
652{
653 return saa7146_register_extension(&budget_extension);
654}
655
656static void __exit budget_patch_exit(void)
657{
658 saa7146_unregister_extension(&budget_extension);
659}
660
661static struct saa7146_extension budget_extension = {
662 .name = "budget_patch dvb",
663 .flags = 0,
664
665 .module = THIS_MODULE,
666 .pci_tbl = pci_tbl,
667 .attach = budget_patch_attach,
668 .detach = budget_patch_detach,
669
670 .irq_mask = MASK_10,
671 .irq_func = ttpci_budget_irq10_handler,
672};
673
674module_init(budget_patch_init);
675module_exit(budget_patch_exit);
676
677MODULE_LICENSE("GPL");
678MODULE_AUTHOR("Emard, Roberto Deza, Holger Waechtler, Michael Hunold, others");
679MODULE_DESCRIPTION("Driver for full TS modified DVB-S SAA7146+AV7110 "
680 "based so-called Budget Patch cards");
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
deleted file mode 100644
index 7e6e43ae5c51..000000000000
--- a/drivers/media/dvb/ttpci/budget.c
+++ /dev/null
@@ -1,871 +0,0 @@
1/*
2 * budget.c: driver for the SAA7146 based Budget DVB cards
3 *
4 * Compiled from various sources by Michael Hunold <michael@mihu.de>
5 *
6 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
7 *
8 * Copyright (C) 1999-2002 Ralph Metzler
9 * & Marcus Metzler for convergence integrated media GmbH
10 *
11 * 26feb2004 Support for FS Activy Card (Grundig tuner) by
12 * Michael Dreher <michael@5dot1.de>,
13 * Oliver Endriss <o.endriss@gmx.de> and
14 * Andreas 'randy' Weinberger
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
20 *
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
32 *
33 *
34 * the project's page is at http://www.linuxtv.org/
35 */
36
37#include "budget.h"
38#include "stv0299.h"
39#include "ves1x93.h"
40#include "ves1820.h"
41#include "l64781.h"
42#include "tda8083.h"
43#include "s5h1420.h"
44#include "tda10086.h"
45#include "tda826x.h"
46#include "lnbp21.h"
47#include "bsru6.h"
48#include "bsbe1.h"
49#include "tdhd1.h"
50#include "stv6110x.h"
51#include "stv090x.h"
52#include "isl6423.h"
53#include "lnbh24.h"
54
55
56static int diseqc_method;
57module_param(diseqc_method, int, 0444);
58MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
62static void Set22K (struct budget *budget, int state)
63{
64 struct saa7146_dev *dev=budget->dev;
65 dprintk(2, "budget: %p\n", budget);
66 saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
67}
68
69/* Diseqc functions only for TT Budget card */
70/* taken from the Skyvision DVB driver by
71 Ralph Metzler <rjkm@metzlerbros.de> */
72
73static void DiseqcSendBit (struct budget *budget, int data)
74{
75 struct saa7146_dev *dev=budget->dev;
76 dprintk(2, "budget: %p\n", budget);
77
78 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
79 udelay(data ? 500 : 1000);
80 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
81 udelay(data ? 1000 : 500);
82}
83
84static void DiseqcSendByte (struct budget *budget, int data)
85{
86 int i, par=1, d;
87
88 dprintk(2, "budget: %p\n", budget);
89
90 for (i=7; i>=0; i--) {
91 d = (data>>i)&1;
92 par ^= d;
93 DiseqcSendBit(budget, d);
94 }
95
96 DiseqcSendBit(budget, par);
97}
98
99static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
100{
101 struct saa7146_dev *dev=budget->dev;
102 int i;
103
104 dprintk(2, "budget: %p\n", budget);
105
106 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
107 mdelay(16);
108
109 for (i=0; i<len; i++)
110 DiseqcSendByte(budget, msg[i]);
111
112 mdelay(16);
113
114 if (burst!=-1) {
115 if (burst)
116 DiseqcSendByte(budget, 0xff);
117 else {
118 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
119 mdelay(12);
120 udelay(500);
121 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
122 }
123 msleep(20);
124 }
125
126 return 0;
127}
128
129/*
130 * Routines for the Fujitsu Siemens Activy budget card
131 * 22 kHz tone and DiSEqC are handled by the frontend.
132 * Voltage must be set here.
133 * GPIO 1: LNBP EN, GPIO 2: LNBP VSEL
134 */
135static int SetVoltage_Activy (struct budget *budget, fe_sec_voltage_t voltage)
136{
137 struct saa7146_dev *dev=budget->dev;
138
139 dprintk(2, "budget: %p\n", budget);
140
141 switch (voltage) {
142 case SEC_VOLTAGE_13:
143 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
144 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTLO);
145 break;
146 case SEC_VOLTAGE_18:
147 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI);
148 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
149 break;
150 case SEC_VOLTAGE_OFF:
151 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO);
152 break;
153 default:
154 return -EINVAL;
155 }
156
157 return 0;
158}
159
160static int siemens_budget_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
161{
162 struct budget* budget = (struct budget*) fe->dvb->priv;
163
164 return SetVoltage_Activy (budget, voltage);
165}
166
167static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
168{
169 struct budget* budget = (struct budget*) fe->dvb->priv;
170
171 switch (tone) {
172 case SEC_TONE_ON:
173 Set22K (budget, 1);
174 break;
175
176 case SEC_TONE_OFF:
177 Set22K (budget, 0);
178 break;
179
180 default:
181 return -EINVAL;
182 }
183
184 return 0;
185}
186
187static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
188{
189 struct budget* budget = (struct budget*) fe->dvb->priv;
190
191 SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
192
193 return 0;
194}
195
196static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
197{
198 struct budget* budget = (struct budget*) fe->dvb->priv;
199
200 SendDiSEqCMsg (budget, 0, NULL, minicmd);
201
202 return 0;
203}
204
205static int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe)
206{
207 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
208 struct budget* budget = (struct budget*) fe->dvb->priv;
209 u8 pwr = 0;
210 u8 buf[4];
211 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
212 u32 div = (c->frequency + 479500) / 125;
213
214 if (c->frequency > 2000000)
215 pwr = 3;
216 else if (c->frequency > 1800000)
217 pwr = 2;
218 else if (c->frequency > 1600000)
219 pwr = 1;
220 else if (c->frequency > 1200000)
221 pwr = 0;
222 else if (c->frequency >= 1100000)
223 pwr = 1;
224 else pwr = 2;
225
226 buf[0] = (div >> 8) & 0x7f;
227 buf[1] = div & 0xff;
228 buf[2] = ((div & 0x18000) >> 10) | 0x95;
229 buf[3] = (pwr << 6) | 0x30;
230
231 // NOTE: since we're using a prescaler of 2, we set the
232 // divisor frequency to 62.5kHz and divide by 125 above
233
234 if (fe->ops.i2c_gate_ctrl)
235 fe->ops.i2c_gate_ctrl(fe, 1);
236 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
237 return 0;
238}
239
240static struct ves1x93_config alps_bsrv2_config =
241{
242 .demod_address = 0x08,
243 .xin = 90100000UL,
244 .invert_pwm = 0,
245};
246
247static int alps_tdbe2_tuner_set_params(struct dvb_frontend *fe)
248{
249 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
250 struct budget* budget = (struct budget*) fe->dvb->priv;
251 u32 div;
252 u8 data[4];
253 struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) };
254
255 div = (c->frequency + 35937500 + 31250) / 62500;
256
257 data[0] = (div >> 8) & 0x7f;
258 data[1] = div & 0xff;
259 data[2] = 0x85 | ((div >> 10) & 0x60);
260 data[3] = (c->frequency < 174000000 ? 0x88 : c->frequency < 470000000 ? 0x84 : 0x81);
261
262 if (fe->ops.i2c_gate_ctrl)
263 fe->ops.i2c_gate_ctrl(fe, 1);
264 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
265 return 0;
266}
267
268static struct ves1820_config alps_tdbe2_config = {
269 .demod_address = 0x09,
270 .xin = 57840000UL,
271 .invert = 1,
272 .selagc = VES1820_SELAGC_SIGNAMPERR,
273};
274
275static int grundig_29504_401_tuner_set_params(struct dvb_frontend *fe)
276{
277 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
278 struct budget *budget = fe->dvb->priv;
279 u8 *tuner_addr = fe->tuner_priv;
280 u32 div;
281 u8 cfg, cpump, band_select;
282 u8 data[4];
283 struct i2c_msg msg = { .flags = 0, .buf = data, .len = sizeof(data) };
284
285 if (tuner_addr)
286 msg.addr = *tuner_addr;
287 else
288 msg.addr = 0x61;
289
290 div = (36125000 + c->frequency) / 166666;
291
292 cfg = 0x88;
293
294 if (c->frequency < 175000000)
295 cpump = 2;
296 else if (c->frequency < 390000000)
297 cpump = 1;
298 else if (c->frequency < 470000000)
299 cpump = 2;
300 else if (c->frequency < 750000000)
301 cpump = 1;
302 else
303 cpump = 3;
304
305 if (c->frequency < 175000000)
306 band_select = 0x0e;
307 else if (c->frequency < 470000000)
308 band_select = 0x05;
309 else
310 band_select = 0x03;
311
312 data[0] = (div >> 8) & 0x7f;
313 data[1] = div & 0xff;
314 data[2] = ((div >> 10) & 0x60) | cfg;
315 data[3] = (cpump << 6) | band_select;
316
317 if (fe->ops.i2c_gate_ctrl)
318 fe->ops.i2c_gate_ctrl(fe, 1);
319 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
320 return 0;
321}
322
323static struct l64781_config grundig_29504_401_config = {
324 .demod_address = 0x55,
325};
326
327static struct l64781_config grundig_29504_401_config_activy = {
328 .demod_address = 0x54,
329};
330
331static u8 tuner_address_grundig_29504_401_activy = 0x60;
332
333static int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe)
334{
335 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
336 struct budget* budget = (struct budget*) fe->dvb->priv;
337 u32 div;
338 u8 data[4];
339 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
340
341 div = c->frequency / 125;
342 data[0] = (div >> 8) & 0x7f;
343 data[1] = div & 0xff;
344 data[2] = 0x8e;
345 data[3] = 0x00;
346
347 if (fe->ops.i2c_gate_ctrl)
348 fe->ops.i2c_gate_ctrl(fe, 1);
349 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
350 return 0;
351}
352
353static struct tda8083_config grundig_29504_451_config = {
354 .demod_address = 0x68,
355};
356
357static int s5h1420_tuner_set_params(struct dvb_frontend *fe)
358{
359 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
360 struct budget* budget = (struct budget*) fe->dvb->priv;
361 u32 div;
362 u8 data[4];
363 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
364
365 div = c->frequency / 1000;
366 data[0] = (div >> 8) & 0x7f;
367 data[1] = div & 0xff;
368 data[2] = 0xc2;
369
370 if (div < 1450)
371 data[3] = 0x00;
372 else if (div < 1850)
373 data[3] = 0x40;
374 else if (div < 2000)
375 data[3] = 0x80;
376 else
377 data[3] = 0xc0;
378
379 if (fe->ops.i2c_gate_ctrl)
380 fe->ops.i2c_gate_ctrl(fe, 1);
381 if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
382
383 return 0;
384}
385
386static struct s5h1420_config s5h1420_config = {
387 .demod_address = 0x53,
388 .invert = 1,
389 .cdclk_polarity = 1,
390};
391
392static struct tda10086_config tda10086_config = {
393 .demod_address = 0x0e,
394 .invert = 0,
395 .diseqc_tone = 1,
396 .xtal_freq = TDA10086_XTAL_16M,
397};
398
399static struct stv0299_config alps_bsru6_config_activy = {
400 .demod_address = 0x68,
401 .inittab = alps_bsru6_inittab,
402 .mclk = 88000000UL,
403 .invert = 1,
404 .op0_off = 1,
405 .min_delay_ms = 100,
406 .set_symbol_rate = alps_bsru6_set_symbol_rate,
407};
408
409static struct stv0299_config alps_bsbe1_config_activy = {
410 .demod_address = 0x68,
411 .inittab = alps_bsbe1_inittab,
412 .mclk = 88000000UL,
413 .invert = 1,
414 .op0_off = 1,
415 .min_delay_ms = 100,
416 .set_symbol_rate = alps_bsbe1_set_symbol_rate,
417};
418
419static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
420{
421 struct budget *budget = (struct budget *)fe->dvb->priv;
422
423 return request_firmware(fw, name, &budget->dev->pci->dev);
424}
425
426
427static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
428{
429 u8 val;
430 struct i2c_msg msg[] = {
431 { .addr = adr, .flags = 0, .buf = &reg, .len = 1 },
432 { .addr = adr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
433 };
434
435 return (i2c_transfer(i2c, msg, 2) != 2) ? -EIO : val;
436}
437
438static u8 read_pwm(struct budget* budget)
439{
440 u8 b = 0xff;
441 u8 pwm;
442 struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
443 { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
444
445 if ((i2c_transfer(&budget->i2c_adap, msg, 2) != 2) || (pwm == 0xff))
446 pwm = 0x48;
447
448 return pwm;
449}
450
451static struct stv090x_config tt1600_stv090x_config = {
452 .device = STV0903,
453 .demod_mode = STV090x_SINGLE,
454 .clk_mode = STV090x_CLK_EXT,
455
456 .xtal = 13500000,
457 .address = 0x68,
458
459 .ts1_mode = STV090x_TSMODE_DVBCI,
460 .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,
461
462 .repeater_level = STV090x_RPTLEVEL_16,
463
464 .tuner_init = NULL,
465 .tuner_sleep = NULL,
466 .tuner_set_mode = NULL,
467 .tuner_set_frequency = NULL,
468 .tuner_get_frequency = NULL,
469 .tuner_set_bandwidth = NULL,
470 .tuner_get_bandwidth = NULL,
471 .tuner_set_bbgain = NULL,
472 .tuner_get_bbgain = NULL,
473 .tuner_set_refclk = NULL,
474 .tuner_get_status = NULL,
475};
476
477static struct stv6110x_config tt1600_stv6110x_config = {
478 .addr = 0x60,
479 .refclk = 27000000,
480 .clk_div = 2,
481};
482
483static struct isl6423_config tt1600_isl6423_config = {
484 .current_max = SEC_CURRENT_515m,
485 .curlim = SEC_CURRENT_LIM_ON,
486 .mod_extern = 1,
487 .addr = 0x08,
488};
489
490static void frontend_init(struct budget *budget)
491{
492 (void)alps_bsbe1_config; /* avoid warning */
493
494 switch(budget->dev->pci->subsystem_device) {
495 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
496 case 0x1013:
497 // try the ALPS BSRV2 first of all
498 budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
499 if (budget->dvb_frontend) {
500 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
501 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
502 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
503 budget->dvb_frontend->ops.set_tone = budget_set_tone;
504 break;
505 }
506
507 // try the ALPS BSRU6 now
508 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
509 if (budget->dvb_frontend) {
510 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
511 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
512 if (budget->dev->pci->subsystem_device == 0x1003 && diseqc_method == 0) {
513 budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
514 budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
515 budget->dvb_frontend->ops.set_tone = budget_set_tone;
516 }
517 break;
518 }
519 break;
520
521 case 0x1004: // Hauppauge/TT DVB-C budget (ves1820/ALPS TDBE2(sp5659))
522
523 budget->dvb_frontend = dvb_attach(ves1820_attach, &alps_tdbe2_config, &budget->i2c_adap, read_pwm(budget));
524 if (budget->dvb_frontend) {
525 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdbe2_tuner_set_params;
526 break;
527 }
528 break;
529
530 case 0x1005: // Hauppauge/TT Nova-T budget (L64781/Grundig 29504-401(tsa5060))
531
532 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config, &budget->i2c_adap);
533 if (budget->dvb_frontend) {
534 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
535 budget->dvb_frontend->tuner_priv = NULL;
536 break;
537 }
538 break;
539
540 case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
541 {
542 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
543
544 if (subtype < 0)
545 break;
546 /* fixme: find a better way to identify the card */
547 if (subtype < 0x36) {
548 /* assume ALPS BSRU6 */
549 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config_activy, &budget->i2c_adap);
550 if (budget->dvb_frontend) {
551 printk(KERN_INFO "budget: tuner ALPS BSRU6 detected\n");
552 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
553 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
554 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
555 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
556 break;
557 }
558 } else {
559 /* assume ALPS BSBE1 */
560 /* reset tuner */
561 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTLO);
562 msleep(50);
563 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTHI);
564 msleep(250);
565 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config_activy, &budget->i2c_adap);
566 if (budget->dvb_frontend) {
567 printk(KERN_INFO "budget: tuner ALPS BSBE1 detected\n");
568 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
569 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
570 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
571 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
572 break;
573 }
574 }
575 break;
576 }
577
578 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
579 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
580 if (budget->dvb_frontend) {
581 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
582 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
583 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
584 }
585 break;
586
587 case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
588 budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
589 if (budget->dvb_frontend) {
590 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
591 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
592 }
593 break;
594
595 case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
596 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
597 if (budget->dvb_frontend) {
598 budget->dvb_frontend->tuner_priv = &tuner_address_grundig_29504_401_activy;
599 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
600 }
601 break;
602
603 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
604 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
605 if (budget->dvb_frontend) {
606 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
607 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
608 printk("%s: No LNBP21 found!\n", __func__);
609 goto error_out;
610 }
611 break;
612 }
613
614 case 0x1018: // TT Budget-S-1401 (philips tda10086/philips tda8262)
615 // gpio2 is connected to CLB - reset it + leave it high
616 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
617 msleep(1);
618 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
619 msleep(1);
620
621 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
622 if (budget->dvb_frontend) {
623 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
624 printk("%s: No tda826x found!\n", __func__);
625 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
626 printk("%s: No LNBP21 found!\n", __func__);
627 goto error_out;
628 }
629 break;
630 }
631
632 case 0x101c: { /* TT S2-1600 */
633 struct stv6110x_devctl *ctl;
634 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
635 msleep(50);
636 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
637 msleep(250);
638
639 budget->dvb_frontend = dvb_attach(stv090x_attach,
640 &tt1600_stv090x_config,
641 &budget->i2c_adap,
642 STV090x_DEMODULATOR_0);
643
644 if (budget->dvb_frontend) {
645
646 ctl = dvb_attach(stv6110x_attach,
647 budget->dvb_frontend,
648 &tt1600_stv6110x_config,
649 &budget->i2c_adap);
650
651 if (ctl) {
652 tt1600_stv090x_config.tuner_init = ctl->tuner_init;
653 tt1600_stv090x_config.tuner_sleep = ctl->tuner_sleep;
654 tt1600_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
655 tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
656 tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
657 tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
658 tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
659 tt1600_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
660 tt1600_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
661 tt1600_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
662 tt1600_stv090x_config.tuner_get_status = ctl->tuner_get_status;
663
664 /* call the init function once to initialize
665 tuner's clock output divider and demod's
666 master clock */
667 if (budget->dvb_frontend->ops.init)
668 budget->dvb_frontend->ops.init(budget->dvb_frontend);
669
670 if (dvb_attach(isl6423_attach,
671 budget->dvb_frontend,
672 &budget->i2c_adap,
673 &tt1600_isl6423_config) == NULL) {
674 printk(KERN_ERR "%s: No Intersil ISL6423 found!\n", __func__);
675 goto error_out;
676 }
677 } else {
678 printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
679 goto error_out;
680 }
681 }
682 }
683 break;
684
685 case 0x1020: { /* Omicom S2 */
686 struct stv6110x_devctl *ctl;
687 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTLO);
688 msleep(50);
689 saa7146_setgpio(budget->dev, 2, SAA7146_GPIO_OUTHI);
690 msleep(250);
691
692 budget->dvb_frontend = dvb_attach(stv090x_attach,
693 &tt1600_stv090x_config,
694 &budget->i2c_adap,
695 STV090x_DEMODULATOR_0);
696
697 if (budget->dvb_frontend) {
698 printk(KERN_INFO "budget: Omicom S2 detected\n");
699
700 ctl = dvb_attach(stv6110x_attach,
701 budget->dvb_frontend,
702 &tt1600_stv6110x_config,
703 &budget->i2c_adap);
704
705 if (ctl) {
706 tt1600_stv090x_config.tuner_init = ctl->tuner_init;
707 tt1600_stv090x_config.tuner_sleep = ctl->tuner_sleep;
708 tt1600_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
709 tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
710 tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
711 tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
712 tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
713 tt1600_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
714 tt1600_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
715 tt1600_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
716 tt1600_stv090x_config.tuner_get_status = ctl->tuner_get_status;
717
718 /* call the init function once to initialize
719 tuner's clock output divider and demod's
720 master clock */
721 if (budget->dvb_frontend->ops.init)
722 budget->dvb_frontend->ops.init(budget->dvb_frontend);
723
724 if (dvb_attach(lnbh24_attach,
725 budget->dvb_frontend,
726 &budget->i2c_adap,
727 LNBH24_PCL | LNBH24_TTX,
728 LNBH24_TEN, 0x14>>1) == NULL) {
729 printk(KERN_ERR
730 "No LNBH24 found!\n");
731 goto error_out;
732 }
733 } else {
734 printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
735 goto error_out;
736 }
737 }
738 }
739 break;
740 }
741
742 if (budget->dvb_frontend == NULL) {
743 printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
744 budget->dev->pci->vendor,
745 budget->dev->pci->device,
746 budget->dev->pci->subsystem_vendor,
747 budget->dev->pci->subsystem_device);
748 } else {
749 if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend))
750 goto error_out;
751 }
752 return;
753
754error_out:
755 printk("budget: Frontend registration failed!\n");
756 dvb_frontend_detach(budget->dvb_frontend);
757 budget->dvb_frontend = NULL;
758 return;
759}
760
761static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
762{
763 struct budget *budget = NULL;
764 int err;
765
766 budget = kmalloc(sizeof(struct budget), GFP_KERNEL);
767 if( NULL == budget ) {
768 return -ENOMEM;
769 }
770
771 dprintk(2, "dev:%p, info:%p, budget:%p\n", dev, info, budget);
772
773 dev->ext_priv = budget;
774
775 err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
776 if (err) {
777 printk("==> failed\n");
778 kfree (budget);
779 return err;
780 }
781
782 budget->dvb_adapter.priv = budget;
783 frontend_init(budget);
784
785 ttpci_budget_init_hooks(budget);
786
787 return 0;
788}
789
790static int budget_detach (struct saa7146_dev* dev)
791{
792 struct budget *budget = (struct budget*) dev->ext_priv;
793 int err;
794
795 if (budget->dvb_frontend) {
796 dvb_unregister_frontend(budget->dvb_frontend);
797 dvb_frontend_detach(budget->dvb_frontend);
798 }
799
800 err = ttpci_budget_deinit (budget);
801
802 kfree (budget);
803 dev->ext_priv = NULL;
804
805 return err;
806}
807
808static struct saa7146_extension budget_extension;
809
810MAKE_BUDGET_INFO(ttbs, "TT-Budget/WinTV-NOVA-S PCI", BUDGET_TT);
811MAKE_BUDGET_INFO(ttbc, "TT-Budget/WinTV-NOVA-C PCI", BUDGET_TT);
812MAKE_BUDGET_INFO(ttbt, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
813MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
814MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
815MAKE_BUDGET_INFO(tt1600, "TT-Budget S2-1600 PCI", BUDGET_TT);
816MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
817MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
818MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
819MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
820MAKE_BUDGET_INFO(omicom, "Omicom S2 PCI", BUDGET_TT);
821
822static struct pci_device_id pci_tbl[] = {
823 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
824 MAKE_EXTENSION_PCI(ttbc, 0x13c2, 0x1004),
825 MAKE_EXTENSION_PCI(ttbt, 0x13c2, 0x1005),
826 MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
827 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1016),
828 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
829 MAKE_EXTENSION_PCI(tt1600, 0x13c2, 0x101c),
830 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
831 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
832 MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
833 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
834 MAKE_EXTENSION_PCI(omicom, 0x14c4, 0x1020),
835 {
836 .vendor = 0,
837 }
838};
839
840MODULE_DEVICE_TABLE(pci, pci_tbl);
841
842static struct saa7146_extension budget_extension = {
843 .name = "budget dvb",
844 .flags = SAA7146_USE_I2C_IRQ,
845
846 .module = THIS_MODULE,
847 .pci_tbl = pci_tbl,
848 .attach = budget_attach,
849 .detach = budget_detach,
850
851 .irq_mask = MASK_10,
852 .irq_func = ttpci_budget_irq10_handler,
853};
854
855static int __init budget_init(void)
856{
857 return saa7146_register_extension(&budget_extension);
858}
859
860static void __exit budget_exit(void)
861{
862 saa7146_unregister_extension(&budget_extension);
863}
864
865module_init(budget_init);
866module_exit(budget_exit);
867
868MODULE_LICENSE("GPL");
869MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others");
870MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
871 "budget PCI DVB cards by Siemens, Technotrend, Hauppauge");
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
deleted file mode 100644
index 3d8a806c20bb..000000000000
--- a/drivers/media/dvb/ttpci/budget.h
+++ /dev/null
@@ -1,124 +0,0 @@
1
2#ifndef __BUDGET_DVB__
3#define __BUDGET_DVB__
4
5#include "dvb_frontend.h"
6#include "dvbdev.h"
7#include "demux.h"
8#include "dvb_demux.h"
9#include "dmxdev.h"
10#include "dvb_filter.h"
11#include "dvb_net.h"
12
13#include <linux/module.h>
14#include <linux/mutex.h>
15
16#include <media/saa7146.h>
17
18extern int budget_debug;
19
20#ifdef dprintk
21#undef dprintk
22#endif
23
24#define dprintk(level,args...) \
25 do { if ((budget_debug & level)) { printk("%s: %s(): ", KBUILD_MODNAME, __func__); printk(args); } } while (0)
26
27struct budget_info {
28 char *name;
29 int type;
30};
31
32/* place to store all the necessary device information */
33struct budget {
34
35 /* devices */
36 struct dvb_device dvb_dev;
37 struct dvb_net dvb_net;
38
39 struct saa7146_dev *dev;
40
41 struct i2c_adapter i2c_adap;
42 struct budget_info *card;
43
44 unsigned char *grabbing;
45 struct saa7146_pgtable pt;
46
47 struct tasklet_struct fidb_tasklet;
48 struct tasklet_struct vpe_tasklet;
49
50 struct dmxdev dmxdev;
51 struct dvb_demux demux;
52
53 struct dmx_frontend hw_frontend;
54 struct dmx_frontend mem_frontend;
55
56 int ci_present;
57 int video_port;
58
59 u32 buffer_width;
60 u32 buffer_height;
61 u32 buffer_size;
62 u32 buffer_warning_threshold;
63 u32 buffer_warnings;
64 unsigned long buffer_warning_time;
65
66 u32 ttbp;
67 int feeding;
68
69 spinlock_t feedlock;
70
71 spinlock_t debilock;
72
73 struct dvb_adapter dvb_adapter;
74 struct dvb_frontend *dvb_frontend;
75 int (*read_fe_status)(struct dvb_frontend *fe, fe_status_t *status);
76 int fe_synced;
77
78 void *priv;
79};
80
81#define MAKE_BUDGET_INFO(x_var,x_name,x_type) \
82static struct budget_info x_var ## _info = { \
83 .name=x_name, \
84 .type=x_type }; \
85static struct saa7146_pci_extension_data x_var = { \
86 .ext_priv = &x_var ## _info, \
87 .ext = &budget_extension };
88
89#define BUDGET_TT 0
90#define BUDGET_TT_HW_DISEQC 1
91#define BUDGET_PATCH 3
92#define BUDGET_FS_ACTIVY 4
93#define BUDGET_CIN1200S 5
94#define BUDGET_CIN1200C 6
95#define BUDGET_CIN1200T 7
96#define BUDGET_KNC1S 8
97#define BUDGET_KNC1C 9
98#define BUDGET_KNC1T 10
99#define BUDGET_KNC1SP 11
100#define BUDGET_KNC1CP 12
101#define BUDGET_KNC1TP 13
102#define BUDGET_TVSTAR 14
103#define BUDGET_CIN1200C_MK3 15
104#define BUDGET_KNC1C_MK3 16
105#define BUDGET_KNC1CP_MK3 17
106#define BUDGET_KNC1S2 18
107#define BUDGET_KNC1C_TDA10024 19
108
109#define BUDGET_VIDEO_PORTA 0
110#define BUDGET_VIDEO_PORTB 1
111
112extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
113 struct saa7146_pci_extension_data *info,
114 struct module *owner, short *adapter_nums);
115extern void ttpci_budget_init_hooks(struct budget *budget);
116extern int ttpci_budget_deinit(struct budget *budget);
117extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr);
118extern void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port);
119extern int ttpci_budget_debiread(struct budget *budget, u32 config, int addr, int count,
120 int uselocks, int nobusyloop);
121extern int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr, int count, u32 value,
122 int uselocks, int nobusyloop);
123
124#endif
diff --git a/drivers/media/dvb/ttpci/ttpci-eeprom.c b/drivers/media/dvb/ttpci/ttpci-eeprom.c
deleted file mode 100644
index 32d43156c548..000000000000
--- a/drivers/media/dvb/ttpci/ttpci-eeprom.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/*
2 Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
3 decode it and store it in the associated adapter struct for
4 use by dvb_net.c
5
6 This card appear to have the 24C16 write protect held to ground,
7 thus permitting normal read/write operation. Theoretically it
8 would be possible to write routines to burn a different (encoded)
9 MAC address into the EEPROM.
10
11 Robert Schlabbach GMX
12 Michael Glaum KVH Industries
13 Holger Waechtler Convergence
14
15 Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
16 Metzler Brothers Systementwicklung GbR
17
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
22
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
32*/
33
34#include <asm/errno.h>
35#include <linux/init.h>
36#include <linux/module.h>
37#include <linux/string.h>
38#include <linux/i2c.h>
39
40#include "ttpci-eeprom.h"
41
42#if 1
43#define dprintk(x...) do { printk(x); } while (0)
44#else
45#define dprintk(x...) do { } while (0)
46#endif
47
48
49static int check_mac_tt(u8 *buf)
50{
51 int i;
52 u16 tmp = 0xffff;
53
54 for (i = 0; i < 8; i++) {
55 tmp = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
56 tmp ^= (tmp >> 4) & 0x0f;
57 tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
58 }
59 tmp ^= 0xffff;
60 return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
61}
62
63static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
64{
65 u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
66 0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
67 0x1d, 0x36, 0x64, 0x78};
68 u8 data[20];
69 int i;
70
71 /* In case there is a sig check failure have the orig contents available */
72 memcpy(data, encodedMAC, 20);
73
74 for (i = 0; i < 20; i++)
75 data[i] ^= xor[i];
76 for (i = 0; i < 10; i++)
77 data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
78 >> ((data[2 * i + 1] >> 6) & 3);
79
80 if (check_mac_tt(data))
81 return -ENODEV;
82
83 decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
84 decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
85 return 0;
86}
87
88int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC)
89{
90 u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
91 0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
92 0x1d, 0x36, 0x64, 0x78};
93 u8 data[20];
94 int i;
95
96 memcpy(data, encodedMAC, 20);
97
98 for (i = 0; i < 20; i++)
99 data[i] ^= xor[i];
100 for (i = 0; i < 10; i++)
101 data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
102 >> ((data[2 * i + 1] >> 6) & 3);
103
104 if (check_mac_tt(data))
105 return -ENODEV;
106
107 decodedMAC[0] = data[2];
108 decodedMAC[1] = data[1];
109 decodedMAC[2] = data[0];
110 decodedMAC[3] = data[6];
111 decodedMAC[4] = data[5];
112 decodedMAC[5] = data[4];
113 return 0;
114}
115EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
116
117static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
118{
119 int ret;
120 u8 b0[] = { 0xcc };
121
122 struct i2c_msg msg[] = {
123 { .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
124 { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
125 };
126
127 /* dprintk("%s\n", __func__); */
128
129 ret = i2c_transfer(adapter, msg, 2);
130
131 if (ret != 2) /* Assume EEPROM isn't there */
132 return (-ENODEV);
133
134 return 0;
135}
136
137
138int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
139{
140 int ret, i;
141 u8 encodedMAC[20];
142 u8 decodedMAC[6];
143
144 ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
145
146 if (ret != 0) { /* Will only be -ENODEV */
147 dprintk("Couldn't read from EEPROM: not there?\n");
148 memset(proposed_mac, 0, 6);
149 return ret;
150 }
151
152 ret = getmac_tt(decodedMAC, encodedMAC);
153 if( ret != 0 ) {
154 dprintk("adapter failed MAC signature check\n");
155 dprintk("encoded MAC from EEPROM was " );
156 for(i=0; i<19; i++) {
157 dprintk( "%.2x:", encodedMAC[i]);
158 }
159 dprintk("%.2x\n", encodedMAC[19]);
160 memset(proposed_mac, 0, 6);
161 return ret;
162 }
163
164 memcpy(proposed_mac, decodedMAC, 6);
165 dprintk("adapter has MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
166 decodedMAC[0], decodedMAC[1], decodedMAC[2],
167 decodedMAC[3], decodedMAC[4], decodedMAC[5]);
168 return 0;
169}
170
171EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
172
173MODULE_LICENSE("GPL");
174MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
175MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards "
176 "made by Siemens, Technotrend, Hauppauge");
diff --git a/drivers/media/dvb/ttpci/ttpci-eeprom.h b/drivers/media/dvb/ttpci/ttpci-eeprom.h
deleted file mode 100644
index dcc33d5a5cb1..000000000000
--- a/drivers/media/dvb/ttpci/ttpci-eeprom.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 Retrieve encoded MAC address from ATMEL ttpci_eeprom serial 2-wire EEPROM,
3 decode it and store it in associated adapter net device
4
5 Robert Schlabbach GMX
6 Michael Glaum KVH Industries
7 Holger Waechtler Convergence
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23*/
24
25#ifndef __TTPCI_EEPROM_H__
26#define __TTPCI_EEPROM_H__
27
28#include <linux/types.h>
29#include <linux/i2c.h>
30
31extern int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC);
32extern int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *propsed_mac);
33
34#endif