diff options
author | Igor M. Liplianin <liplianin@me.by> | 2011-01-25 15:01:00 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-21 19:32:16 -0400 |
commit | 349bcf02e3615556e9c49ea73a04abab2a4d8ed7 (patch) | |
tree | b6447f8e27eeb93564bce12d924992fec1c11849 /drivers | |
parent | fa766c9be58bd872784b081074a7d15a3ce61c5f (diff) |
[media] Altera FPGA based CI driver module
An Altera FPGA CI module for NetUP Dual DVB-T/C RF CI card.
Signed-off-by: Igor M. Liplianin <liplianin@netup.ru>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/cx23885/Kconfig | 9 | ||||
-rw-r--r-- | drivers/media/video/cx23885/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/video/cx23885/altera-ci.c | 830 | ||||
-rw-r--r-- | drivers/media/video/cx23885/altera-ci.h | 102 |
4 files changed, 942 insertions, 0 deletions
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig index 6b4a516addfe..5e5faadd678f 100644 --- a/drivers/media/video/cx23885/Kconfig +++ b/drivers/media/video/cx23885/Kconfig | |||
@@ -33,3 +33,12 @@ config VIDEO_CX23885 | |||
33 | To compile this driver as a module, choose M here: the | 33 | To compile this driver as a module, choose M here: the |
34 | module will be called cx23885 | 34 | module will be called cx23885 |
35 | 35 | ||
36 | config MEDIA_ALTERA_CI | ||
37 | tristate "Altera FPGA based CI module" | ||
38 | depends on VIDEO_CX23885 && DVB_CORE | ||
39 | select STAPL_ALTERA | ||
40 | ---help--- | ||
41 | An Altera FPGA CI module for NetUP Dual DVB-T/C RF CI card. | ||
42 | |||
43 | To compile this driver as a module, choose M here: the | ||
44 | module will be called altera-ci | ||
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile index e2ee95f660d8..23293c7b6ac7 100644 --- a/drivers/media/video/cx23885/Makefile +++ b/drivers/media/video/cx23885/Makefile | |||
@@ -5,6 +5,7 @@ cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \ | |||
5 | cx23885-f300.o | 5 | cx23885-f300.o |
6 | 6 | ||
7 | obj-$(CONFIG_VIDEO_CX23885) += cx23885.o | 7 | obj-$(CONFIG_VIDEO_CX23885) += cx23885.o |
8 | obj-$(CONFIG_MEDIA_ALTERA_CI) += altera-ci.o | ||
8 | 9 | ||
9 | EXTRA_CFLAGS += -Idrivers/media/video | 10 | EXTRA_CFLAGS += -Idrivers/media/video |
10 | EXTRA_CFLAGS += -Idrivers/media/common/tuners | 11 | EXTRA_CFLAGS += -Idrivers/media/common/tuners |
diff --git a/drivers/media/video/cx23885/altera-ci.c b/drivers/media/video/cx23885/altera-ci.c new file mode 100644 index 000000000000..e5c0873aca15 --- /dev/null +++ b/drivers/media/video/cx23885/altera-ci.c | |||
@@ -0,0 +1,830 @@ | |||
1 | /* | ||
2 | * altera-ci.c | ||
3 | * | ||
4 | * CI driver in conjunction with NetUp Dual DVB-T/C RF CI card | ||
5 | * | ||
6 | * Copyright (C) 2010,2011 NetUP Inc. | ||
7 | * Copyright (C) 2010,2011 Igor M. Liplianin <liplianin@netup.ru> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | ||
24 | |||
25 | /* | ||
26 | * currently cx23885 GPIO's used. | ||
27 | * GPIO-0 ~INT in | ||
28 | * GPIO-1 TMS out | ||
29 | * GPIO-2 ~reset chips out | ||
30 | * GPIO-3 to GPIO-10 data/addr for CA in/out | ||
31 | * GPIO-11 ~CS out | ||
32 | * GPIO-12 AD_RG out | ||
33 | * GPIO-13 ~WR out | ||
34 | * GPIO-14 ~RD out | ||
35 | * GPIO-15 ~RDY in | ||
36 | * GPIO-16 TCK out | ||
37 | * GPIO-17 TDO in | ||
38 | * GPIO-18 TDI out | ||
39 | */ | ||
40 | /* | ||
41 | * Bit definitions for MC417_RWD and MC417_OEN registers | ||
42 | * bits 31-16 | ||
43 | * +-----------+ | ||
44 | * | Reserved | | ||
45 | * +-----------+ | ||
46 | * bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 | ||
47 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | ||
48 | * | TDI | TDO | TCK | RDY# | #RD | #WR | AD_RG | #CS | | ||
49 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | ||
50 | * bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 | ||
51 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | ||
52 | * | DATA7| DATA6| DATA5| DATA4| DATA3| DATA2| DATA1| DATA0| | ||
53 | * +-------+-------+-------+-------+-------+-------+-------+-------+ | ||
54 | */ | ||
55 | #include <linux/version.h> | ||
56 | #include <media/videobuf-dma-sg.h> | ||
57 | #include <media/videobuf-dvb.h> | ||
58 | #include "altera-ci.h" | ||
59 | #include "dvb_ca_en50221.h" | ||
60 | |||
61 | /* FPGA regs */ | ||
62 | #define NETUP_CI_INT_CTRL 0x00 | ||
63 | #define NETUP_CI_BUSCTRL2 0x01 | ||
64 | #define NETUP_CI_ADDR0 0x04 | ||
65 | #define NETUP_CI_ADDR1 0x05 | ||
66 | #define NETUP_CI_DATA 0x06 | ||
67 | #define NETUP_CI_BUSCTRL 0x07 | ||
68 | #define NETUP_CI_PID_ADDR0 0x08 | ||
69 | #define NETUP_CI_PID_ADDR1 0x09 | ||
70 | #define NETUP_CI_PID_DATA 0x0a | ||
71 | #define NETUP_CI_TSA_DIV 0x0c | ||
72 | #define NETUP_CI_TSB_DIV 0x0d | ||
73 | #define NETUP_CI_REVISION 0x0f | ||
74 | |||
75 | /* const for ci op */ | ||
76 | #define NETUP_CI_FLG_CTL 1 | ||
77 | #define NETUP_CI_FLG_RD 1 | ||
78 | #define NETUP_CI_FLG_AD 1 | ||
79 | |||
80 | static unsigned int ci_dbg; | ||
81 | module_param(ci_dbg, int, 0644); | ||
82 | MODULE_PARM_DESC(ci_dbg, "Enable CI debugging"); | ||
83 | |||
84 | static unsigned int pid_dbg; | ||
85 | module_param(pid_dbg, int, 0644); | ||
86 | MODULE_PARM_DESC(pid_dbg, "Enable PID filtering debugging"); | ||
87 | |||
88 | MODULE_DESCRIPTION("altera FPGA CI module"); | ||
89 | MODULE_AUTHOR("Igor M. Liplianin <liplianin@netup.ru>"); | ||
90 | MODULE_LICENSE("GPL"); | ||
91 | |||
92 | #define ci_dbg_print(args...) \ | ||
93 | do { \ | ||
94 | if (ci_dbg) \ | ||
95 | printk(KERN_DEBUG args); \ | ||
96 | } while (0) | ||
97 | |||
98 | #define pid_dbg_print(args...) \ | ||
99 | do { \ | ||
100 | if (pid_dbg) \ | ||
101 | printk(KERN_DEBUG args); \ | ||
102 | } while (0) | ||
103 | |||
104 | struct altera_ci_state; | ||
105 | struct netup_hw_pid_filter; | ||
106 | |||
107 | struct fpga_internal { | ||
108 | void *dev; | ||
109 | struct mutex fpga_mutex;/* two CI's on the same fpga */ | ||
110 | struct netup_hw_pid_filter *pid_filt[2]; | ||
111 | struct altera_ci_state *state[2]; | ||
112 | struct work_struct work; | ||
113 | int (*fpga_rw) (void *dev, int flag, int data, int rw); | ||
114 | int cis_used; | ||
115 | int filts_used; | ||
116 | int strt_wrk; | ||
117 | }; | ||
118 | |||
119 | /* stores all private variables for communication with CI */ | ||
120 | struct altera_ci_state { | ||
121 | struct fpga_internal *internal; | ||
122 | struct dvb_ca_en50221 ca; | ||
123 | int status; | ||
124 | int nr; | ||
125 | }; | ||
126 | |||
127 | /* stores all private variables for hardware pid filtering */ | ||
128 | struct netup_hw_pid_filter { | ||
129 | struct fpga_internal *internal; | ||
130 | struct dvb_demux *demux; | ||
131 | /* save old functions */ | ||
132 | int (*start_feed)(struct dvb_demux_feed *feed); | ||
133 | int (*stop_feed)(struct dvb_demux_feed *feed); | ||
134 | |||
135 | int status; | ||
136 | int nr; | ||
137 | }; | ||
138 | |||
139 | /* internal params node */ | ||
140 | struct fpga_inode { | ||
141 | /* pointer for internal params, one for each pair of CI's */ | ||
142 | struct fpga_internal *internal; | ||
143 | struct fpga_inode *next_inode; | ||
144 | }; | ||
145 | |||
146 | /* first internal params */ | ||
147 | static struct fpga_inode *fpga_first_inode; | ||
148 | |||
149 | /* find chip by dev */ | ||
150 | static struct fpga_inode *find_inode(void *dev) | ||
151 | { | ||
152 | struct fpga_inode *temp_chip = fpga_first_inode; | ||
153 | |||
154 | if (temp_chip == NULL) | ||
155 | return temp_chip; | ||
156 | |||
157 | /* | ||
158 | Search for the last fpga CI chip or | ||
159 | find it by dev */ | ||
160 | while ((temp_chip != NULL) && | ||
161 | (temp_chip->internal->dev != dev)) | ||
162 | temp_chip = temp_chip->next_inode; | ||
163 | |||
164 | return temp_chip; | ||
165 | } | ||
166 | /* check demux */ | ||
167 | static struct fpga_internal *check_filter(struct fpga_internal *temp_int, | ||
168 | void *demux_dev, int filt_nr) | ||
169 | { | ||
170 | if (temp_int == NULL) | ||
171 | return NULL; | ||
172 | |||
173 | if ((temp_int->pid_filt[filt_nr]) == NULL) | ||
174 | return NULL; | ||
175 | |||
176 | if (temp_int->pid_filt[filt_nr]->demux == demux_dev) | ||
177 | return temp_int; | ||
178 | |||
179 | return NULL; | ||
180 | } | ||
181 | |||
182 | /* find chip by demux */ | ||
183 | static struct fpga_inode *find_dinode(void *demux_dev) | ||
184 | { | ||
185 | struct fpga_inode *temp_chip = fpga_first_inode; | ||
186 | struct fpga_internal *temp_int; | ||
187 | |||
188 | /* | ||
189 | * Search of the last fpga CI chip or | ||
190 | * find it by demux | ||
191 | */ | ||
192 | while (temp_chip != NULL) { | ||
193 | if (temp_chip->internal != NULL) { | ||
194 | temp_int = temp_chip->internal; | ||
195 | if (check_filter(temp_int, demux_dev, 0)) | ||
196 | break; | ||
197 | if (check_filter(temp_int, demux_dev, 1)) | ||
198 | break; | ||
199 | } | ||
200 | |||
201 | temp_chip = temp_chip->next_inode; | ||
202 | } | ||
203 | |||
204 | return temp_chip; | ||
205 | } | ||
206 | |||
207 | /* deallocating chip */ | ||
208 | static void remove_inode(struct fpga_internal *internal) | ||
209 | { | ||
210 | struct fpga_inode *prev_node = fpga_first_inode; | ||
211 | struct fpga_inode *del_node = find_inode(internal->dev); | ||
212 | |||
213 | if (del_node != NULL) { | ||
214 | if (del_node == fpga_first_inode) { | ||
215 | fpga_first_inode = del_node->next_inode; | ||
216 | } else { | ||
217 | while (prev_node->next_inode != del_node) | ||
218 | prev_node = prev_node->next_inode; | ||
219 | |||
220 | if (del_node->next_inode == NULL) | ||
221 | prev_node->next_inode = NULL; | ||
222 | else | ||
223 | prev_node->next_inode = | ||
224 | prev_node->next_inode->next_inode; | ||
225 | } | ||
226 | |||
227 | kfree(del_node); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /* allocating new chip */ | ||
232 | static struct fpga_inode *append_internal(struct fpga_internal *internal) | ||
233 | { | ||
234 | struct fpga_inode *new_node = fpga_first_inode; | ||
235 | |||
236 | if (new_node == NULL) { | ||
237 | new_node = kmalloc(sizeof(struct fpga_inode), GFP_KERNEL); | ||
238 | fpga_first_inode = new_node; | ||
239 | } else { | ||
240 | while (new_node->next_inode != NULL) | ||
241 | new_node = new_node->next_inode; | ||
242 | |||
243 | new_node->next_inode = | ||
244 | kmalloc(sizeof(struct fpga_inode), GFP_KERNEL); | ||
245 | if (new_node->next_inode != NULL) | ||
246 | new_node = new_node->next_inode; | ||
247 | else | ||
248 | new_node = NULL; | ||
249 | } | ||
250 | |||
251 | if (new_node != NULL) { | ||
252 | new_node->internal = internal; | ||
253 | new_node->next_inode = NULL; | ||
254 | } | ||
255 | |||
256 | return new_node; | ||
257 | } | ||
258 | |||
259 | static int netup_fpga_op_rw(struct fpga_internal *inter, int addr, | ||
260 | u8 val, u8 read) | ||
261 | { | ||
262 | inter->fpga_rw(inter->dev, NETUP_CI_FLG_AD, addr, 0); | ||
263 | return inter->fpga_rw(inter->dev, 0, val, read); | ||
264 | } | ||
265 | |||
266 | /* flag - mem/io, read - read/write */ | ||
267 | int altera_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot, | ||
268 | u8 flag, u8 read, int addr, u8 val) | ||
269 | { | ||
270 | |||
271 | struct altera_ci_state *state = en50221->data; | ||
272 | struct fpga_internal *inter = state->internal; | ||
273 | |||
274 | u8 store; | ||
275 | int mem = 0; | ||
276 | |||
277 | if (0 != slot) | ||
278 | return -EINVAL; | ||
279 | |||
280 | mutex_lock(&inter->fpga_mutex); | ||
281 | |||
282 | netup_fpga_op_rw(inter, NETUP_CI_ADDR0, ((addr << 1) & 0xfe), 0); | ||
283 | netup_fpga_op_rw(inter, NETUP_CI_ADDR1, ((addr >> 7) & 0x7f), 0); | ||
284 | store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); | ||
285 | |||
286 | store &= 0x3f; | ||
287 | store |= ((state->nr << 7) | (flag << 6)); | ||
288 | |||
289 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, store, 0); | ||
290 | mem = netup_fpga_op_rw(inter, NETUP_CI_DATA, val, read); | ||
291 | |||
292 | mutex_unlock(&inter->fpga_mutex); | ||
293 | |||
294 | ci_dbg_print("%s: %s: addr=[0x%02x], %s=%x\n", __func__, | ||
295 | (read) ? "read" : "write", addr, | ||
296 | (flag == NETUP_CI_FLG_CTL) ? "ctl" : "mem", | ||
297 | (read) ? mem : val); | ||
298 | |||
299 | return mem; | ||
300 | } | ||
301 | |||
302 | int altera_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221, | ||
303 | int slot, int addr) | ||
304 | { | ||
305 | return altera_ci_op_cam(en50221, slot, 0, NETUP_CI_FLG_RD, addr, 0); | ||
306 | } | ||
307 | |||
308 | int altera_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221, | ||
309 | int slot, int addr, u8 data) | ||
310 | { | ||
311 | return altera_ci_op_cam(en50221, slot, 0, 0, addr, data); | ||
312 | } | ||
313 | |||
314 | int altera_ci_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr) | ||
315 | { | ||
316 | return altera_ci_op_cam(en50221, slot, NETUP_CI_FLG_CTL, | ||
317 | NETUP_CI_FLG_RD, addr, 0); | ||
318 | } | ||
319 | |||
320 | int altera_ci_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, | ||
321 | u8 addr, u8 data) | ||
322 | { | ||
323 | return altera_ci_op_cam(en50221, slot, NETUP_CI_FLG_CTL, 0, addr, data); | ||
324 | } | ||
325 | |||
326 | int altera_ci_slot_reset(struct dvb_ca_en50221 *en50221, int slot) | ||
327 | { | ||
328 | struct altera_ci_state *state = en50221->data; | ||
329 | struct fpga_internal *inter = state->internal; | ||
330 | /* reasonable timeout for CI reset is 10 seconds */ | ||
331 | unsigned long t_out = jiffies + msecs_to_jiffies(9999); | ||
332 | int ret; | ||
333 | |||
334 | ci_dbg_print("%s\n", __func__); | ||
335 | |||
336 | if (0 != slot) | ||
337 | return -EINVAL; | ||
338 | |||
339 | mutex_lock(&inter->fpga_mutex); | ||
340 | |||
341 | ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); | ||
342 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, | ||
343 | ret | (1 << (5 - state->nr)), 0); | ||
344 | |||
345 | for (;;) { | ||
346 | mdelay(50); | ||
347 | ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, | ||
348 | 0, NETUP_CI_FLG_RD); | ||
349 | if ((ret & (1 << (5 - state->nr))) == 0) | ||
350 | break; | ||
351 | if (time_after(jiffies, t_out)) | ||
352 | break; | ||
353 | } | ||
354 | |||
355 | mutex_unlock(&inter->fpga_mutex); | ||
356 | |||
357 | ci_dbg_print("%s: %d msecs\n", __func__, | ||
358 | jiffies_to_msecs(jiffies + msecs_to_jiffies(9999) - t_out)); | ||
359 | |||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | int altera_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot) | ||
364 | { | ||
365 | /* not implemented */ | ||
366 | return 0; | ||
367 | } | ||
368 | |||
369 | int altera_ci_slot_ts_ctl(struct dvb_ca_en50221 *en50221, int slot) | ||
370 | { | ||
371 | struct altera_ci_state *state = en50221->data; | ||
372 | struct fpga_internal *inter = state->internal; | ||
373 | int ret; | ||
374 | |||
375 | ci_dbg_print("%s\n", __func__); | ||
376 | |||
377 | if (0 != slot) | ||
378 | return -EINVAL; | ||
379 | |||
380 | mutex_lock(&inter->fpga_mutex); | ||
381 | |||
382 | ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); | ||
383 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, | ||
384 | ret | (1 << (3 - state->nr)), 0); | ||
385 | |||
386 | mutex_unlock(&inter->fpga_mutex); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | /* work handler */ | ||
392 | static void netup_read_ci_status(struct work_struct *work) | ||
393 | { | ||
394 | struct fpga_internal *inter = | ||
395 | container_of(work, struct fpga_internal, work); | ||
396 | int ret; | ||
397 | |||
398 | ci_dbg_print("%s\n", __func__); | ||
399 | |||
400 | mutex_lock(&inter->fpga_mutex); | ||
401 | /* ack' irq */ | ||
402 | ret = netup_fpga_op_rw(inter, NETUP_CI_INT_CTRL, 0, NETUP_CI_FLG_RD); | ||
403 | ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); | ||
404 | |||
405 | mutex_unlock(&inter->fpga_mutex); | ||
406 | |||
407 | if (inter->state[1] != NULL) { | ||
408 | inter->state[1]->status = | ||
409 | ((ret & 1) == 0 ? | ||
410 | DVB_CA_EN50221_POLL_CAM_PRESENT | | ||
411 | DVB_CA_EN50221_POLL_CAM_READY : 0); | ||
412 | ci_dbg_print("%s: setting CI[1] status = 0x%x\n", | ||
413 | __func__, inter->state[1]->status); | ||
414 | }; | ||
415 | |||
416 | if (inter->state[0] != NULL) { | ||
417 | inter->state[0]->status = | ||
418 | ((ret & 2) == 0 ? | ||
419 | DVB_CA_EN50221_POLL_CAM_PRESENT | | ||
420 | DVB_CA_EN50221_POLL_CAM_READY : 0); | ||
421 | ci_dbg_print("%s: setting CI[0] status = 0x%x\n", | ||
422 | __func__, inter->state[0]->status); | ||
423 | }; | ||
424 | } | ||
425 | |||
426 | /* CI irq handler */ | ||
427 | int altera_ci_irq(void *dev) | ||
428 | { | ||
429 | struct fpga_inode *temp_int = NULL; | ||
430 | struct fpga_internal *inter = NULL; | ||
431 | |||
432 | ci_dbg_print("%s\n", __func__); | ||
433 | |||
434 | if (dev != NULL) { | ||
435 | temp_int = find_inode(dev); | ||
436 | if (temp_int != NULL) { | ||
437 | inter = temp_int->internal; | ||
438 | schedule_work(&inter->work); | ||
439 | } | ||
440 | } | ||
441 | |||
442 | return 1; | ||
443 | } | ||
444 | EXPORT_SYMBOL(altera_ci_irq); | ||
445 | |||
446 | int altera_poll_ci_slot_status(struct dvb_ca_en50221 *en50221, int slot, | ||
447 | int open) | ||
448 | { | ||
449 | struct altera_ci_state *state = en50221->data; | ||
450 | |||
451 | if (0 != slot) | ||
452 | return -EINVAL; | ||
453 | |||
454 | return state->status; | ||
455 | } | ||
456 | |||
457 | void altera_hw_filt_release(void *main_dev, int filt_nr) | ||
458 | { | ||
459 | struct fpga_inode *temp_int = find_inode(main_dev); | ||
460 | struct netup_hw_pid_filter *pid_filt = NULL; | ||
461 | |||
462 | ci_dbg_print("%s\n", __func__); | ||
463 | |||
464 | if (temp_int != NULL) { | ||
465 | pid_filt = temp_int->internal->pid_filt[filt_nr - 1]; | ||
466 | /* stored old feed controls */ | ||
467 | pid_filt->demux->start_feed = pid_filt->start_feed; | ||
468 | pid_filt->demux->stop_feed = pid_filt->stop_feed; | ||
469 | |||
470 | if (((--(temp_int->internal->filts_used)) <= 0) && | ||
471 | ((temp_int->internal->cis_used) <= 0)) { | ||
472 | |||
473 | ci_dbg_print("%s: Actually removing\n", __func__); | ||
474 | |||
475 | remove_inode(temp_int->internal); | ||
476 | kfree(pid_filt->internal); | ||
477 | } | ||
478 | |||
479 | kfree(pid_filt); | ||
480 | |||
481 | } | ||
482 | |||
483 | } | ||
484 | EXPORT_SYMBOL(altera_hw_filt_release); | ||
485 | |||
486 | void altera_ci_release(void *dev, int ci_nr) | ||
487 | { | ||
488 | struct fpga_inode *temp_int = find_inode(dev); | ||
489 | struct altera_ci_state *state = NULL; | ||
490 | |||
491 | ci_dbg_print("%s\n", __func__); | ||
492 | |||
493 | if (temp_int != NULL) { | ||
494 | state = temp_int->internal->state[ci_nr - 1]; | ||
495 | altera_hw_filt_release(dev, ci_nr); | ||
496 | |||
497 | |||
498 | if (((temp_int->internal->filts_used) <= 0) && | ||
499 | ((--(temp_int->internal->cis_used)) <= 0)) { | ||
500 | |||
501 | ci_dbg_print("%s: Actually removing\n", __func__); | ||
502 | |||
503 | remove_inode(temp_int->internal); | ||
504 | kfree(state->internal); | ||
505 | } | ||
506 | |||
507 | if (state != NULL) { | ||
508 | if (state->ca.data != NULL) | ||
509 | dvb_ca_en50221_release(&state->ca); | ||
510 | |||
511 | kfree(state); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | } | ||
516 | EXPORT_SYMBOL(altera_ci_release); | ||
517 | |||
518 | static void altera_pid_control(struct netup_hw_pid_filter *pid_filt, | ||
519 | u16 pid, int onoff) | ||
520 | { | ||
521 | struct fpga_internal *inter = pid_filt->internal; | ||
522 | u8 store = 0; | ||
523 | |||
524 | if (pid == 0x2000) | ||
525 | return; | ||
526 | |||
527 | mutex_lock(&inter->fpga_mutex); | ||
528 | |||
529 | netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR0, (pid >> 3) & 0xff, 0); | ||
530 | netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR1, | ||
531 | ((pid >> 11) & 0x03) | (pid_filt->nr << 2), 0); | ||
532 | |||
533 | store = netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, 0, NETUP_CI_FLG_RD); | ||
534 | |||
535 | if (onoff)/* 0 - on, 1 - off */ | ||
536 | store |= (1 << (pid & 7)); | ||
537 | else | ||
538 | store &= ~(1 << (pid & 7)); | ||
539 | |||
540 | netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, store, 0); | ||
541 | |||
542 | mutex_unlock(&inter->fpga_mutex); | ||
543 | |||
544 | pid_dbg_print("%s: (%d) set pid: %5d 0x%04x '%s'\n", __func__, | ||
545 | pid_filt->nr, pid, pid, onoff ? "off" : "on"); | ||
546 | } | ||
547 | |||
548 | static void altera_toggle_fullts_streaming(struct netup_hw_pid_filter *pid_filt, | ||
549 | int filt_nr, int onoff) | ||
550 | { | ||
551 | struct fpga_internal *inter = pid_filt->internal; | ||
552 | u8 store = 0; | ||
553 | int i; | ||
554 | |||
555 | pid_dbg_print("%s: pid_filt->nr[%d] now %s\n", __func__, pid_filt->nr, | ||
556 | onoff ? "off" : "on"); | ||
557 | |||
558 | if (onoff)/* 0 - on, 1 - off */ | ||
559 | store = 0xff;/* ignore pid */ | ||
560 | else | ||
561 | store = 0;/* enable pid */ | ||
562 | |||
563 | mutex_lock(&inter->fpga_mutex); | ||
564 | |||
565 | for (i = 0; i < 1024; i++) { | ||
566 | netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR0, i & 0xff, 0); | ||
567 | |||
568 | netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR1, | ||
569 | ((i >> 8) & 0x03) | (pid_filt->nr << 2), 0); | ||
570 | |||
571 | netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, store, 0); | ||
572 | } | ||
573 | |||
574 | mutex_unlock(&inter->fpga_mutex); | ||
575 | } | ||
576 | |||
577 | int altera_pid_feed_control(void *demux_dev, int filt_nr, | ||
578 | struct dvb_demux_feed *feed, int onoff) | ||
579 | { | ||
580 | struct fpga_inode *temp_int = find_dinode(demux_dev); | ||
581 | struct fpga_internal *inter = temp_int->internal; | ||
582 | struct netup_hw_pid_filter *pid_filt = inter->pid_filt[filt_nr - 1]; | ||
583 | |||
584 | altera_pid_control(pid_filt, feed->pid, onoff ? 0 : 1); | ||
585 | /* call old feed proc's */ | ||
586 | if (onoff) | ||
587 | pid_filt->start_feed(feed); | ||
588 | else | ||
589 | pid_filt->stop_feed(feed); | ||
590 | |||
591 | if (feed->pid == 0x2000) | ||
592 | altera_toggle_fullts_streaming(pid_filt, filt_nr, | ||
593 | onoff ? 0 : 1); | ||
594 | |||
595 | return 0; | ||
596 | } | ||
597 | EXPORT_SYMBOL(altera_pid_feed_control); | ||
598 | |||
599 | int altera_ci_start_feed(struct dvb_demux_feed *feed, int num) | ||
600 | { | ||
601 | altera_pid_feed_control(feed->demux, num, feed, 1); | ||
602 | |||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | int altera_ci_stop_feed(struct dvb_demux_feed *feed, int num) | ||
607 | { | ||
608 | altera_pid_feed_control(feed->demux, num, feed, 0); | ||
609 | |||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | int altera_ci_start_feed_1(struct dvb_demux_feed *feed) | ||
614 | { | ||
615 | return altera_ci_start_feed(feed, 1); | ||
616 | } | ||
617 | |||
618 | int altera_ci_stop_feed_1(struct dvb_demux_feed *feed) | ||
619 | { | ||
620 | return altera_ci_stop_feed(feed, 1); | ||
621 | } | ||
622 | |||
623 | int altera_ci_start_feed_2(struct dvb_demux_feed *feed) | ||
624 | { | ||
625 | return altera_ci_start_feed(feed, 2); | ||
626 | } | ||
627 | |||
628 | int altera_ci_stop_feed_2(struct dvb_demux_feed *feed) | ||
629 | { | ||
630 | return altera_ci_stop_feed(feed, 2); | ||
631 | } | ||
632 | |||
633 | int altera_hw_filt_init(struct altera_ci_config *config, int hw_filt_nr) | ||
634 | { | ||
635 | struct netup_hw_pid_filter *pid_filt = NULL; | ||
636 | struct fpga_inode *temp_int = find_inode(config->dev); | ||
637 | struct fpga_internal *inter = NULL; | ||
638 | int ret = 0; | ||
639 | |||
640 | pid_filt = kzalloc(sizeof(struct netup_hw_pid_filter), GFP_KERNEL); | ||
641 | |||
642 | ci_dbg_print("%s\n", __func__); | ||
643 | |||
644 | if (!pid_filt) { | ||
645 | ret = -ENOMEM; | ||
646 | goto err; | ||
647 | } | ||
648 | |||
649 | if (temp_int != NULL) { | ||
650 | inter = temp_int->internal; | ||
651 | (inter->filts_used)++; | ||
652 | ci_dbg_print("%s: Find Internal Structure!\n", __func__); | ||
653 | } else { | ||
654 | inter = kzalloc(sizeof(struct fpga_internal), GFP_KERNEL); | ||
655 | if (!inter) { | ||
656 | ret = -ENOMEM; | ||
657 | goto err; | ||
658 | } | ||
659 | |||
660 | temp_int = append_internal(inter); | ||
661 | inter->filts_used = 1; | ||
662 | inter->dev = config->dev; | ||
663 | inter->fpga_rw = config->fpga_rw; | ||
664 | mutex_init(&inter->fpga_mutex); | ||
665 | inter->strt_wrk = 1; | ||
666 | ci_dbg_print("%s: Create New Internal Structure!\n", __func__); | ||
667 | } | ||
668 | |||
669 | ci_dbg_print("%s: setting hw pid filter = 0x%x for ci = %d\n", __func__, | ||
670 | (int)pid_filt, hw_filt_nr - 1); | ||
671 | inter->pid_filt[hw_filt_nr - 1] = pid_filt; | ||
672 | pid_filt->demux = config->demux; | ||
673 | pid_filt->internal = inter; | ||
674 | pid_filt->nr = hw_filt_nr - 1; | ||
675 | /* store old feed controls */ | ||
676 | pid_filt->start_feed = config->demux->start_feed; | ||
677 | pid_filt->stop_feed = config->demux->stop_feed; | ||
678 | /* replace with new feed controls */ | ||
679 | if (hw_filt_nr == 1) { | ||
680 | pid_filt->demux->start_feed = altera_ci_start_feed_1; | ||
681 | pid_filt->demux->stop_feed = altera_ci_stop_feed_1; | ||
682 | } else if (hw_filt_nr == 2) { | ||
683 | pid_filt->demux->start_feed = altera_ci_start_feed_2; | ||
684 | pid_filt->demux->stop_feed = altera_ci_stop_feed_2; | ||
685 | } | ||
686 | |||
687 | altera_toggle_fullts_streaming(pid_filt, 0, 1); | ||
688 | |||
689 | return 0; | ||
690 | err: | ||
691 | ci_dbg_print("%s: Can't init hardware filter: Error %d\n", | ||
692 | __func__, ret); | ||
693 | |||
694 | kfree(pid_filt); | ||
695 | |||
696 | return ret; | ||
697 | } | ||
698 | EXPORT_SYMBOL(altera_hw_filt_init); | ||
699 | |||
700 | int altera_ci_init(struct altera_ci_config *config, int ci_nr) | ||
701 | { | ||
702 | struct altera_ci_state *state; | ||
703 | struct fpga_inode *temp_int = find_inode(config->dev); | ||
704 | struct fpga_internal *inter = NULL; | ||
705 | int ret = 0; | ||
706 | u8 store = 0; | ||
707 | |||
708 | state = kzalloc(sizeof(struct altera_ci_state), GFP_KERNEL); | ||
709 | |||
710 | ci_dbg_print("%s\n", __func__); | ||
711 | |||
712 | if (!state) { | ||
713 | ret = -ENOMEM; | ||
714 | goto err; | ||
715 | } | ||
716 | |||
717 | if (temp_int != NULL) { | ||
718 | inter = temp_int->internal; | ||
719 | (inter->cis_used)++; | ||
720 | ci_dbg_print("%s: Find Internal Structure!\n", __func__); | ||
721 | } else { | ||
722 | inter = kzalloc(sizeof(struct fpga_internal), GFP_KERNEL); | ||
723 | if (!inter) { | ||
724 | ret = -ENOMEM; | ||
725 | goto err; | ||
726 | } | ||
727 | |||
728 | temp_int = append_internal(inter); | ||
729 | inter->cis_used = 1; | ||
730 | inter->dev = config->dev; | ||
731 | inter->fpga_rw = config->fpga_rw; | ||
732 | mutex_init(&inter->fpga_mutex); | ||
733 | inter->strt_wrk = 1; | ||
734 | ci_dbg_print("%s: Create New Internal Structure!\n", __func__); | ||
735 | } | ||
736 | |||
737 | ci_dbg_print("%s: setting state = 0x%x for ci = %d\n", __func__, | ||
738 | (int)state, ci_nr - 1); | ||
739 | inter->state[ci_nr - 1] = state; | ||
740 | state->internal = inter; | ||
741 | state->nr = ci_nr - 1; | ||
742 | |||
743 | state->ca.owner = THIS_MODULE; | ||
744 | state->ca.read_attribute_mem = altera_ci_read_attribute_mem; | ||
745 | state->ca.write_attribute_mem = altera_ci_write_attribute_mem; | ||
746 | state->ca.read_cam_control = altera_ci_read_cam_ctl; | ||
747 | state->ca.write_cam_control = altera_ci_write_cam_ctl; | ||
748 | state->ca.slot_reset = altera_ci_slot_reset; | ||
749 | state->ca.slot_shutdown = altera_ci_slot_shutdown; | ||
750 | state->ca.slot_ts_enable = altera_ci_slot_ts_ctl; | ||
751 | state->ca.poll_slot_status = altera_poll_ci_slot_status; | ||
752 | state->ca.data = state; | ||
753 | |||
754 | ret = dvb_ca_en50221_init(config->adapter, | ||
755 | &state->ca, | ||
756 | /* flags */ 0, | ||
757 | /* n_slots */ 1); | ||
758 | if (0 != ret) | ||
759 | goto err; | ||
760 | |||
761 | altera_hw_filt_init(config, ci_nr); | ||
762 | |||
763 | if (inter->strt_wrk) { | ||
764 | INIT_WORK(&inter->work, netup_read_ci_status); | ||
765 | inter->strt_wrk = 0; | ||
766 | } | ||
767 | |||
768 | ci_dbg_print("%s: CI initialized!\n", __func__); | ||
769 | |||
770 | mutex_lock(&inter->fpga_mutex); | ||
771 | |||
772 | /* Enable div */ | ||
773 | netup_fpga_op_rw(inter, NETUP_CI_TSA_DIV, 0x0, 0); | ||
774 | netup_fpga_op_rw(inter, NETUP_CI_TSB_DIV, 0x0, 0); | ||
775 | |||
776 | /* enable TS out */ | ||
777 | store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, 0, NETUP_CI_FLG_RD); | ||
778 | store |= (3 << 4); | ||
779 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); | ||
780 | |||
781 | ret = netup_fpga_op_rw(inter, NETUP_CI_REVISION, 0, NETUP_CI_FLG_RD); | ||
782 | /* enable irq */ | ||
783 | netup_fpga_op_rw(inter, NETUP_CI_INT_CTRL, 0x44, 0); | ||
784 | |||
785 | mutex_unlock(&inter->fpga_mutex); | ||
786 | |||
787 | ci_dbg_print("%s: NetUP CI Revision = 0x%x\n", __func__, ret); | ||
788 | |||
789 | schedule_work(&inter->work); | ||
790 | |||
791 | return 0; | ||
792 | err: | ||
793 | ci_dbg_print("%s: Cannot initialize CI: Error %d.\n", __func__, ret); | ||
794 | |||
795 | kfree(state); | ||
796 | |||
797 | return ret; | ||
798 | } | ||
799 | EXPORT_SYMBOL(altera_ci_init); | ||
800 | |||
801 | int altera_ci_tuner_reset(void *dev, int ci_nr) | ||
802 | { | ||
803 | struct fpga_inode *temp_int = find_inode(dev); | ||
804 | struct fpga_internal *inter = NULL; | ||
805 | u8 store; | ||
806 | |||
807 | ci_dbg_print("%s\n", __func__); | ||
808 | |||
809 | if (temp_int == NULL) | ||
810 | return -1; | ||
811 | |||
812 | if (temp_int->internal == NULL) | ||
813 | return -1; | ||
814 | |||
815 | inter = temp_int->internal; | ||
816 | |||
817 | mutex_lock(&inter->fpga_mutex); | ||
818 | |||
819 | store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, 0, NETUP_CI_FLG_RD); | ||
820 | store &= ~(4 << (2 - ci_nr)); | ||
821 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); | ||
822 | msleep(100); | ||
823 | store |= (4 << (2 - ci_nr)); | ||
824 | netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); | ||
825 | |||
826 | mutex_unlock(&inter->fpga_mutex); | ||
827 | |||
828 | return 0; | ||
829 | } | ||
830 | EXPORT_SYMBOL(altera_ci_tuner_reset); | ||
diff --git a/drivers/media/video/cx23885/altera-ci.h b/drivers/media/video/cx23885/altera-ci.h new file mode 100644 index 000000000000..ba0c6c05082a --- /dev/null +++ b/drivers/media/video/cx23885/altera-ci.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * altera-ci.c | ||
3 | * | ||
4 | * CI driver in conjunction with NetUp Dual DVB-T/C RF CI card | ||
5 | * | ||
6 | * Copyright (C) 2010 NetUP Inc. | ||
7 | * Copyright (C) 2010 Igor M. Liplianin <liplianin@netup.ru> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
23 | */ | ||
24 | #ifndef __ALTERA_CI_H | ||
25 | #define __ALTERA_CI_H | ||
26 | |||
27 | #define ALT_DATA 0x000000ff | ||
28 | #define ALT_TDI 0x00008000 | ||
29 | #define ALT_TDO 0x00004000 | ||
30 | #define ALT_TCK 0x00002000 | ||
31 | #define ALT_RDY 0x00001000 | ||
32 | #define ALT_RD 0x00000800 | ||
33 | #define ALT_WR 0x00000400 | ||
34 | #define ALT_AD_RG 0x00000200 | ||
35 | #define ALT_CS 0x00000100 | ||
36 | |||
37 | struct altera_ci_config { | ||
38 | void *dev;/* main dev, for example cx23885_dev */ | ||
39 | void *adapter;/* for CI to connect to */ | ||
40 | struct dvb_demux *demux;/* for hardware PID filter to connect to */ | ||
41 | int (*fpga_rw) (void *dev, int ad_rg, int val, int rw); | ||
42 | }; | ||
43 | |||
44 | #if defined(CONFIG_MEDIA_ALTERA_CI) || (defined(CONFIG_MEDIA_ALTERA_CI_MODULE) \ | ||
45 | && defined(MODULE)) | ||
46 | |||
47 | extern int altera_ci_init(struct altera_ci_config *config, int ci_nr); | ||
48 | extern void altera_ci_release(void *dev, int ci_nr); | ||
49 | extern int altera_ci_irq(void *dev); | ||
50 | extern int altera_ci_tuner_reset(void *dev, int ci_nr); | ||
51 | |||
52 | #else | ||
53 | |||
54 | static inline int altera_ci_init(struct altera_ci_config *config, int ci_nr) | ||
55 | { | ||
56 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static inline void altera_ci_release(void *dev, int ci_nr) | ||
61 | { | ||
62 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static inline int altera_ci_irq(void *dev) | ||
67 | { | ||
68 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int altera_ci_tuner_reset(void *dev, int ci_nr) | ||
73 | { | ||
74 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | #endif | ||
79 | #if 0 | ||
80 | static inline int altera_hw_filt_init(struct altera_ci_config *config, | ||
81 | int hw_filt_nr) | ||
82 | { | ||
83 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static inline void altera_hw_filt_release(void *dev, int filt_nr) | ||
88 | { | ||
89 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static inline int altera_pid_feed_control(void *dev, int filt_nr, | ||
94 | struct dvb_demux_feed *dvbdmxfeed, int onoff) | ||
95 | { | ||
96 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | #endif /* CONFIG_MEDIA_ALTERA_CI */ | ||
101 | |||
102 | #endif /* __ALTERA_CI_H */ | ||