diff options
author | Ralph Metzler <rjkm@metzlerbros.de> | 2011-01-10 04:36:15 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-21 19:31:45 -0400 |
commit | 0f0b270f905bbb0c8e75988ceaf10ff9a401e712 (patch) | |
tree | 03fd199d1cc923a1182b51f6b737cadbd2f4f5fb | |
parent | 8a484719c790772bc51c87c56323611752361bef (diff) |
[media] ngene: CXD2099AR Common Interface driver
Driver for the Common Interface Controller CXD2099AR.
Supports the CI of the cineS2 DVB-S2.
For now, data is passed through '/dev/dvb/adapterX/sec0':
- Encrypted data must be written to 'sec0'.
- Decrypted data can be read from 'sec0'.
- Setup the CAM using device 'ca0'.
Signed-off-by: Ralph Metzler <rjkm@metzlerbros.de>
Signed-off-by: Oliver Endriss <o.endriss@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/dvb/ngene/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/cxd2099.c | 574 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/cxd2099.h | 32 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/ngene-cards.c | 6 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/ngene-core.c | 110 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/ngene-dvb.c | 70 | ||||
-rw-r--r-- | drivers/media/dvb/ngene/ngene.h | 19 |
7 files changed, 782 insertions, 31 deletions
diff --git a/drivers/media/dvb/ngene/Makefile b/drivers/media/dvb/ngene/Makefile index 0608aabb14ee..00d12d6c4618 100644 --- a/drivers/media/dvb/ngene/Makefile +++ b/drivers/media/dvb/ngene/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for the nGene device driver | 2 | # Makefile for the nGene device driver |
3 | # | 3 | # |
4 | 4 | ||
5 | ngene-objs := ngene-core.o ngene-i2c.o ngene-cards.o ngene-dvb.o | 5 | ngene-objs := ngene-core.o ngene-i2c.o ngene-cards.o ngene-dvb.o cxd2099.o |
6 | 6 | ||
7 | obj-$(CONFIG_DVB_NGENE) += ngene.o | 7 | obj-$(CONFIG_DVB_NGENE) += ngene.o |
8 | 8 | ||
diff --git a/drivers/media/dvb/ngene/cxd2099.c b/drivers/media/dvb/ngene/cxd2099.c new file mode 100644 index 000000000000..b49186c74eb3 --- /dev/null +++ b/drivers/media/dvb/ngene/cxd2099.c | |||
@@ -0,0 +1,574 @@ | |||
1 | /* | ||
2 | * cxd2099.c: Driver for the CXD2099AR Common Interface Controller | ||
3 | * | ||
4 | * Copyright (C) 2010 DigitalDevices UG | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 only, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
21 | * 02110-1301, USA | ||
22 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | ||
23 | */ | ||
24 | |||
25 | #include <linux/version.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/moduleparam.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/i2c.h> | ||
32 | #include <linux/wait.h> | ||
33 | #include <linux/delay.h> | ||
34 | #include <linux/mutex.h> | ||
35 | #include <linux/io.h> | ||
36 | |||
37 | #include "cxd2099.h" | ||
38 | |||
39 | #define MAX_BUFFER_SIZE 248 | ||
40 | |||
41 | struct cxd { | ||
42 | struct dvb_ca_en50221 en; | ||
43 | |||
44 | struct i2c_adapter *i2c; | ||
45 | u8 adr; | ||
46 | u8 regs[0x23]; | ||
47 | u8 lastaddress; | ||
48 | u8 clk_reg_f; | ||
49 | u8 clk_reg_b; | ||
50 | int mode; | ||
51 | u32 bitrate; | ||
52 | int ready; | ||
53 | int dr; | ||
54 | int slot_stat; | ||
55 | |||
56 | u8 amem[1024]; | ||
57 | int amem_read; | ||
58 | |||
59 | int cammode; | ||
60 | struct mutex lock; | ||
61 | }; | ||
62 | |||
63 | static int i2c_write_reg(struct i2c_adapter *adapter, u8 adr, | ||
64 | u8 reg, u8 data) | ||
65 | { | ||
66 | u8 m[2] = {reg, data}; | ||
67 | struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m, .len = 2}; | ||
68 | |||
69 | if (i2c_transfer(adapter, &msg, 1) != 1) { | ||
70 | printk(KERN_ERR "Failed to write to I2C register %02x@%02x!\n", | ||
71 | reg, adr); | ||
72 | return -1; | ||
73 | } | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static int i2c_write(struct i2c_adapter *adapter, u8 adr, | ||
78 | u8 *data, u8 len) | ||
79 | { | ||
80 | struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = data, .len = len}; | ||
81 | |||
82 | if (i2c_transfer(adapter, &msg, 1) != 1) { | ||
83 | printk(KERN_ERR "Failed to write to I2C!\n"); | ||
84 | return -1; | ||
85 | } | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr, | ||
90 | u8 reg, u8 *val) | ||
91 | { | ||
92 | struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0, | ||
93 | .buf = ®, .len = 1 }, | ||
94 | {.addr = adr, .flags = I2C_M_RD, | ||
95 | .buf = val, .len = 1 } }; | ||
96 | |||
97 | if (i2c_transfer(adapter, msgs, 2) != 2) { | ||
98 | printk(KERN_ERR "error in i2c_read_reg\n"); | ||
99 | return -1; | ||
100 | } | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static int i2c_read(struct i2c_adapter *adapter, u8 adr, | ||
105 | u8 reg, u8 *data, u8 n) | ||
106 | { | ||
107 | struct i2c_msg msgs[2] = {{.addr = adr, .flags = 0, | ||
108 | .buf = ®, .len = 1 }, | ||
109 | {.addr = adr, .flags = I2C_M_RD, | ||
110 | .buf = data, .len = n } }; | ||
111 | |||
112 | if (i2c_transfer(adapter, msgs, 2) != 2) { | ||
113 | printk(KERN_ERR "error in i2c_read\n"); | ||
114 | return -1; | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static int read_block(struct cxd *ci, u8 adr, u8 *data, u8 n) | ||
120 | { | ||
121 | int status; | ||
122 | |||
123 | status = i2c_write_reg(ci->i2c, ci->adr, 0, adr); | ||
124 | if (!status) { | ||
125 | ci->lastaddress = adr; | ||
126 | status = i2c_read(ci->i2c, ci->adr, 1, data, n); | ||
127 | } | ||
128 | return status; | ||
129 | } | ||
130 | |||
131 | static int read_reg(struct cxd *ci, u8 reg, u8 *val) | ||
132 | { | ||
133 | return read_block(ci, reg, val, 1); | ||
134 | } | ||
135 | |||
136 | |||
137 | static int read_pccard(struct cxd *ci, u16 address, u8 *data, u8 n) | ||
138 | { | ||
139 | int status; | ||
140 | u8 addr[3] = { 2, address&0xff, address>>8 }; | ||
141 | |||
142 | status = i2c_write(ci->i2c, ci->adr, addr, 3); | ||
143 | if (!status) | ||
144 | status = i2c_read(ci->i2c, ci->adr, 3, data, n); | ||
145 | return status; | ||
146 | } | ||
147 | |||
148 | static int write_pccard(struct cxd *ci, u16 address, u8 *data, u8 n) | ||
149 | { | ||
150 | int status; | ||
151 | u8 addr[3] = { 2, address&0xff, address>>8 }; | ||
152 | |||
153 | status = i2c_write(ci->i2c, ci->adr, addr, 3); | ||
154 | if (!status) { | ||
155 | u8 buf[256] = {3}; | ||
156 | memcpy(buf+1, data, n); | ||
157 | status = i2c_write(ci->i2c, ci->adr, buf, n+1); | ||
158 | } | ||
159 | return status; | ||
160 | } | ||
161 | |||
162 | static int read_io(struct cxd *ci, u16 address, u8 *val) | ||
163 | { | ||
164 | int status; | ||
165 | u8 addr[3] = { 2, address&0xff, address>>8 }; | ||
166 | |||
167 | status = i2c_write(ci->i2c, ci->adr, addr, 3); | ||
168 | if (!status) | ||
169 | status = i2c_read(ci->i2c, ci->adr, 3, val, 1); | ||
170 | return status; | ||
171 | } | ||
172 | |||
173 | static int write_io(struct cxd *ci, u16 address, u8 val) | ||
174 | { | ||
175 | int status; | ||
176 | u8 addr[3] = { 2, address&0xff, address>>8 }; | ||
177 | u8 buf[2] = { 3, val }; | ||
178 | |||
179 | status = i2c_write(ci->i2c, ci->adr, addr, 3); | ||
180 | if (!status) | ||
181 | status = i2c_write(ci->i2c, ci->adr, buf, 2); | ||
182 | |||
183 | return status; | ||
184 | } | ||
185 | |||
186 | |||
187 | static int write_regm(struct cxd *ci, u8 reg, u8 val, u8 mask) | ||
188 | { | ||
189 | int status; | ||
190 | |||
191 | status = i2c_write_reg(ci->i2c, ci->adr, 0, reg); | ||
192 | if (!status && reg >= 6 && reg <= 8 && mask != 0xff) | ||
193 | status = i2c_read_reg(ci->i2c, ci->adr, 1, &ci->regs[reg]); | ||
194 | ci->regs[reg] = (ci->regs[reg]&(~mask))|val; | ||
195 | if (!status) { | ||
196 | ci->lastaddress = reg; | ||
197 | status = i2c_write_reg(ci->i2c, ci->adr, 1, ci->regs[reg]); | ||
198 | } | ||
199 | if (reg == 0x20) | ||
200 | ci->regs[reg] &= 0x7f; | ||
201 | return status; | ||
202 | } | ||
203 | |||
204 | static int write_reg(struct cxd *ci, u8 reg, u8 val) | ||
205 | { | ||
206 | return write_regm(ci, reg, val, 0xff); | ||
207 | } | ||
208 | |||
209 | #ifdef BUFFER_MODE | ||
210 | static int write_block(struct cxd *ci, u8 adr, u8 *data, int n) | ||
211 | { | ||
212 | int status; | ||
213 | u8 buf[256] = {1}; | ||
214 | |||
215 | status = i2c_write_reg(ci->i2c, ci->adr, 0, adr); | ||
216 | if (!status) { | ||
217 | ci->lastaddress = adr; | ||
218 | memcpy(buf+1, data, n); | ||
219 | status = i2c_write(ci->i2c, ci->adr, buf, n+1); | ||
220 | } | ||
221 | return status; | ||
222 | } | ||
223 | #endif | ||
224 | |||
225 | static void set_mode(struct cxd *ci, int mode) | ||
226 | { | ||
227 | if (mode == ci->mode) | ||
228 | return; | ||
229 | |||
230 | switch (mode) { | ||
231 | case 0x00: /* IO mem */ | ||
232 | write_regm(ci, 0x06, 0x00, 0x07); | ||
233 | break; | ||
234 | case 0x01: /* ATT mem */ | ||
235 | write_regm(ci, 0x06, 0x02, 0x07); | ||
236 | break; | ||
237 | default: | ||
238 | break; | ||
239 | } | ||
240 | ci->mode = mode; | ||
241 | } | ||
242 | |||
243 | static void cam_mode(struct cxd *ci, int mode) | ||
244 | { | ||
245 | if (mode == ci->cammode) | ||
246 | return; | ||
247 | |||
248 | switch (mode) { | ||
249 | case 0x00: | ||
250 | write_regm(ci, 0x20, 0x80, 0x80); | ||
251 | break; | ||
252 | case 0x01: | ||
253 | printk(KERN_INFO "enable cam buffer mode\n"); | ||
254 | /* write_reg(ci, 0x0d, 0x00); */ | ||
255 | /* write_reg(ci, 0x0e, 0x01); */ | ||
256 | write_regm(ci, 0x08, 0x40, 0x40); | ||
257 | /* read_reg(ci, 0x12, &dummy); */ | ||
258 | write_regm(ci, 0x08, 0x80, 0x80); | ||
259 | break; | ||
260 | default: | ||
261 | break; | ||
262 | } | ||
263 | ci->cammode = mode; | ||
264 | } | ||
265 | |||
266 | |||
267 | |||
268 | #define CHK_ERROR(s) if ((status = s)) break | ||
269 | |||
270 | static int init(struct cxd *ci) | ||
271 | { | ||
272 | int status; | ||
273 | |||
274 | mutex_lock(&ci->lock); | ||
275 | ci->mode = -1; | ||
276 | do { | ||
277 | CHK_ERROR(write_reg(ci, 0x00, 0x00)); | ||
278 | CHK_ERROR(write_reg(ci, 0x01, 0x00)); | ||
279 | CHK_ERROR(write_reg(ci, 0x02, 0x10)); | ||
280 | CHK_ERROR(write_reg(ci, 0x03, 0x00)); | ||
281 | CHK_ERROR(write_reg(ci, 0x05, 0xFF)); | ||
282 | CHK_ERROR(write_reg(ci, 0x06, 0x1F)); | ||
283 | CHK_ERROR(write_reg(ci, 0x07, 0x1F)); | ||
284 | CHK_ERROR(write_reg(ci, 0x08, 0x28)); | ||
285 | CHK_ERROR(write_reg(ci, 0x14, 0x20)); | ||
286 | |||
287 | CHK_ERROR(write_reg(ci, 0x09, 0x4D)); /* Input Mode C, BYPass Serial, TIVAL = low, MSB */ | ||
288 | CHK_ERROR(write_reg(ci, 0x0A, 0xA7)); /* TOSTRT = 8, Mode B (gated clock), falling Edge, Serial, POL=HIGH, MSB */ | ||
289 | |||
290 | /* Sync detector */ | ||
291 | CHK_ERROR(write_reg(ci, 0x0B, 0x33)); | ||
292 | CHK_ERROR(write_reg(ci, 0x0C, 0x33)); | ||
293 | |||
294 | CHK_ERROR(write_regm(ci, 0x14, 0x00, 0x0F)); | ||
295 | CHK_ERROR(write_reg(ci, 0x15, ci->clk_reg_b)); | ||
296 | CHK_ERROR(write_regm(ci, 0x16, 0x00, 0x0F)); | ||
297 | CHK_ERROR(write_reg(ci, 0x17, ci->clk_reg_f)); | ||
298 | |||
299 | CHK_ERROR(write_reg(ci, 0x20, 0x28)); /* Integer Divider, Falling Edge, Internal Sync, */ | ||
300 | CHK_ERROR(write_reg(ci, 0x21, 0x00)); /* MCLKI = TICLK/8 */ | ||
301 | CHK_ERROR(write_reg(ci, 0x22, 0x07)); /* MCLKI = TICLK/8 */ | ||
302 | |||
303 | |||
304 | CHK_ERROR(write_regm(ci, 0x20, 0x80, 0x80)); /* Reset CAM state machine */ | ||
305 | |||
306 | CHK_ERROR(write_regm(ci, 0x03, 0x02, 02)); /* Enable IREQA Interrupt */ | ||
307 | CHK_ERROR(write_reg(ci, 0x01, 0x04)); /* Enable CD Interrupt */ | ||
308 | CHK_ERROR(write_reg(ci, 0x00, 0x31)); /* Enable TS1,Hot Swap,Slot A */ | ||
309 | CHK_ERROR(write_regm(ci, 0x09, 0x08, 0x08)); /* Put TS in bypass */ | ||
310 | ci->cammode = -1; | ||
311 | #ifdef BUFFER_MODE | ||
312 | cam_mode(ci, 0); | ||
313 | #endif | ||
314 | } while (0); | ||
315 | mutex_unlock(&ci->lock); | ||
316 | |||
317 | return 0; | ||
318 | } | ||
319 | |||
320 | |||
321 | static int read_attribute_mem(struct dvb_ca_en50221 *ca, | ||
322 | int slot, int address) | ||
323 | { | ||
324 | struct cxd *ci = ca->data; | ||
325 | u8 val; | ||
326 | mutex_lock(&ci->lock); | ||
327 | set_mode(ci, 1); | ||
328 | read_pccard(ci, address, &val, 1); | ||
329 | mutex_unlock(&ci->lock); | ||
330 | return val; | ||
331 | } | ||
332 | |||
333 | |||
334 | static int write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, | ||
335 | int address, u8 value) | ||
336 | { | ||
337 | struct cxd *ci = ca->data; | ||
338 | |||
339 | mutex_lock(&ci->lock); | ||
340 | set_mode(ci, 1); | ||
341 | write_pccard(ci, address, &value, 1); | ||
342 | mutex_unlock(&ci->lock); | ||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | static int read_cam_control(struct dvb_ca_en50221 *ca, | ||
347 | int slot, u8 address) | ||
348 | { | ||
349 | struct cxd *ci = ca->data; | ||
350 | u8 val; | ||
351 | |||
352 | mutex_lock(&ci->lock); | ||
353 | set_mode(ci, 0); | ||
354 | read_io(ci, address, &val); | ||
355 | mutex_unlock(&ci->lock); | ||
356 | return val; | ||
357 | } | ||
358 | |||
359 | static int write_cam_control(struct dvb_ca_en50221 *ca, int slot, | ||
360 | u8 address, u8 value) | ||
361 | { | ||
362 | struct cxd *ci = ca->data; | ||
363 | |||
364 | mutex_lock(&ci->lock); | ||
365 | set_mode(ci, 0); | ||
366 | write_io(ci, address, value); | ||
367 | mutex_unlock(&ci->lock); | ||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | static int slot_reset(struct dvb_ca_en50221 *ca, int slot) | ||
372 | { | ||
373 | struct cxd *ci = ca->data; | ||
374 | |||
375 | mutex_lock(&ci->lock); | ||
376 | cam_mode(ci, 0); | ||
377 | write_reg(ci, 0x00, 0x21); | ||
378 | write_reg(ci, 0x06, 0x1F); | ||
379 | write_reg(ci, 0x00, 0x31); | ||
380 | write_regm(ci, 0x20, 0x80, 0x80); | ||
381 | write_reg(ci, 0x03, 0x02); | ||
382 | ci->ready = 0; | ||
383 | ci->mode = -1; | ||
384 | { | ||
385 | int i; | ||
386 | for (i = 0; i < 100; i++) { | ||
387 | msleep(10); | ||
388 | if (ci->ready) | ||
389 | break; | ||
390 | } | ||
391 | } | ||
392 | mutex_unlock(&ci->lock); | ||
393 | /* msleep(500); */ | ||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | static int slot_shutdown(struct dvb_ca_en50221 *ca, int slot) | ||
398 | { | ||
399 | struct cxd *ci = ca->data; | ||
400 | |||
401 | printk(KERN_INFO "slot_shutdown\n"); | ||
402 | mutex_lock(&ci->lock); | ||
403 | /* write_regm(ci, 0x09, 0x08, 0x08); */ | ||
404 | write_regm(ci, 0x20, 0x80, 0x80); | ||
405 | write_regm(ci, 0x06, 0x07, 0x07); | ||
406 | ci->mode = -1; | ||
407 | mutex_unlock(&ci->lock); | ||
408 | return 0; /* shutdown(ci); */ | ||
409 | } | ||
410 | |||
411 | static int slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) | ||
412 | { | ||
413 | struct cxd *ci = ca->data; | ||
414 | |||
415 | mutex_lock(&ci->lock); | ||
416 | write_regm(ci, 0x09, 0x00, 0x08); | ||
417 | set_mode(ci, 0); | ||
418 | #ifdef BUFFER_MODE | ||
419 | cam_mode(ci, 1); | ||
420 | #endif | ||
421 | mutex_unlock(&ci->lock); | ||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | |||
426 | static int campoll(struct cxd *ci) | ||
427 | { | ||
428 | u8 istat; | ||
429 | |||
430 | read_reg(ci, 0x04, &istat); | ||
431 | if (!istat) | ||
432 | return 0; | ||
433 | write_reg(ci, 0x05, istat); | ||
434 | |||
435 | if (istat&0x40) { | ||
436 | ci->dr = 1; | ||
437 | printk(KERN_INFO "DR\n"); | ||
438 | } | ||
439 | if (istat&0x20) | ||
440 | printk(KERN_INFO "WC\n"); | ||
441 | |||
442 | if (istat&2) { | ||
443 | u8 slotstat; | ||
444 | |||
445 | read_reg(ci, 0x01, &slotstat); | ||
446 | if (!(2&slotstat)) { | ||
447 | if (!ci->slot_stat) { | ||
448 | ci->slot_stat |= DVB_CA_EN50221_POLL_CAM_PRESENT; | ||
449 | write_regm(ci, 0x03, 0x08, 0x08); | ||
450 | } | ||
451 | |||
452 | } else { | ||
453 | if (ci->slot_stat) { | ||
454 | ci->slot_stat = 0; | ||
455 | write_regm(ci, 0x03, 0x00, 0x08); | ||
456 | printk(KERN_INFO "NO CAM\n"); | ||
457 | ci->ready = 0; | ||
458 | } | ||
459 | } | ||
460 | if (istat&8 && ci->slot_stat == DVB_CA_EN50221_POLL_CAM_PRESENT) { | ||
461 | ci->ready = 1; | ||
462 | ci->slot_stat |= DVB_CA_EN50221_POLL_CAM_READY; | ||
463 | printk(KERN_INFO "READY\n"); | ||
464 | } | ||
465 | } | ||
466 | return 0; | ||
467 | } | ||
468 | |||
469 | |||
470 | static int poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) | ||
471 | { | ||
472 | struct cxd *ci = ca->data; | ||
473 | u8 slotstat; | ||
474 | |||
475 | mutex_lock(&ci->lock); | ||
476 | campoll(ci); | ||
477 | read_reg(ci, 0x01, &slotstat); | ||
478 | mutex_unlock(&ci->lock); | ||
479 | |||
480 | return ci->slot_stat; | ||
481 | } | ||
482 | |||
483 | #ifdef BUFFER_MODE | ||
484 | static int read_data(struct dvb_ca_en50221 *ca, int slot, u8 *ebuf, int ecount) | ||
485 | { | ||
486 | struct cxd *ci = ca->data; | ||
487 | u8 msb, lsb; | ||
488 | u16 len; | ||
489 | |||
490 | mutex_lock(&ci->lock); | ||
491 | campoll(ci); | ||
492 | mutex_unlock(&ci->lock); | ||
493 | |||
494 | printk(KERN_INFO "read_data\n"); | ||
495 | if (!ci->dr) | ||
496 | return 0; | ||
497 | |||
498 | mutex_lock(&ci->lock); | ||
499 | read_reg(ci, 0x0f, &msb); | ||
500 | read_reg(ci, 0x10, &lsb); | ||
501 | len = (msb<<8)|lsb; | ||
502 | read_block(ci, 0x12, ebuf, len); | ||
503 | ci->dr = 0; | ||
504 | mutex_unlock(&ci->lock); | ||
505 | |||
506 | return len; | ||
507 | } | ||
508 | |||
509 | static int write_data(struct dvb_ca_en50221 *ca, int slot, u8 *ebuf, int ecount) | ||
510 | { | ||
511 | struct cxd *ci = ca->data; | ||
512 | |||
513 | mutex_lock(&ci->lock); | ||
514 | printk(KERN_INFO "write_data %d\n", ecount); | ||
515 | write_reg(ci, 0x0d, ecount>>8); | ||
516 | write_reg(ci, 0x0e, ecount&0xff); | ||
517 | write_block(ci, 0x11, ebuf, ecount); | ||
518 | mutex_unlock(&ci->lock); | ||
519 | return ecount; | ||
520 | } | ||
521 | #endif | ||
522 | |||
523 | static struct dvb_ca_en50221 en_templ = { | ||
524 | .read_attribute_mem = read_attribute_mem, | ||
525 | .write_attribute_mem = write_attribute_mem, | ||
526 | .read_cam_control = read_cam_control, | ||
527 | .write_cam_control = write_cam_control, | ||
528 | .slot_reset = slot_reset, | ||
529 | .slot_shutdown = slot_shutdown, | ||
530 | .slot_ts_enable = slot_ts_enable, | ||
531 | .poll_slot_status = poll_slot_status, | ||
532 | #ifdef BUFFER_MODE | ||
533 | .read_data = read_data, | ||
534 | .write_data = write_data, | ||
535 | #endif | ||
536 | |||
537 | }; | ||
538 | |||
539 | struct dvb_ca_en50221 *cxd2099_attach(u8 adr, void *priv, | ||
540 | struct i2c_adapter *i2c) | ||
541 | { | ||
542 | struct cxd *ci = 0; | ||
543 | u32 bitrate = 62000000; | ||
544 | u8 val; | ||
545 | |||
546 | if (i2c_read_reg(i2c, adr, 0, &val) < 0) { | ||
547 | printk(KERN_ERR "No CXD2099 detected at %02x\n", adr); | ||
548 | return 0; | ||
549 | } | ||
550 | |||
551 | ci = kmalloc(sizeof(struct cxd), GFP_KERNEL); | ||
552 | if (!ci) | ||
553 | return 0; | ||
554 | memset(ci, 0, sizeof(*ci)); | ||
555 | |||
556 | mutex_init(&ci->lock); | ||
557 | ci->i2c = i2c; | ||
558 | ci->adr = adr; | ||
559 | ci->lastaddress = 0xff; | ||
560 | ci->clk_reg_b = 0x4a; | ||
561 | ci->clk_reg_f = 0x1b; | ||
562 | ci->bitrate = bitrate; | ||
563 | |||
564 | memcpy(&ci->en, &en_templ, sizeof(en_templ)); | ||
565 | ci->en.data = ci; | ||
566 | init(ci); | ||
567 | printk(KERN_INFO "Attached CXD2099AR at %02x\n", ci->adr); | ||
568 | return &ci->en; | ||
569 | } | ||
570 | EXPORT_SYMBOL(cxd2099_attach); | ||
571 | |||
572 | MODULE_DESCRIPTION("cxd2099"); | ||
573 | MODULE_AUTHOR("Ralph Metzler <rjkm@metzlerbros.de>"); | ||
574 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/dvb/ngene/cxd2099.h b/drivers/media/dvb/ngene/cxd2099.h new file mode 100644 index 000000000000..f71b807e8bb7 --- /dev/null +++ b/drivers/media/dvb/ngene/cxd2099.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * cxd2099.h: Driver for the CXD2099AR Common Interface Controller | ||
3 | * | ||
4 | * Copyright (C) 2010 DigitalDevices UG | ||
5 | * | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 only, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
21 | * 02110-1301, USA | ||
22 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html | ||
23 | */ | ||
24 | |||
25 | #ifndef _CXD2099_H_ | ||
26 | #define _CXD2099_H_ | ||
27 | |||
28 | #include <dvb_ca_en50221.h> | ||
29 | |||
30 | struct dvb_ca_en50221 *cxd2099_attach(u8 adr, void *priv, struct i2c_adapter *i2c); | ||
31 | |||
32 | #endif | ||
diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c index fc93d1064d4e..93e6f9e954ca 100644 --- a/drivers/media/dvb/ngene/ngene-cards.c +++ b/drivers/media/dvb/ngene/ngene-cards.c | |||
@@ -317,7 +317,8 @@ static struct ngene_info ngene_info_satixS2v2 = { | |||
317 | static struct ngene_info ngene_info_cineS2v5 = { | 317 | static struct ngene_info ngene_info_cineS2v5 = { |
318 | .type = NGENE_SIDEWINDER, | 318 | .type = NGENE_SIDEWINDER, |
319 | .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)", | 319 | .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)", |
320 | .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN}, | 320 | .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, |
321 | NGENE_IO_TSOUT}, | ||
321 | .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe}, | 322 | .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe}, |
322 | .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110}, | 323 | .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110}, |
323 | .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2}, | 324 | .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2}, |
@@ -332,7 +333,8 @@ static struct ngene_info ngene_info_cineS2v5 = { | |||
332 | static struct ngene_info ngene_info_duoFlexS2 = { | 333 | static struct ngene_info ngene_info_duoFlexS2 = { |
333 | .type = NGENE_SIDEWINDER, | 334 | .type = NGENE_SIDEWINDER, |
334 | .name = "Digital Devices DuoFlex S2 miniPCIe", | 335 | .name = "Digital Devices DuoFlex S2 miniPCIe", |
335 | .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN}, | 336 | .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, |
337 | NGENE_IO_TSOUT}, | ||
336 | .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe}, | 338 | .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe}, |
337 | .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110}, | 339 | .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110}, |
338 | .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2}, | 340 | .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2}, |
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c index 831b7586e88f..deaf72aab058 100644 --- a/drivers/media/dvb/ngene/ngene-core.c +++ b/drivers/media/dvb/ngene/ngene-core.c | |||
@@ -45,7 +45,6 @@ static int one_adapter = 1; | |||
45 | module_param(one_adapter, int, 0444); | 45 | module_param(one_adapter, int, 0444); |
46 | MODULE_PARM_DESC(one_adapter, "Use only one adapter."); | 46 | MODULE_PARM_DESC(one_adapter, "Use only one adapter."); |
47 | 47 | ||
48 | |||
49 | static int debug; | 48 | static int debug; |
50 | module_param(debug, int, 0444); | 49 | module_param(debug, int, 0444); |
51 | MODULE_PARM_DESC(debug, "Print debugging information."); | 50 | MODULE_PARM_DESC(debug, "Print debugging information."); |
@@ -476,7 +475,7 @@ static u8 SPDIFConfiguration[10] = { | |||
476 | 475 | ||
477 | static u8 TS_I2SConfiguration[4] = { 0x3E, 0x18, 0x00, 0x00 }; | 476 | static u8 TS_I2SConfiguration[4] = { 0x3E, 0x18, 0x00, 0x00 }; |
478 | 477 | ||
479 | static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x20, 0x00, 0x00 }; | 478 | static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x04, 0x00, 0x00 }; |
480 | 479 | ||
481 | static u8 ITUDecoderSetup[4][16] = { | 480 | static u8 ITUDecoderSetup[4][16] = { |
482 | {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20, /* SDTV */ | 481 | {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20, /* SDTV */ |
@@ -749,13 +748,11 @@ void set_transfer(struct ngene_channel *chan, int state) | |||
749 | if (chan->mode & NGENE_IO_TSOUT) { | 748 | if (chan->mode & NGENE_IO_TSOUT) { |
750 | chan->pBufferExchange = tsout_exchange; | 749 | chan->pBufferExchange = tsout_exchange; |
751 | /* 0x66666666 = 50MHz *2^33 /250MHz */ | 750 | /* 0x66666666 = 50MHz *2^33 /250MHz */ |
752 | chan->AudioDTOValue = 0x66666666; | 751 | chan->AudioDTOValue = 0x80000000; |
753 | /* set_dto(chan, 38810700+1000); */ | 752 | chan->AudioDTOUpdated = 1; |
754 | /* set_dto(chan, 19392658); */ | ||
755 | } | 753 | } |
756 | if (chan->mode & NGENE_IO_TSIN) | 754 | if (chan->mode & NGENE_IO_TSIN) |
757 | chan->pBufferExchange = tsin_exchange; | 755 | chan->pBufferExchange = tsin_exchange; |
758 | /* ngwritel(0, 0x9310); */ | ||
759 | spin_unlock_irq(&chan->state_lock); | 756 | spin_unlock_irq(&chan->state_lock); |
760 | } else | 757 | } else |
761 | ;/* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n", | 758 | ;/* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n", |
@@ -1168,6 +1165,7 @@ static void ngene_release_buffers(struct ngene *dev) | |||
1168 | iounmap(dev->iomem); | 1165 | iounmap(dev->iomem); |
1169 | free_common_buffers(dev); | 1166 | free_common_buffers(dev); |
1170 | vfree(dev->tsout_buf); | 1167 | vfree(dev->tsout_buf); |
1168 | vfree(dev->tsin_buf); | ||
1171 | vfree(dev->ain_buf); | 1169 | vfree(dev->ain_buf); |
1172 | vfree(dev->vin_buf); | 1170 | vfree(dev->vin_buf); |
1173 | vfree(dev); | 1171 | vfree(dev); |
@@ -1184,6 +1182,13 @@ static int ngene_get_buffers(struct ngene *dev) | |||
1184 | dvb_ringbuffer_init(&dev->tsout_rbuf, | 1182 | dvb_ringbuffer_init(&dev->tsout_rbuf, |
1185 | dev->tsout_buf, TSOUT_BUF_SIZE); | 1183 | dev->tsout_buf, TSOUT_BUF_SIZE); |
1186 | } | 1184 | } |
1185 | if (dev->card_info->io_type[2]&NGENE_IO_TSIN) { | ||
1186 | dev->tsin_buf = vmalloc(TSIN_BUF_SIZE); | ||
1187 | if (!dev->tsin_buf) | ||
1188 | return -ENOMEM; | ||
1189 | dvb_ringbuffer_init(&dev->tsin_rbuf, | ||
1190 | dev->tsin_buf, TSIN_BUF_SIZE); | ||
1191 | } | ||
1187 | if (dev->card_info->io_type[2] & NGENE_IO_AIN) { | 1192 | if (dev->card_info->io_type[2] & NGENE_IO_AIN) { |
1188 | dev->ain_buf = vmalloc(AIN_BUF_SIZE); | 1193 | dev->ain_buf = vmalloc(AIN_BUF_SIZE); |
1189 | if (!dev->ain_buf) | 1194 | if (!dev->ain_buf) |
@@ -1307,6 +1312,35 @@ static void ngene_stop(struct ngene *dev) | |||
1307 | #endif | 1312 | #endif |
1308 | } | 1313 | } |
1309 | 1314 | ||
1315 | static int ngene_buffer_config(struct ngene *dev) | ||
1316 | { | ||
1317 | int stat; | ||
1318 | |||
1319 | if (dev->card_info->fw_version >= 17) { | ||
1320 | u8 tsin12_config[6] = { 0x60, 0x60, 0x00, 0x00, 0x00, 0x00 }; | ||
1321 | u8 tsin1234_config[6] = { 0x30, 0x30, 0x00, 0x30, 0x30, 0x00 }; | ||
1322 | u8 tsio1235_config[6] = { 0x30, 0x30, 0x00, 0x28, 0x00, 0x38 }; | ||
1323 | u8 *bconf = tsin12_config; | ||
1324 | |||
1325 | if (dev->card_info->io_type[2]&NGENE_IO_TSIN && | ||
1326 | dev->card_info->io_type[3]&NGENE_IO_TSIN) { | ||
1327 | bconf = tsin1234_config; | ||
1328 | if (dev->card_info->io_type[4]&NGENE_IO_TSOUT && | ||
1329 | dev->ci.en) | ||
1330 | bconf = tsio1235_config; | ||
1331 | } | ||
1332 | stat = ngene_command_config_free_buf(dev, bconf); | ||
1333 | } else { | ||
1334 | int bconf = BUFFER_CONFIG_4422; | ||
1335 | |||
1336 | if (dev->card_info->io_type[3] == NGENE_IO_TSIN) | ||
1337 | bconf = BUFFER_CONFIG_3333; | ||
1338 | stat = ngene_command_config_buf(dev, bconf); | ||
1339 | } | ||
1340 | return stat; | ||
1341 | } | ||
1342 | |||
1343 | |||
1310 | static int ngene_start(struct ngene *dev) | 1344 | static int ngene_start(struct ngene *dev) |
1311 | { | 1345 | { |
1312 | int stat; | 1346 | int stat; |
@@ -1371,23 +1405,6 @@ static int ngene_start(struct ngene *dev) | |||
1371 | if (stat < 0) | 1405 | if (stat < 0) |
1372 | goto fail; | 1406 | goto fail; |
1373 | 1407 | ||
1374 | if (dev->card_info->fw_version >= 17) { | ||
1375 | u8 tsin4_config[6] = { | ||
1376 | 3072 / 64, 3072 / 64, 0, 3072 / 64, 3072 / 64, 0}; | ||
1377 | u8 default_config[6] = { | ||
1378 | 4096 / 64, 4096 / 64, 0, 2048 / 64, 2048 / 64, 0}; | ||
1379 | u8 *bconf = default_config; | ||
1380 | |||
1381 | if (dev->card_info->io_type[3] == NGENE_IO_TSIN) | ||
1382 | bconf = tsin4_config; | ||
1383 | dprintk(KERN_DEBUG DEVICE_NAME ": FW 17+ buffer config\n"); | ||
1384 | stat = ngene_command_config_free_buf(dev, bconf); | ||
1385 | } else { | ||
1386 | int bconf = BUFFER_CONFIG_4422; | ||
1387 | if (dev->card_info->io_type[3] == NGENE_IO_TSIN) | ||
1388 | bconf = BUFFER_CONFIG_3333; | ||
1389 | stat = ngene_command_config_buf(dev, bconf); | ||
1390 | } | ||
1391 | if (!stat) | 1408 | if (!stat) |
1392 | return stat; | 1409 | return stat; |
1393 | 1410 | ||
@@ -1403,9 +1420,6 @@ fail2: | |||
1403 | return stat; | 1420 | return stat; |
1404 | } | 1421 | } |
1405 | 1422 | ||
1406 | |||
1407 | |||
1408 | |||
1409 | /****************************************************************************/ | 1423 | /****************************************************************************/ |
1410 | /****************************************************************************/ | 1424 | /****************************************************************************/ |
1411 | /****************************************************************************/ | 1425 | /****************************************************************************/ |
@@ -1422,7 +1436,12 @@ static void release_channel(struct ngene_channel *chan) | |||
1422 | 1436 | ||
1423 | tasklet_kill(&chan->demux_tasklet); | 1437 | tasklet_kill(&chan->demux_tasklet); |
1424 | 1438 | ||
1439 | if (chan->number >= 2 && chan->number <= 3 && dev->ci.en) | ||
1440 | return; | ||
1441 | |||
1425 | if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { | 1442 | if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { |
1443 | if (chan->ci_dev) | ||
1444 | dvb_unregister_device(chan->ci_dev); | ||
1426 | if (chan->fe) { | 1445 | if (chan->fe) { |
1427 | dvb_unregister_frontend(chan->fe); | 1446 | dvb_unregister_frontend(chan->fe); |
1428 | dvb_frontend_detach(chan->fe); | 1447 | dvb_frontend_detach(chan->fe); |
@@ -1458,6 +1477,9 @@ static int init_channel(struct ngene_channel *chan) | |||
1458 | if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { | 1477 | if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { |
1459 | if (nr >= STREAM_AUDIOIN1) | 1478 | if (nr >= STREAM_AUDIOIN1) |
1460 | chan->DataFormatFlags = DF_SWAP32; | 1479 | chan->DataFormatFlags = DF_SWAP32; |
1480 | |||
1481 | if (nr >= 2 && nr <= 3 && dev->ci.en) | ||
1482 | return 0; | ||
1461 | if (nr == 0 || !one_adapter || dev->first_adapter == NULL) { | 1483 | if (nr == 0 || !one_adapter || dev->first_adapter == NULL) { |
1462 | adapter = &dev->adapter[nr]; | 1484 | adapter = &dev->adapter[nr]; |
1463 | ret = dvb_register_adapter(adapter, "nGene", | 1485 | ret = dvb_register_adapter(adapter, "nGene", |
@@ -1478,6 +1500,15 @@ static int init_channel(struct ngene_channel *chan) | |||
1478 | ret = my_dvb_dmxdev_ts_card_init(&chan->dmxdev, &chan->demux, | 1500 | ret = my_dvb_dmxdev_ts_card_init(&chan->dmxdev, &chan->demux, |
1479 | &chan->hw_frontend, | 1501 | &chan->hw_frontend, |
1480 | &chan->mem_frontend, adapter); | 1502 | &chan->mem_frontend, adapter); |
1503 | if (dev->ci.en && (io&NGENE_IO_TSOUT)) { | ||
1504 | dvb_ca_en50221_init(adapter, dev->ci.en, 0, 1); | ||
1505 | set_transfer(chan, 1); | ||
1506 | set_transfer(&chan->dev->channel[2], 1); | ||
1507 | |||
1508 | dvb_register_device(adapter, &chan->ci_dev, | ||
1509 | &ngene_dvbdev_ci, (void *) chan, | ||
1510 | DVB_DEVICE_SEC); | ||
1511 | } | ||
1481 | } | 1512 | } |
1482 | 1513 | ||
1483 | if (io & NGENE_IO_TSIN) { | 1514 | if (io & NGENE_IO_TSIN) { |
@@ -1525,6 +1556,24 @@ static int init_channels(struct ngene *dev) | |||
1525 | return 0; | 1556 | return 0; |
1526 | } | 1557 | } |
1527 | 1558 | ||
1559 | static void cxd_attach(struct ngene *dev) | ||
1560 | { | ||
1561 | struct ngene_ci *ci = &dev->ci; | ||
1562 | |||
1563 | ci->en = cxd2099_attach(0x40, dev, &dev->channel[0].i2c_adapter); | ||
1564 | ci->dev = dev; | ||
1565 | return; | ||
1566 | } | ||
1567 | |||
1568 | static void cxd_detach(struct ngene *dev) | ||
1569 | { | ||
1570 | struct ngene_ci *ci = &dev->ci; | ||
1571 | |||
1572 | dvb_ca_en50221_release(ci->en); | ||
1573 | kfree(ci->en); | ||
1574 | ci->en = 0; | ||
1575 | } | ||
1576 | |||
1528 | /****************************************************************************/ | 1577 | /****************************************************************************/ |
1529 | /* device probe/remove calls ************************************************/ | 1578 | /* device probe/remove calls ************************************************/ |
1530 | /****************************************************************************/ | 1579 | /****************************************************************************/ |
@@ -1537,6 +1586,8 @@ void __devexit ngene_remove(struct pci_dev *pdev) | |||
1537 | tasklet_kill(&dev->event_tasklet); | 1586 | tasklet_kill(&dev->event_tasklet); |
1538 | for (i = MAX_STREAM - 1; i >= 0; i--) | 1587 | for (i = MAX_STREAM - 1; i >= 0; i--) |
1539 | release_channel(&dev->channel[i]); | 1588 | release_channel(&dev->channel[i]); |
1589 | if (dev->ci.en) | ||
1590 | cxd_detach(dev); | ||
1540 | ngene_stop(dev); | 1591 | ngene_stop(dev); |
1541 | ngene_release_buffers(dev); | 1592 | ngene_release_buffers(dev); |
1542 | pci_set_drvdata(pdev, NULL); | 1593 | pci_set_drvdata(pdev, NULL); |
@@ -1572,6 +1623,13 @@ int __devinit ngene_probe(struct pci_dev *pci_dev, | |||
1572 | if (stat < 0) | 1623 | if (stat < 0) |
1573 | goto fail1; | 1624 | goto fail1; |
1574 | 1625 | ||
1626 | cxd_attach(dev); | ||
1627 | |||
1628 | stat = ngene_buffer_config(dev); | ||
1629 | if (stat < 0) | ||
1630 | goto fail1; | ||
1631 | |||
1632 | |||
1575 | dev->i2c_current_bus = -1; | 1633 | dev->i2c_current_bus = -1; |
1576 | 1634 | ||
1577 | /* Register DVB adapters and devices for both channels */ | 1635 | /* Register DVB adapters and devices for both channels */ |
diff --git a/drivers/media/dvb/ngene/ngene-dvb.c b/drivers/media/dvb/ngene/ngene-dvb.c index 8bb159370c70..0b4943233166 100644 --- a/drivers/media/dvb/ngene/ngene-dvb.c +++ b/drivers/media/dvb/ngene/ngene-dvb.c | |||
@@ -47,6 +47,64 @@ | |||
47 | /* COMMAND API interface ****************************************************/ | 47 | /* COMMAND API interface ****************************************************/ |
48 | /****************************************************************************/ | 48 | /****************************************************************************/ |
49 | 49 | ||
50 | static ssize_t ts_write(struct file *file, const char *buf, | ||
51 | size_t count, loff_t *ppos) | ||
52 | { | ||
53 | struct dvb_device *dvbdev = file->private_data; | ||
54 | struct ngene_channel *chan = dvbdev->priv; | ||
55 | struct ngene *dev = chan->dev; | ||
56 | |||
57 | if (wait_event_interruptible(dev->tsout_rbuf.queue, | ||
58 | dvb_ringbuffer_free | ||
59 | (&dev->tsout_rbuf) >= count) < 0) | ||
60 | return 0; | ||
61 | |||
62 | dvb_ringbuffer_write(&dev->tsout_rbuf, buf, count); | ||
63 | |||
64 | return count; | ||
65 | } | ||
66 | |||
67 | static ssize_t ts_read(struct file *file, char *buf, | ||
68 | size_t count, loff_t *ppos) | ||
69 | { | ||
70 | struct dvb_device *dvbdev = file->private_data; | ||
71 | struct ngene_channel *chan = dvbdev->priv; | ||
72 | struct ngene *dev = chan->dev; | ||
73 | int left, avail; | ||
74 | |||
75 | left = count; | ||
76 | while (left) { | ||
77 | if (wait_event_interruptible( | ||
78 | dev->tsin_rbuf.queue, | ||
79 | dvb_ringbuffer_avail(&dev->tsin_rbuf) > 0) < 0) | ||
80 | return -EAGAIN; | ||
81 | avail = dvb_ringbuffer_avail(&dev->tsin_rbuf); | ||
82 | if (avail > left) | ||
83 | avail = left; | ||
84 | dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail); | ||
85 | left -= avail; | ||
86 | buf += avail; | ||
87 | } | ||
88 | return count; | ||
89 | } | ||
90 | |||
91 | static const struct file_operations ci_fops = { | ||
92 | .owner = THIS_MODULE, | ||
93 | .read = ts_read, | ||
94 | .write = ts_write, | ||
95 | .open = dvb_generic_open, | ||
96 | .release = dvb_generic_release, | ||
97 | }; | ||
98 | |||
99 | struct dvb_device ngene_dvbdev_ci = { | ||
100 | .priv = 0, | ||
101 | .readers = -1, | ||
102 | .writers = -1, | ||
103 | .users = -1, | ||
104 | .fops = &ci_fops, | ||
105 | }; | ||
106 | |||
107 | |||
50 | /****************************************************************************/ | 108 | /****************************************************************************/ |
51 | /* DVB functions and API interface ******************************************/ | 109 | /* DVB functions and API interface ******************************************/ |
52 | /****************************************************************************/ | 110 | /****************************************************************************/ |
@@ -63,11 +121,19 @@ static void swap_buffer(u32 *p, u32 len) | |||
63 | void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) | 121 | void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) |
64 | { | 122 | { |
65 | struct ngene_channel *chan = priv; | 123 | struct ngene_channel *chan = priv; |
124 | struct ngene *dev = chan->dev; | ||
66 | 125 | ||
67 | 126 | ||
127 | if (flags & DF_SWAP32) | ||
128 | swap_buffer(buf, len); | ||
129 | if (dev->ci.en && chan->number == 2) { | ||
130 | if (dvb_ringbuffer_free(&dev->tsin_rbuf) > len) { | ||
131 | dvb_ringbuffer_write(&dev->tsin_rbuf, buf, len); | ||
132 | wake_up_interruptible(&dev->tsin_rbuf.queue); | ||
133 | } | ||
134 | return 0; | ||
135 | } | ||
68 | if (chan->users > 0) { | 136 | if (chan->users > 0) { |
69 | if (flags & DF_SWAP32) | ||
70 | swap_buffer(buf, len); | ||
71 | dvb_dmx_swfilter(&chan->demux, buf, len); | 137 | dvb_dmx_swfilter(&chan->demux, buf, len); |
72 | } | 138 | } |
73 | return NULL; | 139 | return NULL; |
diff --git a/drivers/media/dvb/ngene/ngene.h b/drivers/media/dvb/ngene/ngene.h index 8fb4200f83f8..f7834066386f 100644 --- a/drivers/media/dvb/ngene/ngene.h +++ b/drivers/media/dvb/ngene/ngene.h | |||
@@ -36,8 +36,10 @@ | |||
36 | #include "dmxdev.h" | 36 | #include "dmxdev.h" |
37 | #include "dvbdev.h" | 37 | #include "dvbdev.h" |
38 | #include "dvb_demux.h" | 38 | #include "dvb_demux.h" |
39 | #include "dvb_ca_en50221.h" | ||
39 | #include "dvb_frontend.h" | 40 | #include "dvb_frontend.h" |
40 | #include "dvb_ringbuffer.h" | 41 | #include "dvb_ringbuffer.h" |
42 | #include "cxd2099.h" | ||
41 | 43 | ||
42 | #define DEVICE_NAME "ngene" | 44 | #define DEVICE_NAME "ngene" |
43 | 45 | ||
@@ -644,6 +646,7 @@ struct ngene_channel { | |||
644 | struct dmx_frontend mem_frontend; | 646 | struct dmx_frontend mem_frontend; |
645 | int users; | 647 | int users; |
646 | struct video_device *v4l_dev; | 648 | struct video_device *v4l_dev; |
649 | struct dvb_device *ci_dev; | ||
647 | struct tasklet_struct demux_tasklet; | 650 | struct tasklet_struct demux_tasklet; |
648 | 651 | ||
649 | struct SBufferHeader *nextBuffer; | 652 | struct SBufferHeader *nextBuffer; |
@@ -710,6 +713,15 @@ struct ngene_channel { | |||
710 | int running; | 713 | int running; |
711 | }; | 714 | }; |
712 | 715 | ||
716 | |||
717 | struct ngene_ci { | ||
718 | struct device device; | ||
719 | struct i2c_adapter i2c_adapter; | ||
720 | |||
721 | struct ngene *dev; | ||
722 | struct dvb_ca_en50221 *en; | ||
723 | }; | ||
724 | |||
713 | struct ngene; | 725 | struct ngene; |
714 | 726 | ||
715 | typedef void (rx_cb_t)(struct ngene *, u32, u8); | 727 | typedef void (rx_cb_t)(struct ngene *, u32, u8); |
@@ -774,6 +786,10 @@ struct ngene { | |||
774 | #define TSOUT_BUF_SIZE (512*188*8) | 786 | #define TSOUT_BUF_SIZE (512*188*8) |
775 | struct dvb_ringbuffer tsout_rbuf; | 787 | struct dvb_ringbuffer tsout_rbuf; |
776 | 788 | ||
789 | u8 *tsin_buf; | ||
790 | #define TSIN_BUF_SIZE (512*188*8) | ||
791 | struct dvb_ringbuffer tsin_rbuf; | ||
792 | |||
777 | u8 *ain_buf; | 793 | u8 *ain_buf; |
778 | #define AIN_BUF_SIZE (128*1024) | 794 | #define AIN_BUF_SIZE (128*1024) |
779 | struct dvb_ringbuffer ain_rbuf; | 795 | struct dvb_ringbuffer ain_rbuf; |
@@ -785,6 +801,8 @@ struct ngene { | |||
785 | 801 | ||
786 | unsigned long exp_val; | 802 | unsigned long exp_val; |
787 | int prev_cmd; | 803 | int prev_cmd; |
804 | |||
805 | struct ngene_ci ci; | ||
788 | }; | 806 | }; |
789 | 807 | ||
790 | struct ngene_info { | 808 | struct ngene_info { |
@@ -872,6 +890,7 @@ void FillTSBuffer(void *Buffer, int Length, u32 Flags); | |||
872 | int ngene_i2c_init(struct ngene *dev, int dev_nr); | 890 | int ngene_i2c_init(struct ngene *dev, int dev_nr); |
873 | 891 | ||
874 | /* Provided by ngene-dvb.c */ | 892 | /* Provided by ngene-dvb.c */ |
893 | extern struct dvb_device ngene_dvbdev_ci; | ||
875 | void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); | 894 | void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); |
876 | void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); | 895 | void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); |
877 | int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed); | 896 | int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed); |