diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2008-03-07 00:30:23 -0500 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2009-02-24 08:51:25 -0500 |
commit | c81c8b68b46752721b0c1addfabb828da27e1489 (patch) | |
tree | 59d2a336150ce59780b73ba8dc59a829e217b2d0 /drivers | |
parent | f7e603ad8f78cd3b59e33fa72707da0cbabdf699 (diff) |
DVB: add firesat driver
Original code written by Christian Dolzer <c.dolzer@digital-everywhere.com>
Cleaned up by Greg.
Major cleanup and reorg by Manu Abraham <manu@linuxtv.org>
Additions also by Ben Backx <ben@bbackx.com>
Cc: Christian Dolzer <c.dolzer@digital-everywhere.com>
Cc: Andreas Monitzer <andy@monitzer.com>
Cc: Manu Abraham <manu@linuxtv.org>
Cc: Fabio De Lorenzo <delorenzo.fabio@gmail.com>
Cc: Robert Berger <robert.berger@reliableembeddedsystems.com>
Signed-off-by: Ben Backx <ben@bbackx.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Added missing dependency to dvb/firesat/Kconfig,
Reported-by: Randy Dunlap <randy.dunlap@oracle.com>
Tweaked dvb/Makefile.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/dvb/Kconfig | 2 | ||||
-rw-r--r-- | drivers/media/dvb/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/Kconfig | 11 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/Makefile | 12 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/avc_api.c | 848 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/avc_api.h | 381 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/cmp.c | 230 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/cmp.h | 9 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat-ci.c | 95 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat-ci.h | 9 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat-rc.c | 84 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat-rc.h | 9 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat.h | 85 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat_1394.c | 468 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat_dvb.c | 350 | ||||
-rw-r--r-- | drivers/media/dvb/firesat/firesat_fe.c | 263 |
16 files changed, 2858 insertions, 0 deletions
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig index 40ebde53b3c..8a2d5f9713d 100644 --- a/drivers/media/dvb/Kconfig +++ b/drivers/media/dvb/Kconfig | |||
@@ -51,6 +51,8 @@ comment "Supported SDMC DM1105 Adapters" | |||
51 | depends on DVB_CORE && PCI && I2C | 51 | depends on DVB_CORE && PCI && I2C |
52 | source "drivers/media/dvb/dm1105/Kconfig" | 52 | source "drivers/media/dvb/dm1105/Kconfig" |
53 | 53 | ||
54 | source "drivers/media/dvb/firesat/Kconfig" | ||
55 | |||
54 | comment "Supported DVB Frontends" | 56 | comment "Supported DVB Frontends" |
55 | depends on DVB_CORE | 57 | depends on DVB_CORE |
56 | source "drivers/media/dvb/frontends/Kconfig" | 58 | source "drivers/media/dvb/frontends/Kconfig" |
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile index f91e9eb15e5..41710554012 100644 --- a/drivers/media/dvb/Makefile +++ b/drivers/media/dvb/Makefile | |||
@@ -3,3 +3,5 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/ | 5 | obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/ |
6 | |||
7 | obj-$(CONFIG_DVB_FIRESAT) += firesat/ | ||
diff --git a/drivers/media/dvb/firesat/Kconfig b/drivers/media/dvb/firesat/Kconfig new file mode 100644 index 00000000000..93f8de5ec3c --- /dev/null +++ b/drivers/media/dvb/firesat/Kconfig | |||
@@ -0,0 +1,11 @@ | |||
1 | config DVB_FIRESAT | ||
2 | tristate "FireSAT devices" | ||
3 | depends on DVB_CORE && IEEE1394 && INPUT | ||
4 | help | ||
5 | Support for external IEEE1394 adapters designed by Digital Everywhere and | ||
6 | produced by El Gato, shipped under the brand name 'FireDTV/FloppyDTV'. | ||
7 | |||
8 | These devices don't have a MPEG decoder built in, so you need | ||
9 | an external software decoder to watch TV. | ||
10 | |||
11 | Say Y if you own such a device and want to use it. | ||
diff --git a/drivers/media/dvb/firesat/Makefile b/drivers/media/dvb/firesat/Makefile new file mode 100644 index 00000000000..fdf86870f1f --- /dev/null +++ b/drivers/media/dvb/firesat/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | firesat-objs := firesat_1394.o \ | ||
2 | firesat_dvb.o \ | ||
3 | firesat_fe.o \ | ||
4 | avc_api.o \ | ||
5 | cmp.o \ | ||
6 | firesat-rc.o \ | ||
7 | firesat-ci.o | ||
8 | |||
9 | obj-$(CONFIG_DVB_FIRESAT) += firesat.o | ||
10 | |||
11 | EXTRA_CFLAGS := -Idrivers/ieee1394 | ||
12 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | ||
diff --git a/drivers/media/dvb/firesat/avc_api.c b/drivers/media/dvb/firesat/avc_api.c new file mode 100644 index 00000000000..d70795623fb --- /dev/null +++ b/drivers/media/dvb/firesat/avc_api.c | |||
@@ -0,0 +1,848 @@ | |||
1 | /* | ||
2 | * FireSAT AVC driver | ||
3 | * | ||
4 | * Copyright (c) 2004 Andreas Monitzer <andy@monitzer.com> | ||
5 | * Copyright (c) 2008 Ben Backx <ben@bbackx.com> | ||
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 as | ||
9 | * published by the Free Software Foundation; either version 2 of | ||
10 | * the License, or (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include "firesat.h" | ||
14 | #include <ieee1394_transactions.h> | ||
15 | #include <nodemgr.h> | ||
16 | #include <asm/byteorder.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include "avc_api.h" | ||
19 | #include "firesat-rc.h" | ||
20 | |||
21 | #define RESPONSE_REGISTER 0xFFFFF0000D00ULL | ||
22 | #define COMMAND_REGISTER 0xFFFFF0000B00ULL | ||
23 | #define PCR_BASE_ADDRESS 0xFFFFF0000900ULL | ||
24 | |||
25 | static int __AVCRegisterRemoteControl(struct firesat*firesat, int internal); | ||
26 | |||
27 | /* Frees an allocated packet */ | ||
28 | static void avc_free_packet(struct hpsb_packet *packet) | ||
29 | { | ||
30 | hpsb_free_tlabel(packet); | ||
31 | hpsb_free_packet(packet); | ||
32 | } | ||
33 | |||
34 | /* | ||
35 | * Goofy routine that basically does a down_timeout function. | ||
36 | * Stolen from sbp2.c | ||
37 | */ | ||
38 | static int avc_down_timeout(atomic_t *done, int timeout) | ||
39 | { | ||
40 | int i; | ||
41 | |||
42 | for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) { | ||
43 | set_current_state(TASK_INTERRUPTIBLE); | ||
44 | if (schedule_timeout(HZ/10)) /* 100ms */ | ||
45 | return(1); | ||
46 | } | ||
47 | return ((i > 0) ? 0:1); | ||
48 | } | ||
49 | |||
50 | static int __AVCWrite(struct firesat *firesat, const AVCCmdFrm *CmdFrm, AVCRspFrm *RspFrm) { | ||
51 | struct hpsb_packet *packet; | ||
52 | struct node_entry *ne; | ||
53 | |||
54 | ne = firesat->nodeentry; | ||
55 | if(!ne) { | ||
56 | printk("%s: lost node!\n",__func__); | ||
57 | return -EIO; | ||
58 | } | ||
59 | |||
60 | /* need all input data */ | ||
61 | if(!firesat || !ne || !CmdFrm) | ||
62 | return -EINVAL; | ||
63 | |||
64 | // printk(KERN_INFO "AVCWrite command %x\n",CmdFrm->opcode); | ||
65 | |||
66 | // for(k=0;k<CmdFrm->length;k++) | ||
67 | // printk(KERN_INFO "CmdFrm[%d] = %08x\n", k, ((quadlet_t*)CmdFrm)[k]); | ||
68 | |||
69 | packet=hpsb_make_writepacket(ne->host, ne->nodeid, COMMAND_REGISTER, | ||
70 | (quadlet_t*)CmdFrm, CmdFrm->length); | ||
71 | |||
72 | hpsb_set_packet_complete_task(packet, (void (*)(void*))avc_free_packet, | ||
73 | packet); | ||
74 | |||
75 | hpsb_node_fill_packet(ne, packet); | ||
76 | |||
77 | if(RspFrm) | ||
78 | atomic_set(&firesat->avc_reply_received, 0); | ||
79 | |||
80 | if (hpsb_send_packet(packet) < 0) { | ||
81 | avc_free_packet(packet); | ||
82 | atomic_set(&firesat->avc_reply_received, 1); | ||
83 | return -EIO; | ||
84 | } | ||
85 | |||
86 | if(RspFrm) { | ||
87 | if(avc_down_timeout(&firesat->avc_reply_received,HZ/2)) { | ||
88 | printk("%s: timeout waiting for avc response\n",__func__); | ||
89 | atomic_set(&firesat->avc_reply_received, 1); | ||
90 | return -ETIMEDOUT; | ||
91 | } | ||
92 | |||
93 | memcpy(RspFrm,firesat->respfrm,firesat->resp_length); | ||
94 | } | ||
95 | |||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | int AVCWrite(struct firesat*firesat, const AVCCmdFrm *CmdFrm, AVCRspFrm *RspFrm) { | ||
100 | int ret; | ||
101 | if(down_interruptible(&firesat->avc_sem)) | ||
102 | return -EINTR; | ||
103 | |||
104 | ret = __AVCWrite(firesat, CmdFrm, RspFrm); | ||
105 | |||
106 | up(&firesat->avc_sem); | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | static void do_schedule_remotecontrol(unsigned long ignored); | ||
111 | DECLARE_TASKLET(schedule_remotecontrol, do_schedule_remotecontrol, 0); | ||
112 | |||
113 | static void do_schedule_remotecontrol(unsigned long ignored) { | ||
114 | struct firesat *firesat; | ||
115 | unsigned long flags; | ||
116 | |||
117 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
118 | list_for_each_entry(firesat,&firesat_list,list) { | ||
119 | if(atomic_read(&firesat->reschedule_remotecontrol) == 1) { | ||
120 | if(down_trylock(&firesat->avc_sem)) | ||
121 | tasklet_schedule(&schedule_remotecontrol); | ||
122 | else { | ||
123 | if(__AVCRegisterRemoteControl(firesat, 1) == 0) | ||
124 | atomic_set(&firesat->reschedule_remotecontrol, 0); | ||
125 | else | ||
126 | tasklet_schedule(&schedule_remotecontrol); | ||
127 | |||
128 | up(&firesat->avc_sem); | ||
129 | } | ||
130 | } | ||
131 | } | ||
132 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
133 | } | ||
134 | |||
135 | int AVCRecv(struct firesat *firesat, u8 *data, size_t length) { | ||
136 | // printk(KERN_INFO "%s\n",__func__); | ||
137 | |||
138 | // remote control handling | ||
139 | |||
140 | AVCRspFrm *RspFrm = (AVCRspFrm*)data; | ||
141 | |||
142 | if(/*RspFrm->length >= 8 && ###*/ | ||
143 | ((RspFrm->operand[0] == SFE_VENDOR_DE_COMPANYID_0 && | ||
144 | RspFrm->operand[1] == SFE_VENDOR_DE_COMPANYID_1 && | ||
145 | RspFrm->operand[2] == SFE_VENDOR_DE_COMPANYID_2)) && | ||
146 | RspFrm->operand[3] == SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL) { | ||
147 | if(RspFrm->resp == CHANGED) { | ||
148 | // printk(KERN_INFO "%s: code = %02x %02x\n",__func__,RspFrm->operand[4],RspFrm->operand[5]); | ||
149 | firesat_got_remotecontrolcode((((u16)RspFrm->operand[4]) << 8) | ((u16)RspFrm->operand[5])); | ||
150 | |||
151 | // schedule | ||
152 | atomic_set(&firesat->reschedule_remotecontrol, 1); | ||
153 | tasklet_schedule(&schedule_remotecontrol); | ||
154 | } else if(RspFrm->resp != INTERIM) | ||
155 | printk(KERN_INFO "%s: remote control result = %d\n",__func__, RspFrm->resp); | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | if(atomic_read(&firesat->avc_reply_received) == 1) { | ||
160 | printk("%s: received out-of-order AVC response, ignored\n",__func__); | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | // AVCRspFrm *resp=(AVCRspFrm *)data; | ||
164 | // int k; | ||
165 | /* | ||
166 | printk(KERN_INFO "resp=0x%x\n",resp->resp); | ||
167 | printk(KERN_INFO "cts=0x%x\n",resp->cts); | ||
168 | printk(KERN_INFO "suid=0x%x\n",resp->suid); | ||
169 | printk(KERN_INFO "sutyp=0x%x\n",resp->sutyp); | ||
170 | printk(KERN_INFO "opcode=0x%x\n",resp->opcode); | ||
171 | printk(KERN_INFO "length=%d\n",resp->length); | ||
172 | */ | ||
173 | // for(k=0;k<2;k++) | ||
174 | // printk(KERN_INFO "operand[%d]=%02x\n",k,resp->operand[k]); | ||
175 | |||
176 | memcpy(firesat->respfrm,data,length); | ||
177 | firesat->resp_length=length; | ||
178 | |||
179 | atomic_set(&firesat->avc_reply_received, 1); | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | // tuning command for setting the relative LNB frequency (not supported by the AVC standard) | ||
185 | static void AVCTuner_tuneQPSK(struct firesat *firesat, struct dvb_frontend_parameters *params, AVCCmdFrm *CmdFrm) { | ||
186 | memset(CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
187 | |||
188 | CmdFrm->cts = AVC; | ||
189 | CmdFrm->ctype = CONTROL; | ||
190 | CmdFrm->sutyp = 0x5; | ||
191 | CmdFrm->suid = firesat->subunit; | ||
192 | CmdFrm->opcode = VENDOR; | ||
193 | |||
194 | CmdFrm->operand[0]=SFE_VENDOR_DE_COMPANYID_0; | ||
195 | CmdFrm->operand[1]=SFE_VENDOR_DE_COMPANYID_1; | ||
196 | CmdFrm->operand[2]=SFE_VENDOR_DE_COMPANYID_2; | ||
197 | CmdFrm->operand[3]=SFE_VENDOR_OPCODE_TUNE_QPSK; | ||
198 | |||
199 | printk(KERN_INFO "%s: tuning to frequency %u\n",__func__,params->frequency); | ||
200 | |||
201 | CmdFrm->operand[4] = (params->frequency >> 24) & 0xFF; | ||
202 | CmdFrm->operand[5] = (params->frequency >> 16) & 0xFF; | ||
203 | CmdFrm->operand[6] = (params->frequency >> 8) & 0xFF; | ||
204 | CmdFrm->operand[7] = params->frequency & 0xFF; | ||
205 | |||
206 | printk(KERN_INFO "%s: symbol rate = %uBd\n",__func__,params->u.qpsk.symbol_rate); | ||
207 | |||
208 | CmdFrm->operand[8] = ((params->u.qpsk.symbol_rate/1000) >> 8) & 0xFF; | ||
209 | CmdFrm->operand[9] = (params->u.qpsk.symbol_rate/1000) & 0xFF; | ||
210 | |||
211 | switch(params->u.qpsk.fec_inner) { | ||
212 | case FEC_1_2: | ||
213 | CmdFrm->operand[10] = 0x1; | ||
214 | break; | ||
215 | case FEC_2_3: | ||
216 | CmdFrm->operand[10] = 0x2; | ||
217 | break; | ||
218 | case FEC_3_4: | ||
219 | CmdFrm->operand[10] = 0x3; | ||
220 | break; | ||
221 | case FEC_5_6: | ||
222 | CmdFrm->operand[10] = 0x4; | ||
223 | break; | ||
224 | case FEC_7_8: | ||
225 | CmdFrm->operand[10] = 0x5; | ||
226 | break; | ||
227 | case FEC_4_5: | ||
228 | case FEC_8_9: | ||
229 | case FEC_AUTO: | ||
230 | default: | ||
231 | CmdFrm->operand[10] = 0x0; | ||
232 | } | ||
233 | |||
234 | if(firesat->voltage == 0xff) | ||
235 | CmdFrm->operand[11] = 0xff; | ||
236 | else | ||
237 | CmdFrm->operand[11] = (firesat->voltage==SEC_VOLTAGE_18)?0:1; // polarisation | ||
238 | if(firesat->tone == 0xff) | ||
239 | CmdFrm->operand[12] = 0xff; | ||
240 | else | ||
241 | CmdFrm->operand[12] = (firesat->tone==SEC_TONE_ON)?1:0; // band | ||
242 | |||
243 | CmdFrm->length = 16; | ||
244 | } | ||
245 | |||
246 | int AVCTuner_DSD(struct firesat *firesat, struct dvb_frontend_parameters *params, BYTE *status) { | ||
247 | AVCCmdFrm CmdFrm; | ||
248 | AVCRspFrm RspFrm; | ||
249 | M_VALID_FLAGS flags; | ||
250 | int k; | ||
251 | |||
252 | // printk(KERN_INFO "%s\n", __func__); | ||
253 | |||
254 | if(firesat->type == FireSAT_DVB_S) | ||
255 | AVCTuner_tuneQPSK(firesat, params, &CmdFrm); | ||
256 | else { | ||
257 | if(firesat->type == FireSAT_DVB_T) { | ||
258 | flags.Bits_T.GuardInterval = (params->u.ofdm.guard_interval != GUARD_INTERVAL_AUTO); | ||
259 | flags.Bits_T.CodeRateLPStream = (params->u.ofdm.code_rate_LP != FEC_AUTO); | ||
260 | flags.Bits_T.CodeRateHPStream = (params->u.ofdm.code_rate_HP != FEC_AUTO); | ||
261 | flags.Bits_T.HierarchyInfo = (params->u.ofdm.hierarchy_information != HIERARCHY_AUTO); | ||
262 | flags.Bits_T.Constellation = (params->u.ofdm.constellation != QAM_AUTO); | ||
263 | flags.Bits_T.Bandwidth = (params->u.ofdm.bandwidth != BANDWIDTH_AUTO); | ||
264 | flags.Bits_T.CenterFrequency = 1; | ||
265 | flags.Bits_T.reserved1 = 0; | ||
266 | flags.Bits_T.reserved2 = 0; | ||
267 | flags.Bits_T.OtherFrequencyFlag = 0; | ||
268 | flags.Bits_T.TransmissionMode = (params->u.ofdm.transmission_mode != TRANSMISSION_MODE_AUTO); | ||
269 | flags.Bits_T.NetworkId = 0; | ||
270 | } else { | ||
271 | flags.Bits.Modulation = 0; | ||
272 | if(firesat->type == FireSAT_DVB_S) { | ||
273 | flags.Bits.FEC_inner = 1; | ||
274 | } else if(firesat->type == FireSAT_DVB_C) { | ||
275 | flags.Bits.FEC_inner = 0; | ||
276 | } | ||
277 | flags.Bits.FEC_outer = 0; | ||
278 | flags.Bits.Symbol_Rate = 1; | ||
279 | flags.Bits.Frequency = 1; | ||
280 | flags.Bits.Orbital_Pos = 0; | ||
281 | if(firesat->type == FireSAT_DVB_S) { | ||
282 | flags.Bits.Polarisation = 1; | ||
283 | } else if(firesat->type == FireSAT_DVB_C) { | ||
284 | flags.Bits.Polarisation = 0; | ||
285 | } | ||
286 | flags.Bits.reserved_fields = 0; | ||
287 | flags.Bits.reserved1 = 0; | ||
288 | flags.Bits.Network_ID = 0; | ||
289 | } | ||
290 | |||
291 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
292 | |||
293 | CmdFrm.cts = AVC; | ||
294 | CmdFrm.ctype = CONTROL; | ||
295 | CmdFrm.sutyp = 0x5; | ||
296 | CmdFrm.suid = firesat->subunit; | ||
297 | CmdFrm.opcode = DSD; | ||
298 | |||
299 | CmdFrm.operand[0] = 0; // source plug | ||
300 | CmdFrm.operand[1] = 0xD2; // subfunction replace | ||
301 | CmdFrm.operand[2] = 0x20; // system id = DVB | ||
302 | CmdFrm.operand[3] = 0x00; // antenna number | ||
303 | CmdFrm.operand[4] = (firesat->type == FireSAT_DVB_T)?0x0c:0x11; // system_specific_multiplex selection_length | ||
304 | CmdFrm.operand[5] = flags.Valid_Word.ByteHi; // valid_flags [0] | ||
305 | CmdFrm.operand[6] = flags.Valid_Word.ByteLo; // valid_flags [1] | ||
306 | |||
307 | if(firesat->type == FireSAT_DVB_T) { | ||
308 | CmdFrm.operand[7] = 0x0; | ||
309 | CmdFrm.operand[8] = (params->frequency/10) >> 24; | ||
310 | CmdFrm.operand[9] = ((params->frequency/10) >> 16) & 0xFF; | ||
311 | CmdFrm.operand[10] = ((params->frequency/10) >> 8) & 0xFF; | ||
312 | CmdFrm.operand[11] = (params->frequency/10) & 0xFF; | ||
313 | switch(params->u.ofdm.bandwidth) { | ||
314 | case BANDWIDTH_7_MHZ: | ||
315 | CmdFrm.operand[12] = 0x20; | ||
316 | break; | ||
317 | case BANDWIDTH_8_MHZ: | ||
318 | case BANDWIDTH_6_MHZ: // not defined by AVC spec | ||
319 | case BANDWIDTH_AUTO: | ||
320 | default: | ||
321 | CmdFrm.operand[12] = 0x00; | ||
322 | } | ||
323 | switch(params->u.ofdm.constellation) { | ||
324 | case QAM_16: | ||
325 | CmdFrm.operand[13] = 1 << 6; | ||
326 | break; | ||
327 | case QAM_64: | ||
328 | CmdFrm.operand[13] = 2 << 6; | ||
329 | break; | ||
330 | case QPSK: | ||
331 | default: | ||
332 | CmdFrm.operand[13] = 0x00; | ||
333 | } | ||
334 | switch(params->u.ofdm.hierarchy_information) { | ||
335 | case HIERARCHY_1: | ||
336 | CmdFrm.operand[13] |= 1 << 3; | ||
337 | break; | ||
338 | case HIERARCHY_2: | ||
339 | CmdFrm.operand[13] |= 2 << 3; | ||
340 | break; | ||
341 | case HIERARCHY_4: | ||
342 | CmdFrm.operand[13] |= 3 << 3; | ||
343 | break; | ||
344 | case HIERARCHY_AUTO: | ||
345 | case HIERARCHY_NONE: | ||
346 | default: | ||
347 | break; | ||
348 | } | ||
349 | switch(params->u.ofdm.code_rate_HP) { | ||
350 | case FEC_2_3: | ||
351 | CmdFrm.operand[13] |= 1; | ||
352 | break; | ||
353 | case FEC_3_4: | ||
354 | CmdFrm.operand[13] |= 2; | ||
355 | break; | ||
356 | case FEC_5_6: | ||
357 | CmdFrm.operand[13] |= 3; | ||
358 | break; | ||
359 | case FEC_7_8: | ||
360 | CmdFrm.operand[13] |= 4; | ||
361 | break; | ||
362 | case FEC_1_2: | ||
363 | default: | ||
364 | break; | ||
365 | } | ||
366 | switch(params->u.ofdm.code_rate_LP) { | ||
367 | case FEC_2_3: | ||
368 | CmdFrm.operand[14] = 1 << 5; | ||
369 | break; | ||
370 | case FEC_3_4: | ||
371 | CmdFrm.operand[14] = 2 << 5; | ||
372 | break; | ||
373 | case FEC_5_6: | ||
374 | CmdFrm.operand[14] = 3 << 5; | ||
375 | break; | ||
376 | case FEC_7_8: | ||
377 | CmdFrm.operand[14] = 4 << 5; | ||
378 | break; | ||
379 | case FEC_1_2: | ||
380 | default: | ||
381 | CmdFrm.operand[14] = 0x00; | ||
382 | break; | ||
383 | } | ||
384 | switch(params->u.ofdm.guard_interval) { | ||
385 | case GUARD_INTERVAL_1_16: | ||
386 | CmdFrm.operand[14] |= 1 << 3; | ||
387 | break; | ||
388 | case GUARD_INTERVAL_1_8: | ||
389 | CmdFrm.operand[14] |= 2 << 3; | ||
390 | break; | ||
391 | case GUARD_INTERVAL_1_4: | ||
392 | CmdFrm.operand[14] |= 3 << 3; | ||
393 | break; | ||
394 | case GUARD_INTERVAL_1_32: | ||
395 | case GUARD_INTERVAL_AUTO: | ||
396 | default: | ||
397 | break; | ||
398 | } | ||
399 | switch(params->u.ofdm.transmission_mode) { | ||
400 | case TRANSMISSION_MODE_8K: | ||
401 | CmdFrm.operand[14] |= 1 << 1; | ||
402 | break; | ||
403 | case TRANSMISSION_MODE_2K: | ||
404 | case TRANSMISSION_MODE_AUTO: | ||
405 | default: | ||
406 | break; | ||
407 | } | ||
408 | |||
409 | CmdFrm.operand[15] = 0x00; // network_ID[0] | ||
410 | CmdFrm.operand[16] = 0x00; // network_ID[1] | ||
411 | CmdFrm.operand[17] = 0x00; // Nr_of_dsd_sel_specs = 0 - > No PIDs are transmitted | ||
412 | |||
413 | CmdFrm.length = 20; | ||
414 | } else { | ||
415 | CmdFrm.operand[7] = 0x00; | ||
416 | CmdFrm.operand[8] = (((firesat->voltage==SEC_VOLTAGE_18)?0:1)<<6); /* 0 = H, 1 = V */ | ||
417 | CmdFrm.operand[9] = 0x00; | ||
418 | CmdFrm.operand[10] = 0x00; | ||
419 | |||
420 | if(firesat->type == FireSAT_DVB_S) { | ||
421 | /* ### relative frequency -> absolute frequency */ | ||
422 | CmdFrm.operand[11] = (((params->frequency/4) >> 16) & 0xFF) | (2 << 6); | ||
423 | CmdFrm.operand[12] = ((params->frequency/4) >> 8) & 0xFF; | ||
424 | CmdFrm.operand[13] = (params->frequency/4) & 0xFF; | ||
425 | } else if(firesat->type == FireSAT_DVB_C) { | ||
426 | CmdFrm.operand[11] = (((params->frequency/4000) >> 16) & 0xFF) | (2 << 6); | ||
427 | CmdFrm.operand[12] = ((params->frequency/4000) >> 8) & 0xFF; | ||
428 | CmdFrm.operand[13] = (params->frequency/4000) & 0xFF; | ||
429 | } | ||
430 | |||
431 | CmdFrm.operand[14] = ((params->u.qpsk.symbol_rate/1000) >> 12) & 0xFF; | ||
432 | CmdFrm.operand[15] = ((params->u.qpsk.symbol_rate/1000) >> 4) & 0xFF; | ||
433 | CmdFrm.operand[16] = ((params->u.qpsk.symbol_rate/1000) << 4) & 0xF0; | ||
434 | |||
435 | CmdFrm.operand[17] = 0x00; | ||
436 | switch(params->u.qpsk.fec_inner) { | ||
437 | case FEC_1_2: | ||
438 | CmdFrm.operand[18] = 0x1; | ||
439 | break; | ||
440 | case FEC_2_3: | ||
441 | CmdFrm.operand[18] = 0x2; | ||
442 | break; | ||
443 | case FEC_3_4: | ||
444 | CmdFrm.operand[18] = 0x3; | ||
445 | break; | ||
446 | case FEC_5_6: | ||
447 | CmdFrm.operand[18] = 0x4; | ||
448 | break; | ||
449 | case FEC_7_8: | ||
450 | CmdFrm.operand[18] = 0x5; | ||
451 | break; | ||
452 | case FEC_4_5: | ||
453 | case FEC_8_9: | ||
454 | case FEC_AUTO: | ||
455 | default: | ||
456 | CmdFrm.operand[18] = 0x0; | ||
457 | } | ||
458 | if(firesat->type == FireSAT_DVB_S) { | ||
459 | CmdFrm.operand[19] = 0x08; // modulation | ||
460 | } else if(firesat->type == FireSAT_DVB_C) { | ||
461 | switch(params->u.qam.modulation) { | ||
462 | case QAM_16: | ||
463 | CmdFrm.operand[19] = 0x08; // modulation | ||
464 | break; | ||
465 | case QAM_32: | ||
466 | CmdFrm.operand[19] = 0x10; // modulation | ||
467 | break; | ||
468 | case QAM_64: | ||
469 | CmdFrm.operand[19] = 0x18; // modulation | ||
470 | break; | ||
471 | case QAM_128: | ||
472 | CmdFrm.operand[19] = 0x20; // modulation | ||
473 | break; | ||
474 | case QAM_256: | ||
475 | CmdFrm.operand[19] = 0x28; // modulation | ||
476 | break; | ||
477 | case QAM_AUTO: | ||
478 | default: | ||
479 | CmdFrm.operand[19] = 0x00; // modulation | ||
480 | } | ||
481 | } | ||
482 | CmdFrm.operand[20] = 0x00; | ||
483 | CmdFrm.operand[21] = 0x00; | ||
484 | CmdFrm.operand[22] = 0x00; // Nr_of_dsd_sel_specs = 0 - > No PIDs are transmitted | ||
485 | |||
486 | CmdFrm.length=28; | ||
487 | } | ||
488 | } // AVCTuner_DSD_direct | ||
489 | |||
490 | if((k=AVCWrite(firesat,&CmdFrm,&RspFrm))) | ||
491 | return k; | ||
492 | |||
493 | // msleep(250); | ||
494 | mdelay(500); | ||
495 | |||
496 | if(status) | ||
497 | *status=RspFrm.operand[2]; | ||
498 | return 0; | ||
499 | } | ||
500 | |||
501 | int AVCTuner_SetPIDs(struct firesat *firesat, unsigned char pidc, u16 pid[]) { | ||
502 | AVCCmdFrm CmdFrm; | ||
503 | AVCRspFrm RspFrm; | ||
504 | int pos,k; | ||
505 | |||
506 | printk(KERN_INFO "%s\n", __func__); | ||
507 | |||
508 | if(pidc > 16 && pidc != 0xFF) | ||
509 | return -EINVAL; | ||
510 | |||
511 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
512 | |||
513 | CmdFrm.cts = AVC; | ||
514 | CmdFrm.ctype = CONTROL; | ||
515 | CmdFrm.sutyp = 0x5; | ||
516 | CmdFrm.suid = firesat->subunit; | ||
517 | CmdFrm.opcode = DSD; | ||
518 | |||
519 | CmdFrm.operand[0] = 0; // source plug | ||
520 | CmdFrm.operand[1] = 0xD2; // subfunction replace | ||
521 | CmdFrm.operand[2] = 0x20; // system id = DVB | ||
522 | CmdFrm.operand[3] = 0x00; // antenna number | ||
523 | CmdFrm.operand[4] = 0x11; // system_specific_multiplex selection_length | ||
524 | CmdFrm.operand[5] = 0x00; // valid_flags [0] | ||
525 | CmdFrm.operand[6] = 0x00; // valid_flags [1] | ||
526 | |||
527 | if(firesat->type == FireSAT_DVB_T) { | ||
528 | /* CmdFrm.operand[7] = 0x00; | ||
529 | CmdFrm.operand[8] = 0x00;//(params->frequency/10) >> 24; | ||
530 | CmdFrm.operand[9] = 0x00;//((params->frequency/10) >> 16) & 0xFF; | ||
531 | CmdFrm.operand[10] = 0x00;//((params->frequency/10) >> 8) & 0xFF; | ||
532 | CmdFrm.operand[11] = 0x00;//(params->frequency/10) & 0xFF; | ||
533 | CmdFrm.operand[12] = 0x00; | ||
534 | CmdFrm.operand[13] = 0x00; | ||
535 | CmdFrm.operand[14] = 0x00; | ||
536 | |||
537 | CmdFrm.operand[15] = 0x00; // network_ID[0] | ||
538 | CmdFrm.operand[16] = 0x00; // network_ID[1] | ||
539 | */ CmdFrm.operand[17] = pidc; // Nr_of_dsd_sel_specs | ||
540 | |||
541 | pos=18; | ||
542 | } else { | ||
543 | /* CmdFrm.operand[7] = 0x00; | ||
544 | CmdFrm.operand[8] = 0x00; | ||
545 | CmdFrm.operand[9] = 0x00; | ||
546 | CmdFrm.operand[10] = 0x00; | ||
547 | |||
548 | CmdFrm.operand[11] = 0x00;//(((params->frequency/4) >> 16) & 0xFF) | (2 << 6); | ||
549 | CmdFrm.operand[12] = 0x00;//((params->frequency/4) >> 8) & 0xFF; | ||
550 | CmdFrm.operand[13] = 0x00;//(params->frequency/4) & 0xFF; | ||
551 | |||
552 | CmdFrm.operand[14] = 0x00;//((params->u.qpsk.symbol_rate/1000) >> 12) & 0xFF; | ||
553 | CmdFrm.operand[15] = 0x00;//((params->u.qpsk.symbol_rate/1000) >> 4) & 0xFF; | ||
554 | CmdFrm.operand[16] = 0x00;//((params->u.qpsk.symbol_rate/1000) << 4) & 0xF0; | ||
555 | |||
556 | CmdFrm.operand[17] = 0x00; | ||
557 | CmdFrm.operand[18] = 0x00; | ||
558 | CmdFrm.operand[19] = 0x00; // modulation | ||
559 | CmdFrm.operand[20] = 0x00; | ||
560 | CmdFrm.operand[21] = 0x00;*/ | ||
561 | CmdFrm.operand[22] = pidc; // Nr_of_dsd_sel_specs | ||
562 | |||
563 | pos=23; | ||
564 | } | ||
565 | if(pidc != 0xFF) | ||
566 | for(k=0;k<pidc;k++) { | ||
567 | CmdFrm.operand[pos++] = 0x13; // flowfunction relay | ||
568 | CmdFrm.operand[pos++] = 0x80; // dsd_sel_spec_valid_flags -> PID | ||
569 | CmdFrm.operand[pos++] = (pid[k] >> 8) & 0x1F; | ||
570 | CmdFrm.operand[pos++] = pid[k] & 0xFF; | ||
571 | CmdFrm.operand[pos++] = 0x00; // tableID | ||
572 | CmdFrm.operand[pos++] = 0x00; // filter_length | ||
573 | } | ||
574 | |||
575 | CmdFrm.length = pos+3; | ||
576 | |||
577 | if((pos+3)%4) | ||
578 | CmdFrm.length += 4 - ((pos+3)%4); | ||
579 | |||
580 | if((k=AVCWrite(firesat,&CmdFrm,&RspFrm))) | ||
581 | return k; | ||
582 | |||
583 | mdelay(250); | ||
584 | |||
585 | return 0; | ||
586 | } | ||
587 | |||
588 | int AVCTuner_GetTS(struct firesat *firesat){ | ||
589 | AVCCmdFrm CmdFrm; | ||
590 | AVCRspFrm RspFrm; | ||
591 | int k; | ||
592 | |||
593 | printk(KERN_INFO "%s\n", __func__); | ||
594 | |||
595 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
596 | |||
597 | CmdFrm.cts = AVC; | ||
598 | CmdFrm.ctype = CONTROL; | ||
599 | CmdFrm.sutyp = 0x5; | ||
600 | CmdFrm.suid = firesat->subunit; | ||
601 | CmdFrm.opcode = DSIT; | ||
602 | |||
603 | CmdFrm.operand[0] = 0; // source plug | ||
604 | CmdFrm.operand[1] = 0xD2; // subfunction replace | ||
605 | CmdFrm.operand[2] = 0xFF; //status | ||
606 | CmdFrm.operand[3] = 0x20; // system id = DVB | ||
607 | CmdFrm.operand[4] = 0x00; // antenna number | ||
608 | CmdFrm.operand[5] = 0x0; // system_specific_search_flags | ||
609 | CmdFrm.operand[6] = 0x11; // system_specific_multiplex selection_length | ||
610 | CmdFrm.operand[7] = 0x00; // valid_flags [0] | ||
611 | CmdFrm.operand[8] = 0x00; // valid_flags [1] | ||
612 | CmdFrm.operand[24] = 0x00; // nr_of_dsit_sel_specs (always 0) | ||
613 | |||
614 | CmdFrm.length = 28; | ||
615 | |||
616 | if((k=AVCWrite(firesat, &CmdFrm, &RspFrm))) return k; | ||
617 | |||
618 | mdelay(250); | ||
619 | return 0; | ||
620 | } | ||
621 | |||
622 | int AVCIdentifySubunit(struct firesat *firesat, unsigned char *systemId, int *transport, int *has_ci) { | ||
623 | AVCCmdFrm CmdFrm; | ||
624 | AVCRspFrm RspFrm; | ||
625 | |||
626 | memset(&CmdFrm,0,sizeof(AVCCmdFrm)); | ||
627 | |||
628 | CmdFrm.cts = AVC; | ||
629 | CmdFrm.ctype = CONTROL; | ||
630 | CmdFrm.sutyp = 0x5; // tuner | ||
631 | CmdFrm.suid = firesat->subunit; | ||
632 | CmdFrm.opcode = READ_DESCRIPTOR; | ||
633 | |||
634 | CmdFrm.operand[0]=DESCRIPTOR_SUBUNIT_IDENTIFIER; | ||
635 | CmdFrm.operand[1]=0xff; | ||
636 | CmdFrm.operand[2]=0x00; | ||
637 | CmdFrm.operand[3]=0x00; // length highbyte | ||
638 | CmdFrm.operand[4]=0x08; // length lowbyte | ||
639 | CmdFrm.operand[5]=0x00; // offset highbyte | ||
640 | CmdFrm.operand[6]=0x0d; // offset lowbyte | ||
641 | |||
642 | CmdFrm.length=12; | ||
643 | |||
644 | if(AVCWrite(firesat,&CmdFrm,&RspFrm)<0) | ||
645 | return -EIO; | ||
646 | |||
647 | if(RspFrm.resp != STABLE && RspFrm.resp != ACCEPTED) { | ||
648 | printk("%s: AVCWrite returned error code %d\n",__func__,RspFrm.resp); | ||
649 | return -EINVAL; | ||
650 | } | ||
651 | if(((RspFrm.operand[3] << 8) + RspFrm.operand[4]) != 8) { | ||
652 | printk("%s: Invalid response length\n",__func__); | ||
653 | return -EINVAL; | ||
654 | } | ||
655 | if(systemId) | ||
656 | *systemId = RspFrm.operand[7]; | ||
657 | if(transport) | ||
658 | *transport = RspFrm.operand[14] & 0x7; | ||
659 | switch(RspFrm.operand[14] & 0x7) { | ||
660 | case 1: | ||
661 | printk(KERN_INFO "%s: found DVB/S\n",__func__); | ||
662 | break; | ||
663 | case 2: | ||
664 | printk(KERN_INFO "%s: found DVB/C\n",__func__); | ||
665 | break; | ||
666 | case 3: | ||
667 | printk(KERN_INFO "%s: found DVB/T\n",__func__); | ||
668 | break; | ||
669 | default: | ||
670 | printk(KERN_INFO "%s: found unknown tuner id %u\n",__func__,RspFrm.operand[14] & 0x7); | ||
671 | } | ||
672 | if(has_ci) | ||
673 | *has_ci = (RspFrm.operand[14] >> 4) & 0x1; | ||
674 | return 0; | ||
675 | } | ||
676 | |||
677 | int AVCTunerStatus(struct firesat *firesat, ANTENNA_INPUT_INFO *antenna_input_info) { | ||
678 | AVCCmdFrm CmdFrm; | ||
679 | AVCRspFrm RspFrm; | ||
680 | int length; | ||
681 | |||
682 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
683 | |||
684 | CmdFrm.cts=AVC; | ||
685 | CmdFrm.ctype=CONTROL; | ||
686 | CmdFrm.sutyp=0x05; // tuner | ||
687 | CmdFrm.suid=firesat->subunit; | ||
688 | CmdFrm.opcode=READ_DESCRIPTOR; | ||
689 | |||
690 | CmdFrm.operand[0]=DESCRIPTOR_TUNER_STATUS; | ||
691 | CmdFrm.operand[1]=0xff; | ||
692 | CmdFrm.operand[2]=0x00; | ||
693 | CmdFrm.operand[3]=sizeof(ANTENNA_INPUT_INFO) >> 8; | ||
694 | CmdFrm.operand[4]=sizeof(ANTENNA_INPUT_INFO) & 0xFF; | ||
695 | CmdFrm.operand[5]=0x00; | ||
696 | CmdFrm.operand[6]=0x03; | ||
697 | CmdFrm.length=12; | ||
698 | //Absenden des AVC request und warten auf response | ||
699 | if (AVCWrite(firesat,&CmdFrm,&RspFrm) < 0) | ||
700 | return -EIO; | ||
701 | |||
702 | if(RspFrm.resp != STABLE && RspFrm.resp != ACCEPTED) { | ||
703 | printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp); | ||
704 | return -EINVAL; | ||
705 | } | ||
706 | |||
707 | length = (RspFrm.operand[3] << 8) + RspFrm.operand[4]; | ||
708 | if(length == sizeof(ANTENNA_INPUT_INFO)) | ||
709 | { | ||
710 | memcpy(antenna_input_info,&RspFrm.operand[7],length); | ||
711 | return 0; | ||
712 | } | ||
713 | printk("%s: invalid info returned from AVC\n",__func__); | ||
714 | return -EINVAL; | ||
715 | } | ||
716 | |||
717 | int AVCLNBControl(struct firesat *firesat, char voltage, char burst, | ||
718 | char conttone, char nrdiseq, | ||
719 | struct dvb_diseqc_master_cmd *diseqcmd) | ||
720 | { | ||
721 | AVCCmdFrm CmdFrm; | ||
722 | AVCRspFrm RspFrm; | ||
723 | int i,j; | ||
724 | |||
725 | printk(KERN_INFO "%s: voltage = %x, burst = %x, conttone = %x\n",__func__,voltage,burst,conttone); | ||
726 | |||
727 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
728 | |||
729 | CmdFrm.cts=AVC; | ||
730 | CmdFrm.ctype=CONTROL; | ||
731 | CmdFrm.sutyp=0x05; | ||
732 | CmdFrm.suid=firesat->subunit; | ||
733 | CmdFrm.opcode=VENDOR; | ||
734 | |||
735 | CmdFrm.operand[0]=SFE_VENDOR_DE_COMPANYID_0; | ||
736 | CmdFrm.operand[1]=SFE_VENDOR_DE_COMPANYID_1; | ||
737 | CmdFrm.operand[2]=SFE_VENDOR_DE_COMPANYID_2; | ||
738 | CmdFrm.operand[3]=SFE_VENDOR_OPCODE_LNB_CONTROL; | ||
739 | |||
740 | CmdFrm.operand[4]=voltage; | ||
741 | CmdFrm.operand[5]=nrdiseq; | ||
742 | |||
743 | i=6; | ||
744 | |||
745 | for(j=0;j<nrdiseq;j++) { | ||
746 | int k; | ||
747 | printk(KERN_INFO "%s: diseq %d len %x\n",__func__,j,diseqcmd[j].msg_len); | ||
748 | CmdFrm.operand[i++]=diseqcmd[j].msg_len; | ||
749 | |||
750 | for(k=0;k<diseqcmd[j].msg_len;k++) { | ||
751 | printk(KERN_INFO "%s: diseq %d msg[%d] = %x\n",__func__,j,k,diseqcmd[j].msg[k]); | ||
752 | CmdFrm.operand[i++]=diseqcmd[j].msg[k]; | ||
753 | } | ||
754 | } | ||
755 | |||
756 | CmdFrm.operand[i++]=burst; | ||
757 | CmdFrm.operand[i++]=conttone; | ||
758 | |||
759 | CmdFrm.length=i+3; | ||
760 | if((i+3)%4) | ||
761 | CmdFrm.length += 4 - ((i+3)%4); | ||
762 | |||
763 | /* for(j=0;j<CmdFrm.length;j++) | ||
764 | printk(KERN_INFO "%s: CmdFrm.operand[%d]=0x%x\n",__func__,j,CmdFrm.operand[j]); | ||
765 | |||
766 | printk(KERN_INFO "%s: cmdfrm.length = %u\n",__func__,CmdFrm.length); | ||
767 | */ | ||
768 | if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0) | ||
769 | return -EIO; | ||
770 | |||
771 | if(RspFrm.resp != ACCEPTED) { | ||
772 | printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp); | ||
773 | return -EINVAL; | ||
774 | } | ||
775 | |||
776 | return 0; | ||
777 | } | ||
778 | |||
779 | int AVCSubUnitInfo(struct firesat *firesat, char *subunitcount) | ||
780 | { | ||
781 | AVCCmdFrm CmdFrm; | ||
782 | AVCRspFrm RspFrm; | ||
783 | |||
784 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
785 | |||
786 | CmdFrm.cts = AVC; | ||
787 | CmdFrm.ctype = STATUS; | ||
788 | CmdFrm.sutyp = 0x1f; | ||
789 | CmdFrm.suid = 0x7; | ||
790 | CmdFrm.opcode = SUBUNIT_Info; | ||
791 | |||
792 | CmdFrm.operand[0] = 0x07; | ||
793 | CmdFrm.operand[1] = 0xff; | ||
794 | CmdFrm.operand[2] = 0xff; | ||
795 | CmdFrm.operand[3] = 0xff; | ||
796 | CmdFrm.operand[4] = 0xff; | ||
797 | |||
798 | CmdFrm.length = 8; | ||
799 | |||
800 | if(AVCWrite(firesat,&CmdFrm,&RspFrm) < 0) | ||
801 | return -EIO; | ||
802 | |||
803 | if(RspFrm.resp != STABLE) { | ||
804 | printk("%s: AVCWrite returned code %d\n",__func__,RspFrm.resp); | ||
805 | return -EINVAL; | ||
806 | } | ||
807 | |||
808 | if(subunitcount) | ||
809 | *subunitcount = (RspFrm.operand[1] & 0x7) + 1; | ||
810 | |||
811 | return 0; | ||
812 | } | ||
813 | |||
814 | static int __AVCRegisterRemoteControl(struct firesat*firesat, int internal) | ||
815 | { | ||
816 | AVCCmdFrm CmdFrm; | ||
817 | |||
818 | // printk(KERN_INFO "%s\n",__func__); | ||
819 | |||
820 | memset(&CmdFrm, 0, sizeof(AVCCmdFrm)); | ||
821 | |||
822 | CmdFrm.cts = AVC; | ||
823 | CmdFrm.ctype = NOTIFY; | ||
824 | CmdFrm.sutyp = 0x1f; | ||
825 | CmdFrm.suid = 0x7; | ||
826 | CmdFrm.opcode = VENDOR; | ||
827 | |||
828 | CmdFrm.operand[0] = SFE_VENDOR_DE_COMPANYID_0; | ||
829 | CmdFrm.operand[1] = SFE_VENDOR_DE_COMPANYID_1; | ||
830 | CmdFrm.operand[2] = SFE_VENDOR_DE_COMPANYID_2; | ||
831 | CmdFrm.operand[3] = SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL; | ||
832 | |||
833 | CmdFrm.length = 8; | ||
834 | |||
835 | if(internal) { | ||
836 | if(__AVCWrite(firesat,&CmdFrm,NULL) < 0) | ||
837 | return -EIO; | ||
838 | } else | ||
839 | if(AVCWrite(firesat,&CmdFrm,NULL) < 0) | ||
840 | return -EIO; | ||
841 | |||
842 | return 0; | ||
843 | } | ||
844 | |||
845 | int AVCRegisterRemoteControl(struct firesat*firesat) | ||
846 | { | ||
847 | return __AVCRegisterRemoteControl(firesat, 0); | ||
848 | } | ||
diff --git a/drivers/media/dvb/firesat/avc_api.h b/drivers/media/dvb/firesat/avc_api.h new file mode 100644 index 00000000000..f9a190adcd3 --- /dev/null +++ b/drivers/media/dvb/firesat/avc_api.h | |||
@@ -0,0 +1,381 @@ | |||
1 | /*************************************************************************** | ||
2 | avc_api.h - description | ||
3 | ------------------- | ||
4 | begin : Wed May 1 2000 | ||
5 | copyright : (C) 2000 by Manfred Weihs | ||
6 | copyright : (C) 2003 by Philipp Gutgsell | ||
7 | email : 0014guph@edu.fh-kaernten.ac.at | ||
8 | ***************************************************************************/ | ||
9 | |||
10 | /*************************************************************************** | ||
11 | * * | ||
12 | * This program is free software; you can redistribute it and/or modify * | ||
13 | * it under the terms of the GNU General Public License as published by * | ||
14 | * the Free Software Foundation; either version 2 of the License, or * | ||
15 | * (at your option) any later version. * | ||
16 | * * | ||
17 | ***************************************************************************/ | ||
18 | |||
19 | /* | ||
20 | This is based on code written by Peter Halwachs, | ||
21 | Thomas Groiss and Andreas Monitzer. | ||
22 | */ | ||
23 | |||
24 | |||
25 | #ifndef __AVC_API_H__ | ||
26 | #define __AVC_API_H__ | ||
27 | |||
28 | #include <linux/dvb/frontend.h> | ||
29 | |||
30 | #define BYTE unsigned char | ||
31 | #define WORD unsigned short | ||
32 | #define DWORD unsigned long | ||
33 | #define ULONG unsigned long | ||
34 | #define LONG long | ||
35 | |||
36 | |||
37 | /************************************************************* | ||
38 | FCP Address range | ||
39 | **************************************************************/ | ||
40 | |||
41 | #define RESPONSE_REGISTER 0xFFFFF0000D00ULL | ||
42 | #define COMMAND_REGISTER 0xFFFFF0000B00ULL | ||
43 | #define PCR_BASE_ADDRESS 0xFFFFF0000900ULL | ||
44 | |||
45 | |||
46 | /************************************************************ | ||
47 | definition of structures | ||
48 | *************************************************************/ | ||
49 | typedef struct { | ||
50 | int Nr_SourcePlugs; | ||
51 | int Nr_DestinationPlugs; | ||
52 | } TunerInfo; | ||
53 | |||
54 | |||
55 | /*********************************************** | ||
56 | |||
57 | supported cts | ||
58 | |||
59 | ************************************************/ | ||
60 | |||
61 | #define AVC 0x0 | ||
62 | |||
63 | // FCP command frame with ctype = 0x0 is AVC command frame | ||
64 | |||
65 | #ifdef __LITTLE_ENDIAN | ||
66 | |||
67 | // Definition FCP Command Frame | ||
68 | typedef struct _AVCCmdFrm | ||
69 | { | ||
70 | // AV/C command frame | ||
71 | BYTE ctype : 4 ; // command type | ||
72 | BYTE cts : 4 ; // always 0x0 for AVC | ||
73 | BYTE suid : 3 ; // subunit ID | ||
74 | BYTE sutyp : 5 ; // subunit_typ | ||
75 | BYTE opcode : 8 ; // opcode | ||
76 | BYTE operand[509] ; // array of operands [1-507] | ||
77 | int length; //length of the command frame | ||
78 | } AVCCmdFrm ; | ||
79 | |||
80 | // Definition FCP Response Frame | ||
81 | typedef struct _AVCRspFrm | ||
82 | { | ||
83 | // AV/C response frame | ||
84 | BYTE resp : 4 ; // response type | ||
85 | BYTE cts : 4 ; // always 0x0 for AVC | ||
86 | BYTE suid : 3 ; // subunit ID | ||
87 | BYTE sutyp : 5 ; // subunit_typ | ||
88 | BYTE opcode : 8 ; // opcode | ||
89 | BYTE operand[509] ; // array of operands [1-507] | ||
90 | int length; //length of the response frame | ||
91 | } AVCRspFrm ; | ||
92 | |||
93 | #else | ||
94 | |||
95 | typedef struct _AVCCmdFrm | ||
96 | { | ||
97 | BYTE cts:4; | ||
98 | BYTE ctype:4; | ||
99 | BYTE sutyp:5; | ||
100 | BYTE suid:3; | ||
101 | BYTE opcode; | ||
102 | BYTE operand[509]; | ||
103 | int length; | ||
104 | } AVCCmdFrm; | ||
105 | |||
106 | typedef struct _AVCRspFrm | ||
107 | { | ||
108 | BYTE cts:4; | ||
109 | BYTE resp:4; | ||
110 | BYTE sutyp:5; | ||
111 | BYTE suid:3; | ||
112 | BYTE opcode; | ||
113 | BYTE operand[509]; | ||
114 | int length; | ||
115 | } AVCRspFrm; | ||
116 | |||
117 | #endif | ||
118 | |||
119 | /************************************************************* | ||
120 | AVC command types (ctype) | ||
121 | **************************************************************/// | ||
122 | #define CONTROL 0x00 | ||
123 | #define STATUS 0x01 | ||
124 | #define INQUIRY 0x02 | ||
125 | #define NOTIFY 0x03 | ||
126 | |||
127 | /************************************************************* | ||
128 | AVC respond types | ||
129 | **************************************************************/// | ||
130 | #define NOT_IMPLEMENTED 0x8 | ||
131 | #define ACCEPTED 0x9 | ||
132 | #define REJECTED 0xA | ||
133 | #define STABLE 0xC | ||
134 | #define CHANGED 0xD | ||
135 | #define INTERIM 0xF | ||
136 | |||
137 | /************************************************************* | ||
138 | AVC opcodes | ||
139 | **************************************************************/// | ||
140 | #define CONNECT 0x24 | ||
141 | #define DISCONNECT 0x25 | ||
142 | #define UNIT_INFO 0x30 | ||
143 | #define SUBUNIT_Info 0x31 | ||
144 | #define VENDOR 0x00 | ||
145 | |||
146 | #define PLUG_INFO 0x02 | ||
147 | #define OPEN_DESCRIPTOR 0x08 | ||
148 | #define READ_DESCRIPTOR 0x09 | ||
149 | #define OBJECT_NUMBER_SELECT 0x0D | ||
150 | |||
151 | /************************************************************* | ||
152 | AVCTuner opcodes | ||
153 | **************************************************************/ | ||
154 | |||
155 | #define DSIT 0xC8 | ||
156 | #define DSD 0xCB | ||
157 | #define DESCRIPTOR_TUNER_STATUS 0x80 | ||
158 | #define DESCRIPTOR_SUBUNIT_IDENTIFIER 0x00 | ||
159 | |||
160 | /************************************************************* | ||
161 | AVCTuner list types | ||
162 | **************************************************************/ | ||
163 | #define Multiplex_List 0x80 | ||
164 | #define Service_List 0x82 | ||
165 | |||
166 | /************************************************************* | ||
167 | AVCTuner object entries | ||
168 | **************************************************************/ | ||
169 | #define Multiplex 0x80 | ||
170 | #define Service 0x82 | ||
171 | #define Service_with_specified_components 0x83 | ||
172 | #define Preferred_components 0x90 | ||
173 | #define Component 0x84 | ||
174 | |||
175 | /************************************************************* | ||
176 | Vendor-specific commands | ||
177 | **************************************************************/ | ||
178 | |||
179 | // digital everywhere vendor ID | ||
180 | #define SFE_VENDOR_DE_COMPANYID_0 0x00 | ||
181 | #define SFE_VENDOR_DE_COMPANYID_1 0x12 | ||
182 | #define SFE_VENDOR_DE_COMPANYID_2 0x87 | ||
183 | |||
184 | #define SFE_VENDOR_MAX_NR_COMPONENTS 0x4 | ||
185 | #define SFE_VENDOR_MAX_NR_SERVICES 0x3 | ||
186 | #define SFE_VENDOR_MAX_NR_DSD_ELEMENTS 0x10 | ||
187 | |||
188 | // vendor commands | ||
189 | #define SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL 0x0A | ||
190 | #define SFE_VENDOR_OPCODE_LNB_CONTROL 0x52 | ||
191 | #define SFE_VENDOR_OPCODE_TUNE_QPSK 0x58 // QPSK command for DVB-S | ||
192 | |||
193 | // TODO: following vendor specific commands needs to be implemented | ||
194 | #define SFE_VENDOR_OPCODE_GET_FIRMWARE_VERSION 0x00 | ||
195 | #define SFE_VENDOR_OPCODE_HOST2CA 0x56 | ||
196 | #define SFE_VENDOR_OPCODE_CA2HOST 0x57 | ||
197 | #define SFE_VENDOR_OPCODE_CISTATUS 0x59 | ||
198 | #define SFE_VENDOR_OPCODE_TUNE_QPSK2 0x60 // QPSK command for DVB-S2 devices | ||
199 | |||
200 | |||
201 | //AVCTuner DVB identifier service_ID | ||
202 | #define DVB 0x20 | ||
203 | |||
204 | /************************************************************* | ||
205 | AVC descriptor types | ||
206 | **************************************************************/ | ||
207 | |||
208 | #define Subunit_Identifier_Descriptor 0x00 | ||
209 | #define Tuner_Status_Descriptor 0x80 | ||
210 | |||
211 | typedef struct { | ||
212 | BYTE Subunit_Type; | ||
213 | BYTE Max_Subunit_ID; | ||
214 | } SUBUNIT_INFO; | ||
215 | |||
216 | /************************************************************* | ||
217 | |||
218 | AVCTuner DVB object IDs are 6 byte long | ||
219 | |||
220 | **************************************************************/ | ||
221 | |||
222 | typedef struct { | ||
223 | BYTE Byte0; | ||
224 | BYTE Byte1; | ||
225 | BYTE Byte2; | ||
226 | BYTE Byte3; | ||
227 | BYTE Byte4; | ||
228 | BYTE Byte5; | ||
229 | }OBJECT_ID; | ||
230 | |||
231 | /************************************************************* | ||
232 | MULIPLEX Structs | ||
233 | **************************************************************/ | ||
234 | typedef struct | ||
235 | { | ||
236 | #ifdef __LITTLE_ENDIAN | ||
237 | BYTE RF_frequency_hByte:6; | ||
238 | BYTE raster_Frequency:2;//Bit7,6 raster frequency | ||
239 | #else | ||
240 | BYTE raster_Frequency:2; | ||
241 | BYTE RF_frequency_hByte:6; | ||
242 | #endif | ||
243 | BYTE RF_frequency_mByte; | ||
244 | BYTE RF_frequency_lByte; | ||
245 | |||
246 | }FREQUENCY; | ||
247 | |||
248 | #ifdef __LITTLE_ENDIAN | ||
249 | |||
250 | typedef struct | ||
251 | { | ||
252 | BYTE Modulation :1; | ||
253 | BYTE FEC_inner :1; | ||
254 | BYTE FEC_outer :1; | ||
255 | BYTE Symbol_Rate :1; | ||
256 | BYTE Frequency :1; | ||
257 | BYTE Orbital_Pos :1; | ||
258 | BYTE Polarisation :1; | ||
259 | BYTE reserved_fields :1; | ||
260 | BYTE reserved1 :7; | ||
261 | BYTE Network_ID :1; | ||
262 | |||
263 | }MULTIPLEX_VALID_FLAGS; | ||
264 | |||
265 | typedef struct | ||
266 | { | ||
267 | BYTE GuardInterval:1; | ||
268 | BYTE CodeRateLPStream:1; | ||
269 | BYTE CodeRateHPStream:1; | ||
270 | BYTE HierarchyInfo:1; | ||
271 | BYTE Constellation:1; | ||
272 | BYTE Bandwidth:1; | ||
273 | BYTE CenterFrequency:1; | ||
274 | BYTE reserved1:1; | ||
275 | BYTE reserved2:5; | ||
276 | BYTE OtherFrequencyFlag:1; | ||
277 | BYTE TransmissionMode:1; | ||
278 | BYTE NetworkId:1; | ||
279 | }MULTIPLEX_VALID_FLAGS_DVBT; | ||
280 | |||
281 | #else | ||
282 | |||
283 | typedef struct { | ||
284 | BYTE reserved_fields:1; | ||
285 | BYTE Polarisation:1; | ||
286 | BYTE Orbital_Pos:1; | ||
287 | BYTE Frequency:1; | ||
288 | BYTE Symbol_Rate:1; | ||
289 | BYTE FEC_outer:1; | ||
290 | BYTE FEC_inner:1; | ||
291 | BYTE Modulation:1; | ||
292 | BYTE Network_ID:1; | ||
293 | BYTE reserved1:7; | ||
294 | }MULTIPLEX_VALID_FLAGS; | ||
295 | |||
296 | typedef struct { | ||
297 | BYTE reserved1:1; | ||
298 | BYTE CenterFrequency:1; | ||
299 | BYTE Bandwidth:1; | ||
300 | BYTE Constellation:1; | ||
301 | BYTE HierarchyInfo:1; | ||
302 | BYTE CodeRateHPStream:1; | ||
303 | BYTE CodeRateLPStream:1; | ||
304 | BYTE GuardInterval:1; | ||
305 | BYTE NetworkId:1; | ||
306 | BYTE TransmissionMode:1; | ||
307 | BYTE OtherFrequencyFlag:1; | ||
308 | BYTE reserved2:5; | ||
309 | }MULTIPLEX_VALID_FLAGS_DVBT; | ||
310 | |||
311 | #endif | ||
312 | |||
313 | typedef union { | ||
314 | MULTIPLEX_VALID_FLAGS Bits; | ||
315 | MULTIPLEX_VALID_FLAGS_DVBT Bits_T; | ||
316 | struct { | ||
317 | BYTE ByteHi; | ||
318 | BYTE ByteLo; | ||
319 | } Valid_Word; | ||
320 | } M_VALID_FLAGS; | ||
321 | |||
322 | typedef struct | ||
323 | { | ||
324 | #ifdef __LITTLE_ENDIAN | ||
325 | BYTE ActiveSystem; | ||
326 | BYTE reserved:5; | ||
327 | BYTE NoRF:1; | ||
328 | BYTE Moving:1; | ||
329 | BYTE Searching:1; | ||
330 | |||
331 | BYTE SelectedAntenna:7; | ||
332 | BYTE Input:1; | ||
333 | |||
334 | BYTE BER[4]; | ||
335 | |||
336 | BYTE SignalStrength; | ||
337 | FREQUENCY Frequency; | ||
338 | |||
339 | BYTE ManDepInfoLength; | ||
340 | #else | ||
341 | BYTE ActiveSystem; | ||
342 | BYTE Searching:1; | ||
343 | BYTE Moving:1; | ||
344 | BYTE NoRF:1; | ||
345 | BYTE reserved:5; | ||
346 | |||
347 | BYTE Input:1; | ||
348 | BYTE SelectedAntenna:7; | ||
349 | |||
350 | BYTE BER[4]; | ||
351 | |||
352 | BYTE SignalStrength; | ||
353 | FREQUENCY Frequency; | ||
354 | |||
355 | BYTE ManDepInfoLength; | ||
356 | #endif | ||
357 | } ANTENNA_INPUT_INFO; // 11 Byte | ||
358 | |||
359 | #define LNBCONTROL_DONTCARE 0xff | ||
360 | |||
361 | |||
362 | extern int AVCWrite(struct firesat *firesat, const AVCCmdFrm *CmdFrm, AVCRspFrm *RspFrm); | ||
363 | extern int AVCRecv(struct firesat *firesat, u8 *data, size_t length); | ||
364 | |||
365 | extern int AVCTuner_DSIT(struct firesat *firesat, | ||
366 | int Source_Plug, | ||
367 | struct dvb_frontend_parameters *params, | ||
368 | BYTE *status); | ||
369 | |||
370 | extern int AVCTunerStatus(struct firesat *firesat, ANTENNA_INPUT_INFO *antenna_input_info); | ||
371 | extern int AVCTuner_DSD(struct firesat *firesat, struct dvb_frontend_parameters *params, BYTE *status); | ||
372 | extern int AVCTuner_SetPIDs(struct firesat *firesat, unsigned char pidc, u16 pid[]); | ||
373 | extern int AVCTuner_GetTS(struct firesat *firesat); | ||
374 | |||
375 | extern int AVCIdentifySubunit(struct firesat *firesat, unsigned char *systemId, int *transport, int *has_ci); | ||
376 | extern int AVCLNBControl(struct firesat *firesat, char voltage, char burst, char conttone, char nrdiseq, struct dvb_diseqc_master_cmd *diseqcmd); | ||
377 | extern int AVCSubUnitInfo(struct firesat *firesat, char *subunitcount); | ||
378 | extern int AVCRegisterRemoteControl(struct firesat *firesat); | ||
379 | |||
380 | #endif | ||
381 | |||
diff --git a/drivers/media/dvb/firesat/cmp.c b/drivers/media/dvb/firesat/cmp.c new file mode 100644 index 00000000000..37b91f3f7ff --- /dev/null +++ b/drivers/media/dvb/firesat/cmp.c | |||
@@ -0,0 +1,230 @@ | |||
1 | #include "cmp.h" | ||
2 | #include <ieee1394.h> | ||
3 | #include <nodemgr.h> | ||
4 | #include <highlevel.h> | ||
5 | #include <ohci1394.h> | ||
6 | #include <hosts.h> | ||
7 | #include <ieee1394_core.h> | ||
8 | #include <ieee1394_transactions.h> | ||
9 | #include "avc_api.h" | ||
10 | |||
11 | typedef struct _OPCR | ||
12 | { | ||
13 | BYTE PTPConnCount : 6 ; // Point to point connect. counter | ||
14 | BYTE BrConnCount : 1 ; // Broadcast connection counter | ||
15 | BYTE OnLine : 1 ; // On Line | ||
16 | |||
17 | BYTE ChNr : 6 ; // Channel number | ||
18 | BYTE Res : 2 ; // Reserved | ||
19 | |||
20 | BYTE PayloadHi : 2 ; // Payoad high bits | ||
21 | BYTE OvhdID : 4 ; // Overhead ID | ||
22 | BYTE DataRate : 2 ; // Data Rate | ||
23 | |||
24 | BYTE PayloadLo ; // Payoad low byte | ||
25 | } OPCR ; | ||
26 | |||
27 | #define FIRESAT_SPEED IEEE1394_SPEED_400 | ||
28 | |||
29 | /* hpsb_lock is being removed from the kernel-source, | ||
30 | * therefor we define our own 'firesat_hpsb_lock'*/ | ||
31 | |||
32 | int send_packet_and_wait(struct hpsb_packet *packet); | ||
33 | |||
34 | int firesat_hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation, | ||
35 | u64 addr, int extcode, quadlet_t * data, quadlet_t arg) { | ||
36 | |||
37 | struct hpsb_packet *packet; | ||
38 | int retval = 0; | ||
39 | |||
40 | BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet | ||
41 | |||
42 | packet = hpsb_make_lockpacket(host, node, addr, extcode, data, arg); | ||
43 | if (!packet) | ||
44 | return -ENOMEM; | ||
45 | |||
46 | packet->generation = generation; | ||
47 | retval = send_packet_and_wait(packet); | ||
48 | if (retval < 0) | ||
49 | goto hpsb_lock_fail; | ||
50 | |||
51 | retval = hpsb_packet_success(packet); | ||
52 | |||
53 | if (retval == 0) { | ||
54 | *data = packet->data[0]; | ||
55 | } | ||
56 | |||
57 | hpsb_lock_fail: | ||
58 | hpsb_free_tlabel(packet); | ||
59 | hpsb_free_packet(packet); | ||
60 | |||
61 | return retval; | ||
62 | } | ||
63 | |||
64 | |||
65 | static int cmp_read(struct firesat *firesat, void *buffer, u64 addr, size_t length) { | ||
66 | int ret; | ||
67 | if(down_interruptible(&firesat->avc_sem)) | ||
68 | return -EINTR; | ||
69 | |||
70 | ret = hpsb_read(firesat->host, firesat->nodeentry->nodeid, firesat->nodeentry->generation, | ||
71 | addr, buffer, length); | ||
72 | |||
73 | up(&firesat->avc_sem); | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | static int cmp_lock(struct firesat *firesat, quadlet_t *data, u64 addr, quadlet_t arg, int ext_tcode) { | ||
78 | int ret; | ||
79 | if(down_interruptible(&firesat->avc_sem)) | ||
80 | return -EINTR; | ||
81 | |||
82 | ret = firesat_hpsb_lock(firesat->host, firesat->nodeentry->nodeid, firesat->nodeentry->generation, | ||
83 | addr, ext_tcode, data, arg); | ||
84 | |||
85 | up(&firesat->avc_sem); | ||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | //try establishing a point-to-point connection (may be interrupted by a busreset | ||
90 | int try_CMPEstablishPPconnection(struct firesat *firesat, int output_plug, int iso_channel) { | ||
91 | unsigned int BWU; //bandwidth to allocate | ||
92 | |||
93 | quadlet_t old_oPCR,test_oPCR = 0x0; | ||
94 | u64 oPCR_address=0xfffff0000904ull+(output_plug << 2); | ||
95 | int result=cmp_read(firesat, &test_oPCR, oPCR_address, 4); | ||
96 | |||
97 | printk(KERN_INFO "%s: nodeid = %d\n",__func__,firesat->nodeentry->nodeid); | ||
98 | |||
99 | if (result < 0) { | ||
100 | printk("%s: cannot read oPCR\n", __func__); | ||
101 | return result; | ||
102 | } else { | ||
103 | printk(KERN_INFO "%s: oPCR = %08x\n",__func__,test_oPCR); | ||
104 | do { | ||
105 | OPCR *hilf= (OPCR*) &test_oPCR; | ||
106 | |||
107 | if (!hilf->OnLine) { | ||
108 | printk("%s: Output offline; oPCR: %08x\n", __func__, test_oPCR); | ||
109 | return -EBUSY; | ||
110 | } else { | ||
111 | quadlet_t new_oPCR; | ||
112 | |||
113 | old_oPCR=test_oPCR; | ||
114 | if (hilf->PTPConnCount) { | ||
115 | if (hilf->ChNr != iso_channel) { | ||
116 | printk("%s: Output plug has already connection on channel %u; cannot change it to channel %u\n",__func__,hilf->ChNr,iso_channel); | ||
117 | return -EBUSY; | ||
118 | } else | ||
119 | printk(KERN_INFO "%s: Overlaying existing connection; connection counter was: %u\n",__func__, hilf->PTPConnCount); | ||
120 | BWU=0; //we allocate no bandwidth (is this necessary?) | ||
121 | } else { | ||
122 | hilf->ChNr=iso_channel; | ||
123 | hilf->DataRate=FIRESAT_SPEED; | ||
124 | |||
125 | hilf->OvhdID=0; //FIXME: that is for worst case -> optimize | ||
126 | BWU=hilf->OvhdID?hilf->OvhdID*32:512; | ||
127 | BWU += (hilf->PayloadLo + (hilf->PayloadHi << 8) +3) * (2 << (3-hilf->DataRate)); | ||
128 | /* if (allocate_1394_resources(iso_channel,BWU)) | ||
129 | { | ||
130 | cout << "Allocation of resources failed\n"; | ||
131 | return -2; | ||
132 | }*/ | ||
133 | } | ||
134 | |||
135 | hilf->PTPConnCount++; | ||
136 | new_oPCR=test_oPCR; | ||
137 | printk(KERN_INFO "%s: trying compare_swap...\n",__func__); | ||
138 | printk(KERN_INFO "%s: oPCR_old: %08x, oPCR_new: %08x\n",__func__, old_oPCR, new_oPCR); | ||
139 | result=cmp_lock(firesat, &test_oPCR, oPCR_address, old_oPCR, 2); | ||
140 | |||
141 | if (result < 0) { | ||
142 | printk("%s: cannot compare_swap oPCR\n",__func__); | ||
143 | return result; | ||
144 | } | ||
145 | if ((old_oPCR != test_oPCR) && (!((OPCR*) &old_oPCR)->PTPConnCount)) | ||
146 | { | ||
147 | printk("%s: change of oPCR failed -> freeing resources\n",__func__); | ||
148 | // hilf= (OPCR*) &new_oPCR; | ||
149 | // unsigned int BWU=hilf->OvhdID?hilf->OvhdID*32:512; | ||
150 | // BWU += (hilf->Payload+3) * (2 << (3-hilf->DataRate)); | ||
151 | /* if (deallocate_1394_resources(iso_channel,BWU)) | ||
152 | { | ||
153 | |||
154 | cout << "Deallocation of resources failed\n"; | ||
155 | return -3; | ||
156 | }*/ | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | while (old_oPCR != test_oPCR); | ||
161 | } | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | //try breaking a point-to-point connection (may be interrupted by a busreset | ||
166 | int try_CMPBreakPPconnection(struct firesat *firesat, int output_plug,int iso_channel) { | ||
167 | quadlet_t old_oPCR,test_oPCR; | ||
168 | |||
169 | u64 oPCR_address=0xfffff0000904ull+(output_plug << 2); | ||
170 | int result=cmp_read(firesat, &test_oPCR, oPCR_address, 4); | ||
171 | |||
172 | printk(KERN_INFO "%s\n",__func__); | ||
173 | |||
174 | if (result < 0) { | ||
175 | printk("%s: cannot read oPCR\n", __func__); | ||
176 | return result; | ||
177 | } else { | ||
178 | do { | ||
179 | OPCR *hilf= (OPCR*) &test_oPCR; | ||
180 | |||
181 | if (!hilf->OnLine || !hilf->PTPConnCount || hilf->ChNr != iso_channel) { | ||
182 | printk("%s: Output plug does not have PtP-connection on that channel; oPCR: %08x\n", __func__, test_oPCR); | ||
183 | return -EINVAL; | ||
184 | } else { | ||
185 | quadlet_t new_oPCR; | ||
186 | old_oPCR=test_oPCR; | ||
187 | hilf->PTPConnCount--; | ||
188 | new_oPCR=test_oPCR; | ||
189 | |||
190 | // printk(KERN_INFO "%s: trying compare_swap...\n", __func__); | ||
191 | result=cmp_lock(firesat, &test_oPCR, oPCR_address, old_oPCR, 2); | ||
192 | if (result < 0) { | ||
193 | printk("%s: cannot compare_swap oPCR\n",__func__); | ||
194 | return result; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | } while (old_oPCR != test_oPCR); | ||
199 | |||
200 | /* hilf = (OPCR*) &old_oPCR; | ||
201 | if (hilf->PTPConnCount == 1) { // if we were the last owner of this connection | ||
202 | cout << "deallocating 1394 resources\n"; | ||
203 | unsigned int BWU=hilf->OvhdID?hilf->OvhdID*32:512; | ||
204 | BWU += (hilf->PayloadLo + (hilf->PayloadHi << 8) +3) * (2 << (3-hilf->DataRate)); | ||
205 | if (deallocate_1394_resources(iso_channel,BWU)) | ||
206 | { | ||
207 | cout << "Deallocation of resources failed\n"; | ||
208 | return -3; | ||
209 | } | ||
210 | }*/ | ||
211 | } | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static void complete_packet(void *data) { | ||
216 | complete((struct completion *) data); | ||
217 | } | ||
218 | |||
219 | int send_packet_and_wait(struct hpsb_packet *packet) { | ||
220 | struct completion done; | ||
221 | int retval; | ||
222 | |||
223 | init_completion(&done); | ||
224 | hpsb_set_packet_complete_task(packet, complete_packet, &done); | ||
225 | retval = hpsb_send_packet(packet); | ||
226 | if (retval == 0) | ||
227 | wait_for_completion(&done); | ||
228 | |||
229 | return retval; | ||
230 | } | ||
diff --git a/drivers/media/dvb/firesat/cmp.h b/drivers/media/dvb/firesat/cmp.h new file mode 100644 index 00000000000..d43fbc29f26 --- /dev/null +++ b/drivers/media/dvb/firesat/cmp.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef __FIRESAT__CMP_H_ | ||
2 | #define __FIRESAT__CMP_H_ | ||
3 | |||
4 | #include "firesat.h" | ||
5 | |||
6 | extern int try_CMPEstablishPPconnection(struct firesat *firesat, int output_plug, int iso_channel); | ||
7 | extern int try_CMPBreakPPconnection(struct firesat *firesat, int output_plug,int iso_channel); | ||
8 | |||
9 | #endif | ||
diff --git a/drivers/media/dvb/firesat/firesat-ci.c b/drivers/media/dvb/firesat/firesat-ci.c new file mode 100644 index 00000000000..862d9553c5b --- /dev/null +++ b/drivers/media/dvb/firesat/firesat-ci.c | |||
@@ -0,0 +1,95 @@ | |||
1 | #include "firesat-ci.h" | ||
2 | #include "firesat.h" | ||
3 | #include "avc_api.h" | ||
4 | |||
5 | #include <linux/dvb/ca.h> | ||
6 | #include <dvbdev.h> | ||
7 | /* | ||
8 | static int firesat_ca_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *parg) { | ||
9 | //struct firesat *firesat = (struct firesat*)((struct dvb_device*)file->private_data)->priv; | ||
10 | int err; | ||
11 | |||
12 | // printk(KERN_INFO "%s: ioctl %d\n",__func__,cmd); | ||
13 | |||
14 | switch(cmd) { | ||
15 | case CA_RESET: | ||
16 | // TODO: Needs to be implemented with new AVC Vendor commands | ||
17 | break; | ||
18 | case CA_GET_CAP: { | ||
19 | ca_caps_t *cap=(ca_caps_t*)parg; | ||
20 | cap->slot_num = 1; | ||
21 | cap->slot_type = CA_CI_LINK; | ||
22 | cap->descr_num = 1; | ||
23 | cap->descr_type = CA_DSS; | ||
24 | |||
25 | err = 0; | ||
26 | break; | ||
27 | } | ||
28 | case CA_GET_SLOT_INFO: { | ||
29 | ca_slot_info_t *slot=(ca_slot_info_t*)parg; | ||
30 | if(slot->num == 0) { | ||
31 | slot->type = CA_CI | CA_CI_LINK | CA_DESCR; | ||
32 | slot->flags = CA_CI_MODULE_PRESENT | CA_CI_MODULE_READY; | ||
33 | } else { | ||
34 | slot->type = 0; | ||
35 | slot->flags = 0; | ||
36 | } | ||
37 | err = 0; | ||
38 | break; | ||
39 | } | ||
40 | default: | ||
41 | err=-EINVAL; | ||
42 | } | ||
43 | return err; | ||
44 | } | ||
45 | */ | ||
46 | |||
47 | static int firesat_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { | ||
48 | //return dvb_usercopy(inode, file, cmd, arg, firesat_ca_do_ioctl); | ||
49 | return dvb_generic_ioctl(inode, file, cmd, arg); | ||
50 | } | ||
51 | |||
52 | static int firesat_ca_io_open(struct inode *inode, struct file *file) { | ||
53 | printk(KERN_INFO "%s!\n",__func__); | ||
54 | return dvb_generic_open(inode, file); | ||
55 | } | ||
56 | |||
57 | static int firesat_ca_io_release(struct inode *inode, struct file *file) { | ||
58 | printk(KERN_INFO "%s!\n",__func__); | ||
59 | return dvb_generic_release(inode, file); | ||
60 | } | ||
61 | |||
62 | static unsigned int firesat_ca_io_poll(struct file *file, poll_table *wait) { | ||
63 | // printk(KERN_INFO "%s!\n",__func__); | ||
64 | return POLLIN; | ||
65 | } | ||
66 | |||
67 | static struct file_operations firesat_ca_fops = { | ||
68 | .owner = THIS_MODULE, | ||
69 | .read = NULL, // There is no low level read anymore | ||
70 | .write = NULL, // There is no low level write anymore | ||
71 | .ioctl = firesat_ca_ioctl, | ||
72 | .open = firesat_ca_io_open, | ||
73 | .release = firesat_ca_io_release, | ||
74 | .poll = firesat_ca_io_poll, | ||
75 | }; | ||
76 | |||
77 | static struct dvb_device firesat_ca = { | ||
78 | .priv = NULL, | ||
79 | .users = 1, | ||
80 | .readers = 1, | ||
81 | .writers = 1, | ||
82 | .fops = &firesat_ca_fops, | ||
83 | }; | ||
84 | |||
85 | int firesat_ca_init(struct firesat *firesat) { | ||
86 | int ret = dvb_register_device(firesat->adapter, &firesat->cadev, &firesat_ca, firesat, DVB_DEVICE_CA); | ||
87 | if(ret) return ret; | ||
88 | |||
89 | // avoid unnecessary delays, we're not talking to the CI yet anyways | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | void firesat_ca_release(struct firesat *firesat) { | ||
94 | dvb_unregister_device(firesat->cadev); | ||
95 | } | ||
diff --git a/drivers/media/dvb/firesat/firesat-ci.h b/drivers/media/dvb/firesat/firesat-ci.h new file mode 100644 index 00000000000..dafe3f0f0cc --- /dev/null +++ b/drivers/media/dvb/firesat/firesat-ci.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef __FIRESAT_CA_H | ||
2 | #define __FIRESAT_CA_H | ||
3 | |||
4 | #include "firesat.h" | ||
5 | |||
6 | int firesat_ca_init(struct firesat *firesat); | ||
7 | void firesat_ca_release(struct firesat *firesat); | ||
8 | |||
9 | #endif | ||
diff --git a/drivers/media/dvb/firesat/firesat-rc.c b/drivers/media/dvb/firesat/firesat-rc.c new file mode 100644 index 00000000000..e300b81008a --- /dev/null +++ b/drivers/media/dvb/firesat/firesat-rc.c | |||
@@ -0,0 +1,84 @@ | |||
1 | #include "firesat.h" | ||
2 | #include "firesat-rc.h" | ||
3 | |||
4 | #include <linux/input.h> | ||
5 | |||
6 | static u16 firesat_irtable[] = { | ||
7 | KEY_ESC, | ||
8 | KEY_F9, | ||
9 | KEY_1, | ||
10 | KEY_2, | ||
11 | KEY_3, | ||
12 | KEY_4, | ||
13 | KEY_5, | ||
14 | KEY_6, | ||
15 | KEY_7, | ||
16 | KEY_8, | ||
17 | KEY_9, | ||
18 | KEY_I, | ||
19 | KEY_0, | ||
20 | KEY_ENTER, | ||
21 | KEY_RED, | ||
22 | KEY_UP, | ||
23 | KEY_GREEN, | ||
24 | KEY_F10, | ||
25 | KEY_SPACE, | ||
26 | KEY_F11, | ||
27 | KEY_YELLOW, | ||
28 | KEY_DOWN, | ||
29 | KEY_BLUE, | ||
30 | KEY_Z, | ||
31 | KEY_P, | ||
32 | KEY_PAGEDOWN, | ||
33 | KEY_LEFT, | ||
34 | KEY_W, | ||
35 | KEY_RIGHT, | ||
36 | KEY_P, | ||
37 | KEY_M, | ||
38 | KEY_R, | ||
39 | KEY_V, | ||
40 | KEY_C, | ||
41 | 0 | ||
42 | }; | ||
43 | |||
44 | static struct input_dev firesat_idev; | ||
45 | |||
46 | int firesat_register_rc(void) | ||
47 | { | ||
48 | int index; | ||
49 | |||
50 | memset(&firesat_idev, 0, sizeof(firesat_idev)); | ||
51 | |||
52 | firesat_idev.evbit[0] = BIT(EV_KEY); | ||
53 | |||
54 | for (index = 0; firesat_irtable[index] != 0; index++) | ||
55 | set_bit(firesat_irtable[index], firesat_idev.keybit); | ||
56 | |||
57 | return input_register_device(&firesat_idev); | ||
58 | } | ||
59 | |||
60 | int firesat_unregister_rc(void) | ||
61 | { | ||
62 | input_unregister_device(&firesat_idev); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | int firesat_got_remotecontrolcode(u16 code) | ||
67 | { | ||
68 | u16 keycode; | ||
69 | |||
70 | if (code > 0x4500 && code < 0x4520) | ||
71 | keycode = firesat_irtable[code - 0x4501]; | ||
72 | else if (code > 0x453f && code < 0x4543) | ||
73 | keycode = firesat_irtable[code - 0x4521]; | ||
74 | else { | ||
75 | printk(KERN_DEBUG "%s: invalid key code 0x%04x\n", __func__, | ||
76 | code); | ||
77 | return -EINVAL; | ||
78 | } | ||
79 | |||
80 | input_report_key(&firesat_idev, keycode, 1); | ||
81 | input_report_key(&firesat_idev, keycode, 0); | ||
82 | |||
83 | return 0; | ||
84 | } | ||
diff --git a/drivers/media/dvb/firesat/firesat-rc.h b/drivers/media/dvb/firesat/firesat-rc.h new file mode 100644 index 00000000000..e89a8069ba8 --- /dev/null +++ b/drivers/media/dvb/firesat/firesat-rc.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef __FIRESAT_LIRC_H | ||
2 | #define __FIRESAT_LIRC_H | ||
3 | |||
4 | extern int firesat_register_rc(void); | ||
5 | extern int firesat_unregister_rc(void); | ||
6 | extern int firesat_got_remotecontrolcode(u16 code); | ||
7 | |||
8 | #endif | ||
9 | |||
diff --git a/drivers/media/dvb/firesat/firesat.h b/drivers/media/dvb/firesat/firesat.h new file mode 100644 index 00000000000..f852a1ac774 --- /dev/null +++ b/drivers/media/dvb/firesat/firesat.h | |||
@@ -0,0 +1,85 @@ | |||
1 | #ifndef __FIRESAT_H | ||
2 | #define __FIRESAT_H | ||
3 | |||
4 | #include "dvb_frontend.h" | ||
5 | #include "dmxdev.h" | ||
6 | #include "dvb_demux.h" | ||
7 | #include "dvb_net.h" | ||
8 | |||
9 | #include <linux/semaphore.h> | ||
10 | #include <linux/dvb/frontend.h> | ||
11 | #include <linux/dvb/dmx.h> | ||
12 | |||
13 | enum model_type { | ||
14 | FireSAT_DVB_S = 1, | ||
15 | FireSAT_DVB_C = 2, | ||
16 | FireSAT_DVB_T = 3 | ||
17 | }; | ||
18 | |||
19 | struct firesat { | ||
20 | struct dvb_demux dvb_demux; | ||
21 | char *model_name; | ||
22 | |||
23 | /* DVB bits */ | ||
24 | struct dvb_adapter *adapter; | ||
25 | struct dmxdev dmxdev; | ||
26 | struct dvb_demux demux; | ||
27 | struct dmx_frontend frontend; | ||
28 | struct dvb_net dvbnet; | ||
29 | struct dvb_frontend_info *frontend_info; | ||
30 | struct dvb_frontend *fe; | ||
31 | |||
32 | struct dvb_device *cadev; | ||
33 | int has_ci; | ||
34 | |||
35 | struct semaphore avc_sem; | ||
36 | atomic_t avc_reply_received; | ||
37 | |||
38 | atomic_t reschedule_remotecontrol; | ||
39 | |||
40 | struct firesat_channel { | ||
41 | struct firesat *firesat; | ||
42 | struct dvb_demux_feed *dvbdmxfeed; | ||
43 | |||
44 | int active; | ||
45 | int id; | ||
46 | int pid; | ||
47 | int type; /* 1 - TS, 2 - Filter */ | ||
48 | } channel[16]; | ||
49 | struct semaphore demux_sem; | ||
50 | |||
51 | /* needed by avc_api */ | ||
52 | void *respfrm; | ||
53 | int resp_length; | ||
54 | |||
55 | // nodeid_t nodeid; | ||
56 | struct hpsb_host *host; | ||
57 | u64 guid; /* GUID of this node */ | ||
58 | u32 guid_vendor_id; /* Top 24bits of guid */ | ||
59 | struct node_entry *nodeentry; | ||
60 | |||
61 | enum model_type type; | ||
62 | char subunit; | ||
63 | fe_sec_voltage_t voltage; | ||
64 | fe_sec_tone_mode_t tone; | ||
65 | |||
66 | int isochannel; | ||
67 | |||
68 | struct list_head list; | ||
69 | }; | ||
70 | |||
71 | extern struct list_head firesat_list; | ||
72 | extern spinlock_t firesat_list_lock; | ||
73 | |||
74 | /* firesat_dvb.c */ | ||
75 | extern int firesat_start_feed(struct dvb_demux_feed *dvbdmxfeed); | ||
76 | extern int firesat_stop_feed(struct dvb_demux_feed *dvbdmxfeed); | ||
77 | extern int firesat_dvbdev_init(struct firesat *firesat, | ||
78 | struct device *dev, | ||
79 | struct dvb_frontend *fe); | ||
80 | |||
81 | /* firesat_fe.c */ | ||
82 | extern int firesat_frontend_attach(struct firesat *firesat, struct dvb_frontend *fe); | ||
83 | |||
84 | |||
85 | #endif | ||
diff --git a/drivers/media/dvb/firesat/firesat_1394.c b/drivers/media/dvb/firesat/firesat_1394.c new file mode 100644 index 00000000000..c7ccf633c24 --- /dev/null +++ b/drivers/media/dvb/firesat/firesat_1394.c | |||
@@ -0,0 +1,468 @@ | |||
1 | /* | ||
2 | * FireSAT DVB driver | ||
3 | * | ||
4 | * Copyright (c) 2004 Andreas Monitzer <andy@monitzer.com> | ||
5 | * Copyright (c) 2007-2008 Ben Backx <ben@bbackx.com> | ||
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 as | ||
9 | * published by the Free Software Foundation; either version 2 of | ||
10 | * the License, or (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/init.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/wait.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/time.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/semaphore.h> | ||
22 | #include <ieee1394_hotplug.h> | ||
23 | #include <nodemgr.h> | ||
24 | #include <highlevel.h> | ||
25 | #include <ohci1394.h> | ||
26 | #include <hosts.h> | ||
27 | #include <dvbdev.h> | ||
28 | |||
29 | #include "firesat.h" | ||
30 | #include "avc_api.h" | ||
31 | #include "cmp.h" | ||
32 | #include "firesat-rc.h" | ||
33 | #include "firesat-ci.h" | ||
34 | |||
35 | #define FIRESAT_Vendor_ID 0x001287 | ||
36 | |||
37 | static struct ieee1394_device_id firesat_id_table[] = { | ||
38 | |||
39 | { | ||
40 | /* FloppyDTV S/CI and FloppyDTV S2 */ | ||
41 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
42 | .model_id = 0x000024, | ||
43 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
44 | },{ | ||
45 | /* FloppyDTV T/CI */ | ||
46 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
47 | .model_id = 0x000025, | ||
48 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
49 | },{ | ||
50 | /* FloppyDTV C/CI */ | ||
51 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
52 | .model_id = 0x000026, | ||
53 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
54 | },{ | ||
55 | /* FireDTV S/CI and FloppyDTV S2 */ | ||
56 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
57 | .model_id = 0x000034, | ||
58 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
59 | },{ | ||
60 | /* FireDTV T/CI */ | ||
61 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
62 | .model_id = 0x000035, | ||
63 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
64 | },{ | ||
65 | /* FireDTV C/CI */ | ||
66 | .match_flags = IEEE1394_MATCH_MODEL_ID | IEEE1394_MATCH_SPECIFIER_ID, | ||
67 | .model_id = 0x000036, | ||
68 | .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff, | ||
69 | }, { } | ||
70 | }; | ||
71 | |||
72 | MODULE_DEVICE_TABLE(ieee1394, firesat_id_table); | ||
73 | |||
74 | /* list of all firesat devices */ | ||
75 | LIST_HEAD(firesat_list); | ||
76 | spinlock_t firesat_list_lock = SPIN_LOCK_UNLOCKED; | ||
77 | |||
78 | static void firesat_add_host(struct hpsb_host *host); | ||
79 | static void firesat_remove_host(struct hpsb_host *host); | ||
80 | static void firesat_host_reset(struct hpsb_host *host); | ||
81 | |||
82 | /* | ||
83 | static void iso_receive(struct hpsb_host *host, int channel, quadlet_t *data, | ||
84 | size_t length); | ||
85 | */ | ||
86 | |||
87 | static void fcp_request(struct hpsb_host *host, | ||
88 | int nodeid, | ||
89 | int direction, | ||
90 | int cts, | ||
91 | u8 *data, | ||
92 | size_t length); | ||
93 | |||
94 | static struct hpsb_highlevel firesat_highlevel = { | ||
95 | .name = "FireSAT", | ||
96 | .add_host = firesat_add_host, | ||
97 | .remove_host = firesat_remove_host, | ||
98 | .host_reset = firesat_host_reset, | ||
99 | // FIXME .iso_receive = iso_receive, | ||
100 | .fcp_request = fcp_request, | ||
101 | }; | ||
102 | |||
103 | static void firesat_add_host (struct hpsb_host *host) | ||
104 | { | ||
105 | struct ti_ohci *ohci = (struct ti_ohci *)host->hostdata; | ||
106 | |||
107 | /* We only work with the OHCI-1394 driver */ | ||
108 | if (strcmp(host->driver->name, OHCI1394_DRIVER_NAME)) | ||
109 | return; | ||
110 | |||
111 | if (!hpsb_create_hostinfo(&firesat_highlevel, host, 0)) { | ||
112 | printk(KERN_ERR "Cannot allocate hostinfo\n"); | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | hpsb_set_hostinfo(&firesat_highlevel, host, ohci); | ||
117 | hpsb_set_hostinfo_key(&firesat_highlevel, host, ohci->host->id); | ||
118 | } | ||
119 | |||
120 | static void firesat_remove_host (struct hpsb_host *host) | ||
121 | { | ||
122 | |||
123 | } | ||
124 | |||
125 | static void firesat_host_reset(struct hpsb_host *host) | ||
126 | { | ||
127 | printk(KERN_INFO "FireSAT host_reset (nodeid = 0x%x, hosts active = %d)\n",host->node_id,host->nodes_active); | ||
128 | } | ||
129 | |||
130 | struct firewireheader { | ||
131 | union { | ||
132 | struct { | ||
133 | unsigned char tcode:4; | ||
134 | unsigned char sy:4; | ||
135 | unsigned char tag:2; | ||
136 | unsigned char channel:6; | ||
137 | |||
138 | unsigned char length_l; | ||
139 | unsigned char length_h; | ||
140 | } hdr; | ||
141 | unsigned long val; | ||
142 | }; | ||
143 | }; | ||
144 | |||
145 | struct CIPHeader { | ||
146 | union { | ||
147 | struct { | ||
148 | unsigned char syncbits:2; | ||
149 | unsigned char sid:6; | ||
150 | unsigned char dbs; | ||
151 | unsigned char fn:2; | ||
152 | unsigned char qpc:3; | ||
153 | unsigned char sph:1; | ||
154 | unsigned char rsv:2; | ||
155 | unsigned char dbc; | ||
156 | unsigned char syncbits2:2; | ||
157 | unsigned char fmt:6; | ||
158 | unsigned long fdf:24; | ||
159 | } cip; | ||
160 | unsigned long long val; | ||
161 | }; | ||
162 | }; | ||
163 | |||
164 | struct MPEG2Header { | ||
165 | union { | ||
166 | struct { | ||
167 | unsigned char sync; // must be 0x47 | ||
168 | unsigned char transport_error_indicator:1; | ||
169 | unsigned char payload_unit_start_indicator:1; | ||
170 | unsigned char transport_priority:1; | ||
171 | unsigned short pid:13; | ||
172 | unsigned char transport_scrambling_control:2; | ||
173 | unsigned char adaption_field_control:2; | ||
174 | unsigned char continuity_counter:4; | ||
175 | } hdr; | ||
176 | unsigned long val; | ||
177 | }; | ||
178 | }; | ||
179 | |||
180 | #if 0 | ||
181 | static void iso_receive(struct hpsb_host *host, | ||
182 | int channel, | ||
183 | quadlet_t *data, | ||
184 | size_t length) | ||
185 | { | ||
186 | struct firesat *firesat = NULL; | ||
187 | struct firesat *firesat_entry; | ||
188 | unsigned long flags; | ||
189 | |||
190 | // printk(KERN_INFO "FireSAT iso_receive: channel %d, length = %d\n", channel, length); | ||
191 | |||
192 | if (length <= 12) | ||
193 | return; // ignore empty packets | ||
194 | else { | ||
195 | |||
196 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
197 | list_for_each_entry(firesat_entry,&firesat_list,list) { | ||
198 | if(firesat_entry->host == host && firesat_entry->isochannel == channel) { | ||
199 | firesat=firesat_entry; | ||
200 | break; | ||
201 | } | ||
202 | } | ||
203 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
204 | |||
205 | if (firesat) { | ||
206 | char *buf= ((char*)data) + sizeof(struct firewireheader)+sizeof(struct CIPHeader); | ||
207 | int count = (length-sizeof(struct CIPHeader)) / 192; | ||
208 | |||
209 | // printk(KERN_INFO "%s: length = %u\n data[0] = %08x\n data[1] = %08x\n data[2] = %08x\n data[3] = %08x\n data[4] = %08x\n",__func__, length, data[0],data[1],data[2],data[3],data[4]); | ||
210 | |||
211 | while (count--) { | ||
212 | |||
213 | if (buf[sizeof(quadlet_t) /*timestamp*/] == 0x47) | ||
214 | dvb_dmx_swfilter_packets(&firesat->demux, &buf[sizeof(quadlet_t)], 1); | ||
215 | else | ||
216 | printk("%s: invalid packet, skipping\n", __func__); | ||
217 | buf += 188 + sizeof (quadlet_t) /* timestamp */; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | #endif | ||
223 | |||
224 | static void fcp_request(struct hpsb_host *host, | ||
225 | int nodeid, | ||
226 | int direction, | ||
227 | int cts, | ||
228 | u8 *data, | ||
229 | size_t length) | ||
230 | { | ||
231 | struct firesat *firesat = NULL; | ||
232 | struct firesat *firesat_entry; | ||
233 | unsigned long flags; | ||
234 | |||
235 | if (length > 0 && ((data[0] & 0xf0) >> 4) == 0) { | ||
236 | |||
237 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
238 | list_for_each_entry(firesat_entry,&firesat_list,list) { | ||
239 | if (firesat_entry->host == host && | ||
240 | firesat_entry->nodeentry->nodeid == nodeid && | ||
241 | (firesat_entry->subunit == (data[1]&0x7) || | ||
242 | (firesat_entry->subunit == 0 && | ||
243 | (data[1]&0x7) == 0x7))) { | ||
244 | firesat=firesat_entry; | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
249 | |||
250 | if (firesat) | ||
251 | AVCRecv(firesat,data,length); | ||
252 | else | ||
253 | printk("%s: received fcp request from unknown source, ignored\n", __func__); | ||
254 | } // else ignore | ||
255 | } | ||
256 | |||
257 | static int firesat_probe(struct device *dev) | ||
258 | { | ||
259 | struct unit_directory *ud = container_of(dev, struct unit_directory, device); | ||
260 | struct firesat *firesat; | ||
261 | struct dvb_frontend *fe; | ||
262 | unsigned long flags; | ||
263 | int result; | ||
264 | unsigned char subunitcount = 0xff, subunit; | ||
265 | struct firesat **firesats = kmalloc(sizeof (void*) * 2,GFP_KERNEL); | ||
266 | |||
267 | if (!firesats) { | ||
268 | printk("%s: couldn't allocate memory.\n", __func__); | ||
269 | return -ENOMEM; | ||
270 | } | ||
271 | |||
272 | // printk(KERN_INFO "FireSAT: Detected device with GUID %08lx%04lx%04lx\n",(unsigned long)((ud->ne->guid)>>32),(unsigned long)(ud->ne->guid & 0xFFFF),(unsigned long)ud->ne->guid_vendor_id); | ||
273 | printk(KERN_INFO "%s: loading device\n", __func__); | ||
274 | |||
275 | firesats[0] = NULL; | ||
276 | firesats[1] = NULL; | ||
277 | |||
278 | ud->device.driver_data = firesats; | ||
279 | |||
280 | for (subunit = 0; subunit < subunitcount; subunit++) { | ||
281 | |||
282 | if (!(firesat = kmalloc(sizeof (struct firesat), GFP_KERNEL)) || | ||
283 | !(fe = kmalloc(sizeof (struct dvb_frontend), GFP_KERNEL))) { | ||
284 | |||
285 | printk("%s: couldn't allocate memory.\n", __func__); | ||
286 | kfree(firesats); | ||
287 | return -ENOMEM; | ||
288 | } | ||
289 | |||
290 | memset(firesat, 0, sizeof (struct firesat)); | ||
291 | |||
292 | firesat->host = ud->ne->host; | ||
293 | firesat->guid = ud->ne->guid; | ||
294 | firesat->guid_vendor_id = ud->ne->guid_vendor_id; | ||
295 | firesat->nodeentry = ud->ne; | ||
296 | firesat->isochannel = -1; | ||
297 | firesat->tone = 0xff; | ||
298 | firesat->voltage = 0xff; | ||
299 | |||
300 | if (!(firesat->respfrm = kmalloc(sizeof (AVCRspFrm), GFP_KERNEL))) { | ||
301 | printk("%s: couldn't allocate memory.\n", __func__); | ||
302 | kfree(firesat); | ||
303 | return -ENOMEM; | ||
304 | } | ||
305 | |||
306 | sema_init(&firesat->avc_sem, 1); | ||
307 | atomic_set(&firesat->avc_reply_received, 1); | ||
308 | sema_init(&firesat->demux_sem, 1); | ||
309 | atomic_set(&firesat->reschedule_remotecontrol, 0); | ||
310 | |||
311 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
312 | INIT_LIST_HEAD(&firesat->list); | ||
313 | list_add_tail(&firesat->list, &firesat_list); | ||
314 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
315 | |||
316 | if (subunit == 0) { | ||
317 | firesat->subunit = 0x7; // 0x7 = don't care | ||
318 | if (AVCSubUnitInfo(firesat, &subunitcount)) { | ||
319 | printk("%s: AVC subunit info command failed.\n",__func__); | ||
320 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
321 | list_del(&firesat->list); | ||
322 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
323 | kfree(firesat); | ||
324 | return -EIO; | ||
325 | } | ||
326 | } | ||
327 | |||
328 | printk(KERN_INFO "%s: subunit count = %d\n", __func__, subunitcount); | ||
329 | |||
330 | firesat->subunit = subunit; | ||
331 | |||
332 | if (AVCIdentifySubunit(firesat, NULL, (int*)&firesat->type, &firesat->has_ci)) { | ||
333 | printk("%s: cannot identify subunit %d\n", __func__, subunit); | ||
334 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
335 | list_del(&firesat->list); | ||
336 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
337 | kfree(firesat); | ||
338 | continue; | ||
339 | } | ||
340 | |||
341 | // ---- | ||
342 | firesat_dvbdev_init(firesat, dev, fe); | ||
343 | // ---- | ||
344 | firesats[subunit] = firesat; | ||
345 | } // loop for all tuners | ||
346 | |||
347 | //beta ;-) Disable remote control stuff to avoid crashing | ||
348 | //if(firesats[0]) | ||
349 | // AVCRegisterRemoteControl(firesats[0]); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | static int firesat_remove(struct device *dev) | ||
355 | { | ||
356 | struct unit_directory *ud = container_of(dev, struct unit_directory, device); | ||
357 | struct dvb_frontend* fe; | ||
358 | struct firesat **firesats = ud->device.driver_data; | ||
359 | int k; | ||
360 | unsigned long flags; | ||
361 | |||
362 | if (firesats) { | ||
363 | for (k = 0; k < 2; k++) | ||
364 | if (firesats[k]) { | ||
365 | if (firesats[k]->has_ci) | ||
366 | firesat_ca_release(firesats[k]); | ||
367 | |||
368 | #if 0 | ||
369 | if (!(fe = kmalloc(sizeof (struct dvb_frontend), GFP_KERNEL))) { | ||
370 | fe->ops = firesat_ops; | ||
371 | fe->dvb = firesats[k]->adapter; | ||
372 | |||
373 | dvb_unregister_frontend(fe); | ||
374 | kfree(fe); | ||
375 | } | ||
376 | #endif | ||
377 | dvb_net_release(&firesats[k]->dvbnet); | ||
378 | firesats[k]->demux.dmx.close(&firesats[k]->demux.dmx); | ||
379 | firesats[k]->demux.dmx.remove_frontend(&firesats[k]->demux.dmx, &firesats[k]->frontend); | ||
380 | dvb_dmxdev_release(&firesats[k]->dmxdev); | ||
381 | dvb_dmx_release(&firesats[k]->demux); | ||
382 | dvb_unregister_adapter(firesats[k]->adapter); | ||
383 | |||
384 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
385 | list_del(&firesats[k]->list); | ||
386 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
387 | |||
388 | kfree(firesats[k]->adapter); | ||
389 | kfree(firesats[k]->respfrm); | ||
390 | kfree(firesats[k]); | ||
391 | } | ||
392 | kfree(firesats); | ||
393 | } else | ||
394 | printk("%s: can't get firesat handle\n", __func__); | ||
395 | |||
396 | printk(KERN_INFO "FireSAT: Removing device with vendor id 0x%x, model id 0x%x.\n",ud->vendor_id,ud->model_id); | ||
397 | |||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | static int firesat_update(struct unit_directory *ud) | ||
402 | { | ||
403 | struct firesat **firesats = ud->device.driver_data; | ||
404 | int k; | ||
405 | // loop over subunits | ||
406 | |||
407 | for (k = 0; k < 2; k++) | ||
408 | if (firesats[k]) { | ||
409 | firesats[k]->nodeentry = ud->ne; | ||
410 | |||
411 | if (firesats[k]->isochannel >= 0) | ||
412 | try_CMPEstablishPPconnection(firesats[k], firesats[k]->subunit, firesats[k]->isochannel); | ||
413 | } | ||
414 | |||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | static struct hpsb_protocol_driver firesat_driver = { | ||
419 | |||
420 | .name = "FireSAT", | ||
421 | .id_table = firesat_id_table, | ||
422 | .update = firesat_update, | ||
423 | |||
424 | .driver = { | ||
425 | //.name and .bus are filled in for us in more recent linux versions | ||
426 | //.name = "FireSAT", | ||
427 | //.bus = &ieee1394_bus_type, | ||
428 | .probe = firesat_probe, | ||
429 | .remove = firesat_remove, | ||
430 | }, | ||
431 | }; | ||
432 | |||
433 | static int __init firesat_init(void) | ||
434 | { | ||
435 | int ret; | ||
436 | |||
437 | printk(KERN_INFO "FireSAT loaded\n"); | ||
438 | hpsb_register_highlevel(&firesat_highlevel); | ||
439 | ret = hpsb_register_protocol(&firesat_driver); | ||
440 | if (ret) { | ||
441 | printk(KERN_ERR "FireSAT: failed to register protocol\n"); | ||
442 | hpsb_unregister_highlevel(&firesat_highlevel); | ||
443 | return ret; | ||
444 | } | ||
445 | |||
446 | //Crash in this function, just disable RC for the time being... | ||
447 | //Don't forget to uncomment in firesat_exit and firesat_probe when you enable this. | ||
448 | /*if((ret=firesat_register_rc())) | ||
449 | printk("%s: firesat_register_rc return error code %d (ignored)\n", __func__, ret);*/ | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | static void __exit firesat_exit(void) | ||
455 | { | ||
456 | hpsb_unregister_protocol(&firesat_driver); | ||
457 | hpsb_unregister_highlevel(&firesat_highlevel); | ||
458 | printk(KERN_INFO "FireSAT quit\n"); | ||
459 | } | ||
460 | |||
461 | module_init(firesat_init); | ||
462 | module_exit(firesat_exit); | ||
463 | |||
464 | MODULE_AUTHOR("Andreas Monitzer <andy@monitzer.com>"); | ||
465 | MODULE_AUTHOR("Ben Backx <ben@bbackx.com>"); | ||
466 | MODULE_DESCRIPTION("FireSAT DVB Driver"); | ||
467 | MODULE_LICENSE("GPL"); | ||
468 | MODULE_SUPPORTED_DEVICE("FireSAT DVB"); | ||
diff --git a/drivers/media/dvb/firesat/firesat_dvb.c b/drivers/media/dvb/firesat/firesat_dvb.c new file mode 100644 index 00000000000..38aad081288 --- /dev/null +++ b/drivers/media/dvb/firesat/firesat_dvb.c | |||
@@ -0,0 +1,350 @@ | |||
1 | #include <linux/init.h> | ||
2 | #include <linux/slab.h> | ||
3 | #include <linux/wait.h> | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/delay.h> | ||
6 | #include <linux/time.h> | ||
7 | #include <linux/errno.h> | ||
8 | #include <linux/interrupt.h> | ||
9 | #include <linux/semaphore.h> | ||
10 | #include <ieee1394_hotplug.h> | ||
11 | #include <nodemgr.h> | ||
12 | #include <highlevel.h> | ||
13 | #include <ohci1394.h> | ||
14 | #include <hosts.h> | ||
15 | #include <dvbdev.h> | ||
16 | |||
17 | #include "firesat.h" | ||
18 | #include "avc_api.h" | ||
19 | #include "cmp.h" | ||
20 | #include "firesat-rc.h" | ||
21 | #include "firesat-ci.h" | ||
22 | |||
23 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
24 | |||
25 | static struct firesat_channel *firesat_channel_allocate(struct firesat *firesat) | ||
26 | { | ||
27 | int k; | ||
28 | |||
29 | printk(KERN_INFO "%s\n", __func__); | ||
30 | |||
31 | if (down_interruptible(&firesat->demux_sem)) | ||
32 | return NULL; | ||
33 | |||
34 | for (k = 0; k < 16; k++) { | ||
35 | printk(KERN_INFO "%s: channel %d: active = %d, pid = 0x%x\n",__func__,k,firesat->channel[k].active,firesat->channel[k].pid); | ||
36 | |||
37 | if (firesat->channel[k].active == 0) { | ||
38 | firesat->channel[k].active = 1; | ||
39 | up(&firesat->demux_sem); | ||
40 | return &firesat->channel[k]; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | up(&firesat->demux_sem); | ||
45 | return NULL; // no more channels available | ||
46 | } | ||
47 | |||
48 | static int firesat_channel_collect(struct firesat *firesat, int *pidc, u16 pid[]) | ||
49 | { | ||
50 | int k, l = 0; | ||
51 | |||
52 | if (down_interruptible(&firesat->demux_sem)) | ||
53 | return -EINTR; | ||
54 | |||
55 | for (k = 0; k < 16; k++) | ||
56 | if (firesat->channel[k].active == 1) | ||
57 | pid[l++] = firesat->channel[k].pid; | ||
58 | |||
59 | up(&firesat->demux_sem); | ||
60 | |||
61 | *pidc = l; | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static int firesat_channel_release(struct firesat *firesat, | ||
67 | struct firesat_channel *channel) | ||
68 | { | ||
69 | if (down_interruptible(&firesat->demux_sem)) | ||
70 | return -EINTR; | ||
71 | |||
72 | channel->active = 0; | ||
73 | |||
74 | up(&firesat->demux_sem); | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | int firesat_start_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
79 | { | ||
80 | struct firesat *firesat = (struct firesat*)dvbdmxfeed->demux->priv; | ||
81 | struct firesat_channel *channel; | ||
82 | int pidc,k; | ||
83 | u16 pids[16]; | ||
84 | |||
85 | printk(KERN_INFO "%s (pid %u)\n",__func__,dvbdmxfeed->pid); | ||
86 | |||
87 | switch (dvbdmxfeed->type) { | ||
88 | case DMX_TYPE_TS: | ||
89 | case DMX_TYPE_SEC: | ||
90 | break; | ||
91 | default: | ||
92 | printk("%s: invalid type %u\n",__func__,dvbdmxfeed->type); | ||
93 | return -EINVAL; | ||
94 | } | ||
95 | |||
96 | if (dvbdmxfeed->type == DMX_TYPE_TS) { | ||
97 | switch (dvbdmxfeed->pes_type) { | ||
98 | case DMX_TS_PES_VIDEO: | ||
99 | case DMX_TS_PES_AUDIO: | ||
100 | case DMX_TS_PES_TELETEXT: | ||
101 | case DMX_TS_PES_PCR: | ||
102 | case DMX_TS_PES_OTHER: | ||
103 | //Dirty fix to keep firesat->channel pid-list up to date | ||
104 | for(k=0;k<16;k++){ | ||
105 | if(firesat->channel[k].active == 0) | ||
106 | firesat->channel[k].pid = | ||
107 | dvbdmxfeed->pid; | ||
108 | break; | ||
109 | } | ||
110 | channel = firesat_channel_allocate(firesat); | ||
111 | break; | ||
112 | default: | ||
113 | printk("%s: invalid pes type %u\n",__func__, dvbdmxfeed->pes_type); | ||
114 | return -EINVAL; | ||
115 | } | ||
116 | } else { | ||
117 | channel = firesat_channel_allocate(firesat); | ||
118 | } | ||
119 | |||
120 | if (!channel) { | ||
121 | printk("%s: busy!\n", __func__); | ||
122 | return -EBUSY; | ||
123 | } | ||
124 | |||
125 | dvbdmxfeed->priv = channel; | ||
126 | |||
127 | channel->dvbdmxfeed = dvbdmxfeed; | ||
128 | channel->pid = dvbdmxfeed->pid; | ||
129 | channel->type = dvbdmxfeed->type; | ||
130 | channel->firesat = firesat; | ||
131 | |||
132 | if (firesat_channel_collect(firesat, &pidc, pids)) { | ||
133 | firesat_channel_release(firesat, channel); | ||
134 | return -EINTR; | ||
135 | } | ||
136 | |||
137 | if(dvbdmxfeed->pid == 8192) { | ||
138 | if((k=AVCTuner_GetTS(firesat))) { | ||
139 | firesat_channel_release(firesat, channel); | ||
140 | printk("%s: AVCTuner_GetTS failed with error %d\n", | ||
141 | __func__,k); | ||
142 | return k; | ||
143 | } | ||
144 | } | ||
145 | else { | ||
146 | if((k=AVCTuner_SetPIDs(firesat, pidc, pids))) { | ||
147 | firesat_channel_release(firesat, channel); | ||
148 | printk("%s: AVCTuner_SetPIDs failed with error %d\n", | ||
149 | __func__,k); | ||
150 | return k; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | int firesat_stop_feed(struct dvb_demux_feed *dvbdmxfeed) | ||
158 | { | ||
159 | struct dvb_demux *demux = dvbdmxfeed->demux; | ||
160 | struct firesat *firesat = (struct firesat*)demux->priv; | ||
161 | int k, l = 0; | ||
162 | u16 pids[16]; | ||
163 | |||
164 | printk(KERN_INFO "%s (pid %u)\n", __func__, dvbdmxfeed->pid); | ||
165 | |||
166 | if (dvbdmxfeed->type == DMX_TYPE_TS && !((dvbdmxfeed->ts_type & TS_PACKET) && | ||
167 | (demux->dmx.frontend->source != DMX_MEMORY_FE))) { | ||
168 | |||
169 | if (dvbdmxfeed->ts_type & TS_DECODER) { | ||
170 | |||
171 | if (dvbdmxfeed->pes_type >= DMX_TS_PES_OTHER || | ||
172 | !demux->pesfilter[dvbdmxfeed->pes_type]) | ||
173 | |||
174 | return -EINVAL; | ||
175 | |||
176 | demux->pids[dvbdmxfeed->pes_type] |= 0x8000; | ||
177 | demux->pesfilter[dvbdmxfeed->pes_type] = 0; | ||
178 | } | ||
179 | |||
180 | if (!(dvbdmxfeed->ts_type & TS_DECODER && | ||
181 | dvbdmxfeed->pes_type < DMX_TS_PES_OTHER)) | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | if (down_interruptible(&firesat->demux_sem)) | ||
187 | return -EINTR; | ||
188 | |||
189 | |||
190 | // list except channel to be removed | ||
191 | for (k = 0; k < 16; k++) | ||
192 | if (firesat->channel[k].active == 1) | ||
193 | if (&firesat->channel[k] != | ||
194 | (struct firesat_channel *)dvbdmxfeed->priv) | ||
195 | pids[l++] = firesat->channel[k].pid; | ||
196 | else | ||
197 | firesat->channel[k].active = 0; | ||
198 | |||
199 | if ((k = AVCTuner_SetPIDs(firesat, l, pids))) { | ||
200 | up(&firesat->demux_sem); | ||
201 | return k; | ||
202 | } | ||
203 | |||
204 | ((struct firesat_channel *)dvbdmxfeed->priv)->active = 0; | ||
205 | |||
206 | up(&firesat->demux_sem); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | int firesat_dvbdev_init(struct firesat *firesat, | ||
212 | struct device *dev, | ||
213 | struct dvb_frontend *fe) | ||
214 | { | ||
215 | int result; | ||
216 | |||
217 | firesat->has_ci = 1; // TEMP workaround | ||
218 | |||
219 | #if 0 | ||
220 | switch (firesat->type) { | ||
221 | case FireSAT_DVB_S: | ||
222 | firesat->model_name = "FireSAT DVB-S"; | ||
223 | firesat->frontend_info = &firesat_S_frontend_info; | ||
224 | break; | ||
225 | case FireSAT_DVB_C: | ||
226 | firesat->model_name = "FireSAT DVB-C"; | ||
227 | firesat->frontend_info = &firesat_C_frontend_info; | ||
228 | break; | ||
229 | case FireSAT_DVB_T: | ||
230 | firesat->model_name = "FireSAT DVB-T"; | ||
231 | firesat->frontend_info = &firesat_T_frontend_info; | ||
232 | break; | ||
233 | default: | ||
234 | printk("%s: unknown model type 0x%x on subunit %d!\n", | ||
235 | __func__, firesat->type,subunit); | ||
236 | firesat->model_name = "Unknown"; | ||
237 | firesat->frontend_info = NULL; | ||
238 | } | ||
239 | #endif | ||
240 | /* // ------- CRAP ----------- | ||
241 | if (!firesat->frontend_info) { | ||
242 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
243 | list_del(&firesat->list); | ||
244 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
245 | kfree(firesat); | ||
246 | continue; | ||
247 | } | ||
248 | */ | ||
249 | //initialising firesat->adapter before calling dvb_register_adapter | ||
250 | if (!(firesat->adapter = kmalloc(sizeof (struct dvb_adapter), GFP_KERNEL))) { | ||
251 | printk("%s: couldn't allocate memory.\n", __func__); | ||
252 | kfree(firesat->adapter); | ||
253 | kfree(firesat); | ||
254 | return -ENOMEM; | ||
255 | } | ||
256 | |||
257 | if ((result = dvb_register_adapter(firesat->adapter, | ||
258 | firesat->model_name, | ||
259 | THIS_MODULE, | ||
260 | dev, adapter_nr)) < 0) { | ||
261 | |||
262 | printk("%s: dvb_register_adapter failed: error %d\n", __func__, result); | ||
263 | #if 0 | ||
264 | /* ### cleanup */ | ||
265 | spin_lock_irqsave(&firesat_list_lock, flags); | ||
266 | list_del(&firesat->list); | ||
267 | spin_unlock_irqrestore(&firesat_list_lock, flags); | ||
268 | #endif | ||
269 | kfree(firesat); | ||
270 | |||
271 | return result; | ||
272 | } | ||
273 | |||
274 | firesat->demux.dmx.capabilities = 0/*DMX_TS_FILTERING | DMX_SECTION_FILTERING*/; | ||
275 | |||
276 | firesat->demux.priv = (void *)firesat; | ||
277 | firesat->demux.filternum = 16; | ||
278 | firesat->demux.feednum = 16; | ||
279 | firesat->demux.start_feed = firesat_start_feed; | ||
280 | firesat->demux.stop_feed = firesat_stop_feed; | ||
281 | firesat->demux.write_to_decoder = NULL; | ||
282 | |||
283 | if ((result = dvb_dmx_init(&firesat->demux)) < 0) { | ||
284 | printk("%s: dvb_dmx_init failed: error %d\n", __func__, | ||
285 | result); | ||
286 | |||
287 | dvb_unregister_adapter(firesat->adapter); | ||
288 | |||
289 | return result; | ||
290 | } | ||
291 | |||
292 | firesat->dmxdev.filternum = 16; | ||
293 | firesat->dmxdev.demux = &firesat->demux.dmx; | ||
294 | firesat->dmxdev.capabilities = 0; | ||
295 | |||
296 | if ((result = dvb_dmxdev_init(&firesat->dmxdev, firesat->adapter)) < 0) { | ||
297 | printk("%s: dvb_dmxdev_init failed: error %d\n", | ||
298 | __func__, result); | ||
299 | |||
300 | dvb_dmx_release(&firesat->demux); | ||
301 | dvb_unregister_adapter(firesat->adapter); | ||
302 | |||
303 | return result; | ||
304 | } | ||
305 | |||
306 | firesat->frontend.source = DMX_FRONTEND_0; | ||
307 | |||
308 | if ((result = firesat->demux.dmx.add_frontend(&firesat->demux.dmx, | ||
309 | &firesat->frontend)) < 0) { | ||
310 | printk("%s: dvb_dmx_init failed: error %d\n", __func__, | ||
311 | result); | ||
312 | |||
313 | dvb_dmxdev_release(&firesat->dmxdev); | ||
314 | dvb_dmx_release(&firesat->demux); | ||
315 | dvb_unregister_adapter(firesat->adapter); | ||
316 | |||
317 | return result; | ||
318 | } | ||
319 | |||
320 | if ((result = firesat->demux.dmx.connect_frontend(&firesat->demux.dmx, | ||
321 | &firesat->frontend)) < 0) { | ||
322 | printk("%s: dvb_dmx_init failed: error %d\n", __func__, | ||
323 | result); | ||
324 | |||
325 | firesat->demux.dmx.remove_frontend(&firesat->demux.dmx, &firesat->frontend); | ||
326 | dvb_dmxdev_release(&firesat->dmxdev); | ||
327 | dvb_dmx_release(&firesat->demux); | ||
328 | dvb_unregister_adapter(firesat->adapter); | ||
329 | |||
330 | return result; | ||
331 | } | ||
332 | |||
333 | dvb_net_init(firesat->adapter, &firesat->dvbnet, &firesat->demux.dmx); | ||
334 | |||
335 | // fe->ops = firesat_ops; | ||
336 | // fe->dvb = firesat->adapter; | ||
337 | firesat_frontend_attach(firesat, fe); | ||
338 | |||
339 | fe->sec_priv = firesat; //IMPORTANT, functions depend on this!!! | ||
340 | if ((result= dvb_register_frontend(firesat->adapter, fe)) < 0) { | ||
341 | printk("%s: dvb_register_frontend_new failed: error %d\n", __func__, result); | ||
342 | /* ### cleanup */ | ||
343 | return result; | ||
344 | } | ||
345 | |||
346 | if (firesat->has_ci) | ||
347 | firesat_ca_init(firesat); | ||
348 | |||
349 | return 0; | ||
350 | } | ||
diff --git a/drivers/media/dvb/firesat/firesat_fe.c b/drivers/media/dvb/firesat/firesat_fe.c new file mode 100644 index 00000000000..f7abd38f001 --- /dev/null +++ b/drivers/media/dvb/firesat/firesat_fe.c | |||
@@ -0,0 +1,263 @@ | |||
1 | #include <linux/init.h> | ||
2 | #include <linux/slab.h> | ||
3 | #include <linux/wait.h> | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/delay.h> | ||
6 | #include <linux/time.h> | ||
7 | #include <linux/errno.h> | ||
8 | #include <linux/interrupt.h> | ||
9 | #include <linux/semaphore.h> | ||
10 | #include <ieee1394_hotplug.h> | ||
11 | #include <nodemgr.h> | ||
12 | #include <highlevel.h> | ||
13 | #include <ohci1394.h> | ||
14 | #include <hosts.h> | ||
15 | #include <dvbdev.h> | ||
16 | |||
17 | #include "firesat.h" | ||
18 | #include "avc_api.h" | ||
19 | #include "cmp.h" | ||
20 | #include "firesat-rc.h" | ||
21 | #include "firesat-ci.h" | ||
22 | |||
23 | static int firesat_dvb_init(struct dvb_frontend *fe) | ||
24 | { | ||
25 | struct firesat *firesat = fe->sec_priv; | ||
26 | printk("fdi: 1\n"); | ||
27 | firesat->isochannel = firesat->adapter->num; //<< 1 | (firesat->subunit & 0x1); // ### ask IRM | ||
28 | printk("fdi: 2\n"); | ||
29 | try_CMPEstablishPPconnection(firesat, firesat->subunit, firesat->isochannel); | ||
30 | printk("fdi: 3\n"); | ||
31 | //FIXME hpsb_listen_channel(&firesat_highlevel, firesat->host, firesat->isochannel); | ||
32 | printk("fdi: 4\n"); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static int firesat_sleep(struct dvb_frontend *fe) | ||
37 | { | ||
38 | struct firesat *firesat = fe->sec_priv; | ||
39 | |||
40 | //FIXME hpsb_unlisten_channel(&firesat_highlevel, firesat->host, firesat->isochannel); | ||
41 | try_CMPBreakPPconnection(firesat, firesat->subunit, firesat->isochannel); | ||
42 | firesat->isochannel = -1; | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static int firesat_diseqc_send_master_cmd(struct dvb_frontend *fe, | ||
47 | struct dvb_diseqc_master_cmd *cmd) | ||
48 | { | ||
49 | struct firesat *firesat = fe->sec_priv; | ||
50 | |||
51 | return AVCLNBControl(firesat, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE, | ||
52 | LNBCONTROL_DONTCARE, 1, cmd); | ||
53 | } | ||
54 | |||
55 | static int firesat_diseqc_send_burst(struct dvb_frontend *fe, | ||
56 | fe_sec_mini_cmd_t minicmd) | ||
57 | { | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | static int firesat_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) | ||
62 | { | ||
63 | struct firesat *firesat = fe->sec_priv; | ||
64 | |||
65 | firesat->tone = tone; | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static int firesat_set_voltage(struct dvb_frontend *fe, | ||
70 | fe_sec_voltage_t voltage) | ||
71 | { | ||
72 | struct firesat *firesat = fe->sec_priv; | ||
73 | |||
74 | firesat->voltage = voltage; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int firesat_read_status (struct dvb_frontend *fe, fe_status_t *status) | ||
79 | { | ||
80 | struct firesat *firesat = fe->sec_priv; | ||
81 | ANTENNA_INPUT_INFO info; | ||
82 | |||
83 | if (AVCTunerStatus(firesat, &info)) | ||
84 | return -EINVAL; | ||
85 | |||
86 | if (info.NoRF) | ||
87 | *status = 0; | ||
88 | else | ||
89 | *status = *status = FE_HAS_SIGNAL | | ||
90 | FE_HAS_VITERBI | | ||
91 | FE_HAS_SYNC | | ||
92 | FE_HAS_CARRIER | | ||
93 | FE_HAS_LOCK; | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static int firesat_read_ber (struct dvb_frontend *fe, u32 *ber) | ||
99 | { | ||
100 | struct firesat *firesat = fe->sec_priv; | ||
101 | ANTENNA_INPUT_INFO info; | ||
102 | |||
103 | if (AVCTunerStatus(firesat, &info)) | ||
104 | return -EINVAL; | ||
105 | |||
106 | *ber = ((info.BER[0] << 24) & 0xff) | | ||
107 | ((info.BER[1] << 16) & 0xff) | | ||
108 | ((info.BER[2] << 8) & 0xff) | | ||
109 | (info.BER[3] & 0xff); | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static int firesat_read_signal_strength (struct dvb_frontend *fe, u16 *strength) | ||
115 | { | ||
116 | struct firesat *firesat = fe->sec_priv; | ||
117 | ANTENNA_INPUT_INFO info; | ||
118 | u16 *signal = strength; | ||
119 | |||
120 | if (AVCTunerStatus(firesat, &info)) | ||
121 | return -EINVAL; | ||
122 | |||
123 | *signal = info.SignalStrength; | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static int firesat_read_snr(struct dvb_frontend *fe, u16 *snr) | ||
129 | { | ||
130 | return -EOPNOTSUPP; | ||
131 | } | ||
132 | |||
133 | static int firesat_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks) | ||
134 | { | ||
135 | return -EOPNOTSUPP; | ||
136 | } | ||
137 | |||
138 | static int firesat_set_frontend(struct dvb_frontend *fe, | ||
139 | struct dvb_frontend_parameters *params) | ||
140 | { | ||
141 | struct firesat *firesat = fe->sec_priv; | ||
142 | |||
143 | if (AVCTuner_DSD(firesat, params, NULL) != ACCEPTED) | ||
144 | return -EINVAL; | ||
145 | else | ||
146 | return 0; //not sure of this... | ||
147 | } | ||
148 | |||
149 | static int firesat_get_frontend(struct dvb_frontend *fe, | ||
150 | struct dvb_frontend_parameters *params) | ||
151 | { | ||
152 | return -EOPNOTSUPP; | ||
153 | } | ||
154 | |||
155 | static struct dvb_frontend_info firesat_S_frontend_info; | ||
156 | static struct dvb_frontend_info firesat_C_frontend_info; | ||
157 | static struct dvb_frontend_info firesat_T_frontend_info; | ||
158 | |||
159 | static struct dvb_frontend_ops firesat_ops = { | ||
160 | |||
161 | .init = firesat_dvb_init, | ||
162 | .sleep = firesat_sleep, | ||
163 | |||
164 | .set_frontend = firesat_set_frontend, | ||
165 | .get_frontend = firesat_get_frontend, | ||
166 | |||
167 | .read_status = firesat_read_status, | ||
168 | .read_ber = firesat_read_ber, | ||
169 | .read_signal_strength = firesat_read_signal_strength, | ||
170 | .read_snr = firesat_read_snr, | ||
171 | .read_ucblocks = firesat_read_uncorrected_blocks, | ||
172 | |||
173 | .diseqc_send_master_cmd = firesat_diseqc_send_master_cmd, | ||
174 | .diseqc_send_burst = firesat_diseqc_send_burst, | ||
175 | .set_tone = firesat_set_tone, | ||
176 | .set_voltage = firesat_set_voltage, | ||
177 | }; | ||
178 | |||
179 | int firesat_frontend_attach(struct firesat *firesat, struct dvb_frontend *fe) | ||
180 | { | ||
181 | switch (firesat->type) { | ||
182 | case FireSAT_DVB_S: | ||
183 | firesat->model_name = "FireSAT DVB-S"; | ||
184 | firesat->frontend_info = &firesat_S_frontend_info; | ||
185 | break; | ||
186 | case FireSAT_DVB_C: | ||
187 | firesat->model_name = "FireSAT DVB-C"; | ||
188 | firesat->frontend_info = &firesat_C_frontend_info; | ||
189 | break; | ||
190 | case FireSAT_DVB_T: | ||
191 | firesat->model_name = "FireSAT DVB-T"; | ||
192 | firesat->frontend_info = &firesat_T_frontend_info; | ||
193 | break; | ||
194 | default: | ||
195 | // printk("%s: unknown model type 0x%x on subunit %d!\n", | ||
196 | // __func__, firesat->type,subunit); | ||
197 | printk("%s: unknown model type 0x%x !\n", | ||
198 | __func__, firesat->type); | ||
199 | firesat->model_name = "Unknown"; | ||
200 | firesat->frontend_info = NULL; | ||
201 | } | ||
202 | fe->ops = firesat_ops; | ||
203 | fe->dvb = firesat->adapter; | ||
204 | |||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static struct dvb_frontend_info firesat_S_frontend_info = { | ||
209 | |||
210 | .name = "FireSAT DVB-S Frontend", | ||
211 | .type = FE_QPSK, | ||
212 | |||
213 | .frequency_min = 950000, | ||
214 | .frequency_max = 2150000, | ||
215 | .frequency_stepsize = 125, | ||
216 | .symbol_rate_min = 1000000, | ||
217 | .symbol_rate_max = 40000000, | ||
218 | |||
219 | .caps = FE_CAN_INVERSION_AUTO | | ||
220 | FE_CAN_FEC_1_2 | | ||
221 | FE_CAN_FEC_2_3 | | ||
222 | FE_CAN_FEC_3_4 | | ||
223 | FE_CAN_FEC_5_6 | | ||
224 | FE_CAN_FEC_7_8 | | ||
225 | FE_CAN_FEC_AUTO | | ||
226 | FE_CAN_QPSK, | ||
227 | }; | ||
228 | |||
229 | static struct dvb_frontend_info firesat_C_frontend_info = { | ||
230 | |||
231 | .name = "FireSAT DVB-C Frontend", | ||
232 | .type = FE_QAM, | ||
233 | |||
234 | .frequency_min = 47000000, | ||
235 | .frequency_max = 866000000, | ||
236 | .frequency_stepsize = 62500, | ||
237 | .symbol_rate_min = 870000, | ||
238 | .symbol_rate_max = 6900000, | ||
239 | |||
240 | .caps = FE_CAN_INVERSION_AUTO | | ||
241 | FE_CAN_QAM_16 | | ||
242 | FE_CAN_QAM_32 | | ||
243 | FE_CAN_QAM_64 | | ||
244 | FE_CAN_QAM_128 | | ||
245 | FE_CAN_QAM_256 | | ||
246 | FE_CAN_QAM_AUTO, | ||
247 | }; | ||
248 | |||
249 | static struct dvb_frontend_info firesat_T_frontend_info = { | ||
250 | |||
251 | .name = "FireSAT DVB-T Frontend", | ||
252 | .type = FE_OFDM, | ||
253 | |||
254 | .frequency_min = 49000000, | ||
255 | .frequency_max = 861000000, | ||
256 | .frequency_stepsize = 62500, | ||
257 | |||
258 | .caps = FE_CAN_INVERSION_AUTO | | ||
259 | FE_CAN_FEC_2_3 | | ||
260 | FE_CAN_TRANSMISSION_MODE_AUTO | | ||
261 | FE_CAN_GUARD_INTERVAL_AUTO | | ||
262 | FE_CAN_HIERARCHY_AUTO, | ||
263 | }; | ||