Lines Matching +full:inter +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * altera-ci.c
5 * CI driver in conjunction with NetUp Dual DVB-T/C RF CI card
13 * GPIO-0 ~INT in
14 * GPIO-1 TMS out
15 * GPIO-2 ~reset chips out
16 * GPIO-3 to GPIO-10 data/addr for CA in/out
17 * GPIO-11 ~CS out
18 * GPIO-12 AD_RG out
19 * GPIO-13 ~WR out
20 * GPIO-14 ~RD out
21 * GPIO-15 ~RDY in
22 * GPIO-16 TCK out
23 * GPIO-17 TDO in
24 * GPIO-18 TDI out
28 * bits 31-16
29 * +-----------+
31 * +-----------+
33 * +-------+-------+-------+-------+-------+-------+-------+-------+
35 * +-------+-------+-------+-------+-------+-------+-------+-------+
37 * +-------+-------+-------+-------+-------+-------+-------+-------+
39 * +-------+-------+-------+-------+-------+-------+-------+-------+
46 #include "altera-ci.h"
103 int (*fpga_rw) (void *dev, int flag, int data, int rw);
151 (temp_chip->internal->dev != dev)) in find_inode()
152 temp_chip = temp_chip->next_inode; in find_inode()
163 if ((temp_int->pid_filt[filt_nr]) == NULL) in check_filter()
166 if (temp_int->pid_filt[filt_nr]->demux == demux_dev) in check_filter()
183 if (temp_chip->internal != NULL) { in find_dinode()
184 temp_int = temp_chip->internal; in find_dinode()
191 temp_chip = temp_chip->next_inode; in find_dinode()
201 struct fpga_inode *del_node = find_inode(internal->dev); in remove_inode()
205 fpga_first_inode = del_node->next_inode; in remove_inode()
207 while (prev_node->next_inode != del_node) in remove_inode()
208 prev_node = prev_node->next_inode; in remove_inode()
210 if (del_node->next_inode == NULL) in remove_inode()
211 prev_node->next_inode = NULL; in remove_inode()
213 prev_node->next_inode = in remove_inode()
214 prev_node->next_inode->next_inode; in remove_inode()
230 while (new_node->next_inode != NULL) in append_internal()
231 new_node = new_node->next_inode; in append_internal()
233 new_node->next_inode = in append_internal()
235 if (new_node->next_inode != NULL) in append_internal()
236 new_node = new_node->next_inode; in append_internal()
242 new_node->internal = internal; in append_internal()
243 new_node->next_inode = NULL; in append_internal()
249 static int netup_fpga_op_rw(struct fpga_internal *inter, int addr, in netup_fpga_op_rw() argument
252 inter->fpga_rw(inter->dev, NETUP_CI_FLG_AD, addr, 0); in netup_fpga_op_rw()
253 return inter->fpga_rw(inter->dev, 0, val, read); in netup_fpga_op_rw()
256 /* flag - mem/io, read - read/write */
261 struct altera_ci_state *state = en50221->data; in altera_ci_op_cam()
262 struct fpga_internal *inter = state->internal; in altera_ci_op_cam() local
268 return -EINVAL; in altera_ci_op_cam()
270 mutex_lock(&inter->fpga_mutex); in altera_ci_op_cam()
272 netup_fpga_op_rw(inter, NETUP_CI_ADDR0, ((addr << 1) & 0xfe), 0); in altera_ci_op_cam()
273 netup_fpga_op_rw(inter, NETUP_CI_ADDR1, ((addr >> 7) & 0x7f), 0); in altera_ci_op_cam()
274 store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); in altera_ci_op_cam()
277 store |= ((state->nr << 7) | (flag << 6)); in altera_ci_op_cam()
279 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, store, 0); in altera_ci_op_cam()
280 mem = netup_fpga_op_rw(inter, NETUP_CI_DATA, val, read); in altera_ci_op_cam()
282 mutex_unlock(&inter->fpga_mutex); in altera_ci_op_cam()
299 int slot, int addr, u8 data) in altera_ci_write_attribute_mem() argument
301 return altera_ci_op_cam(en50221, slot, 0, 0, addr, data); in altera_ci_write_attribute_mem()
312 u8 addr, u8 data) in altera_ci_write_cam_ctl() argument
314 return altera_ci_op_cam(en50221, slot, NETUP_CI_FLG_CTL, 0, addr, data); in altera_ci_write_cam_ctl()
319 struct altera_ci_state *state = en50221->data; in altera_ci_slot_reset()
320 struct fpga_internal *inter = state->internal; in altera_ci_slot_reset() local
328 return -EINVAL; in altera_ci_slot_reset()
330 mutex_lock(&inter->fpga_mutex); in altera_ci_slot_reset()
332 ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); in altera_ci_slot_reset()
333 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, in altera_ci_slot_reset()
334 (ret & 0xcf) | (1 << (5 - state->nr)), 0); in altera_ci_slot_reset()
336 mutex_unlock(&inter->fpga_mutex); in altera_ci_slot_reset()
341 mutex_lock(&inter->fpga_mutex); in altera_ci_slot_reset()
343 ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, in altera_ci_slot_reset()
345 mutex_unlock(&inter->fpga_mutex); in altera_ci_slot_reset()
347 if ((ret & (1 << (5 - state->nr))) == 0) in altera_ci_slot_reset()
355 jiffies_to_msecs(jiffies + msecs_to_jiffies(9999) - t_out)); in altera_ci_slot_reset()
368 struct altera_ci_state *state = en50221->data; in altera_ci_slot_ts_ctl()
369 struct fpga_internal *inter = state->internal; in altera_ci_slot_ts_ctl() local
375 return -EINVAL; in altera_ci_slot_ts_ctl()
377 mutex_lock(&inter->fpga_mutex); in altera_ci_slot_ts_ctl()
379 ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); in altera_ci_slot_ts_ctl()
380 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, in altera_ci_slot_ts_ctl()
381 (ret & 0x0f) | (1 << (3 - state->nr)), 0); in altera_ci_slot_ts_ctl()
383 mutex_unlock(&inter->fpga_mutex); in altera_ci_slot_ts_ctl()
391 struct fpga_internal *inter = in netup_read_ci_status() local
397 mutex_lock(&inter->fpga_mutex); in netup_read_ci_status()
399 ret = netup_fpga_op_rw(inter, NETUP_CI_INT_CTRL, 0, NETUP_CI_FLG_RD); in netup_read_ci_status()
400 ret = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL, 0, NETUP_CI_FLG_RD); in netup_read_ci_status()
402 mutex_unlock(&inter->fpga_mutex); in netup_read_ci_status()
404 if (inter->state[1] != NULL) { in netup_read_ci_status()
405 inter->state[1]->status = in netup_read_ci_status()
410 __func__, inter->state[1]->status); in netup_read_ci_status()
413 if (inter->state[0] != NULL) { in netup_read_ci_status()
414 inter->state[0]->status = in netup_read_ci_status()
419 __func__, inter->state[0]->status); in netup_read_ci_status()
427 struct fpga_internal *inter = NULL; in altera_ci_irq() local
434 inter = temp_int->internal; in altera_ci_irq()
435 schedule_work(&inter->work); in altera_ci_irq()
446 struct altera_ci_state *state = en50221->data; in altera_poll_ci_slot_status()
449 return -EINVAL; in altera_poll_ci_slot_status()
451 return state->status; in altera_poll_ci_slot_status()
462 pid_filt = temp_int->internal->pid_filt[filt_nr - 1]; in altera_hw_filt_release()
464 pid_filt->demux->start_feed = pid_filt->start_feed; in altera_hw_filt_release()
465 pid_filt->demux->stop_feed = pid_filt->stop_feed; in altera_hw_filt_release()
467 if (((--(temp_int->internal->filts_used)) <= 0) && in altera_hw_filt_release()
468 ((temp_int->internal->cis_used) <= 0)) { in altera_hw_filt_release()
472 remove_inode(temp_int->internal); in altera_hw_filt_release()
473 kfree(pid_filt->internal); in altera_hw_filt_release()
490 state = temp_int->internal->state[ci_nr - 1]; in altera_ci_release()
494 if (((temp_int->internal->filts_used) <= 0) && in altera_ci_release()
495 ((--(temp_int->internal->cis_used)) <= 0)) { in altera_ci_release()
499 remove_inode(temp_int->internal); in altera_ci_release()
500 kfree(state->internal); in altera_ci_release()
504 if (state->ca.data != NULL) in altera_ci_release()
505 dvb_ca_en50221_release(&state->ca); in altera_ci_release()
517 struct fpga_internal *inter = pid_filt->internal; in altera_pid_control() local
520 /* pid 0-0x1f always enabled, don't touch them */ in altera_pid_control()
524 mutex_lock(&inter->fpga_mutex); in altera_pid_control()
526 netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR0, (pid >> 3) & 0xff, 0); in altera_pid_control()
527 netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR1, in altera_pid_control()
528 ((pid >> 11) & 0x03) | (pid_filt->nr << 2), 0); in altera_pid_control()
530 store = netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, 0, NETUP_CI_FLG_RD); in altera_pid_control()
532 if (onoff)/* 0 - on, 1 - off */ in altera_pid_control()
537 netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, store, 0); in altera_pid_control()
539 mutex_unlock(&inter->fpga_mutex); in altera_pid_control()
542 pid_filt->nr, pid, pid, onoff ? "off" : "on"); in altera_pid_control()
548 struct fpga_internal *inter = pid_filt->internal; in altera_toggle_fullts_streaming() local
552 pid_dbg_print("%s: pid_filt->nr[%d] now %s\n", __func__, pid_filt->nr, in altera_toggle_fullts_streaming()
555 if (onoff)/* 0 - on, 1 - off */ in altera_toggle_fullts_streaming()
560 mutex_lock(&inter->fpga_mutex); in altera_toggle_fullts_streaming()
563 netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR0, i & 0xff, 0); in altera_toggle_fullts_streaming()
565 netup_fpga_op_rw(inter, NETUP_CI_PID_ADDR1, in altera_toggle_fullts_streaming()
566 ((i >> 8) & 0x03) | (pid_filt->nr << 2), 0); in altera_toggle_fullts_streaming()
567 /* pid 0-0x1f always enabled */ in altera_toggle_fullts_streaming()
568 netup_fpga_op_rw(inter, NETUP_CI_PID_DATA, in altera_toggle_fullts_streaming()
572 mutex_unlock(&inter->fpga_mutex); in altera_toggle_fullts_streaming()
579 struct fpga_internal *inter = temp_int->internal; in altera_pid_feed_control() local
580 struct netup_hw_pid_filter *pid_filt = inter->pid_filt[filt_nr - 1]; in altera_pid_feed_control()
582 altera_pid_control(pid_filt, feed->pid, onoff ? 0 : 1); in altera_pid_feed_control()
585 pid_filt->start_feed(feed); in altera_pid_feed_control()
587 pid_filt->stop_feed(feed); in altera_pid_feed_control()
589 if (feed->pid == 0x2000) in altera_pid_feed_control()
598 altera_pid_feed_control(feed->demux, num, feed, 1); in altera_ci_start_feed()
605 altera_pid_feed_control(feed->demux, num, feed, 0); in altera_ci_stop_feed()
633 struct fpga_inode *temp_int = find_inode(config->dev); in altera_hw_filt_init()
634 struct fpga_internal *inter = NULL; in altera_hw_filt_init() local
642 ret = -ENOMEM; in altera_hw_filt_init()
647 inter = temp_int->internal; in altera_hw_filt_init()
648 (inter->filts_used)++; in altera_hw_filt_init()
651 inter = kzalloc(sizeof(struct fpga_internal), GFP_KERNEL); in altera_hw_filt_init()
652 if (!inter) { in altera_hw_filt_init()
653 ret = -ENOMEM; in altera_hw_filt_init()
657 temp_int = append_internal(inter); in altera_hw_filt_init()
659 ret = -ENOMEM; in altera_hw_filt_init()
662 inter->filts_used = 1; in altera_hw_filt_init()
663 inter->dev = config->dev; in altera_hw_filt_init()
664 inter->fpga_rw = config->fpga_rw; in altera_hw_filt_init()
665 mutex_init(&inter->fpga_mutex); in altera_hw_filt_init()
666 inter->strt_wrk = 1; in altera_hw_filt_init()
671 pid_filt, hw_filt_nr - 1); in altera_hw_filt_init()
672 inter->pid_filt[hw_filt_nr - 1] = pid_filt; in altera_hw_filt_init()
673 pid_filt->demux = config->demux; in altera_hw_filt_init()
674 pid_filt->internal = inter; in altera_hw_filt_init()
675 pid_filt->nr = hw_filt_nr - 1; in altera_hw_filt_init()
677 pid_filt->start_feed = config->demux->start_feed; in altera_hw_filt_init()
678 pid_filt->stop_feed = config->demux->stop_feed; in altera_hw_filt_init()
681 pid_filt->demux->start_feed = altera_ci_start_feed_1; in altera_hw_filt_init()
682 pid_filt->demux->stop_feed = altera_ci_stop_feed_1; in altera_hw_filt_init()
684 pid_filt->demux->start_feed = altera_ci_start_feed_2; in altera_hw_filt_init()
685 pid_filt->demux->stop_feed = altera_ci_stop_feed_2; in altera_hw_filt_init()
696 kfree(inter); in altera_hw_filt_init()
704 struct fpga_inode *temp_int = find_inode(config->dev); in altera_ci_init()
705 struct fpga_internal *inter = NULL; in altera_ci_init() local
714 ret = -ENOMEM; in altera_ci_init()
719 inter = temp_int->internal; in altera_ci_init()
720 (inter->cis_used)++; in altera_ci_init()
721 inter->fpga_rw = config->fpga_rw; in altera_ci_init()
724 inter = kzalloc(sizeof(struct fpga_internal), GFP_KERNEL); in altera_ci_init()
725 if (!inter) { in altera_ci_init()
726 ret = -ENOMEM; in altera_ci_init()
730 temp_int = append_internal(inter); in altera_ci_init()
732 ret = -ENOMEM; in altera_ci_init()
735 inter->cis_used = 1; in altera_ci_init()
736 inter->dev = config->dev; in altera_ci_init()
737 inter->fpga_rw = config->fpga_rw; in altera_ci_init()
738 mutex_init(&inter->fpga_mutex); in altera_ci_init()
739 inter->strt_wrk = 1; in altera_ci_init()
744 state, ci_nr - 1); in altera_ci_init()
745 state->internal = inter; in altera_ci_init()
746 state->nr = ci_nr - 1; in altera_ci_init()
748 state->ca.owner = THIS_MODULE; in altera_ci_init()
749 state->ca.read_attribute_mem = altera_ci_read_attribute_mem; in altera_ci_init()
750 state->ca.write_attribute_mem = altera_ci_write_attribute_mem; in altera_ci_init()
751 state->ca.read_cam_control = altera_ci_read_cam_ctl; in altera_ci_init()
752 state->ca.write_cam_control = altera_ci_write_cam_ctl; in altera_ci_init()
753 state->ca.slot_reset = altera_ci_slot_reset; in altera_ci_init()
754 state->ca.slot_shutdown = altera_ci_slot_shutdown; in altera_ci_init()
755 state->ca.slot_ts_enable = altera_ci_slot_ts_ctl; in altera_ci_init()
756 state->ca.poll_slot_status = altera_poll_ci_slot_status; in altera_ci_init()
757 state->ca.data = state; in altera_ci_init()
759 ret = dvb_ca_en50221_init(config->adapter, in altera_ci_init()
760 &state->ca, in altera_ci_init()
766 inter->state[ci_nr - 1] = state; in altera_ci_init()
770 if (inter->strt_wrk) { in altera_ci_init()
771 INIT_WORK(&inter->work, netup_read_ci_status); in altera_ci_init()
772 inter->strt_wrk = 0; in altera_ci_init()
777 mutex_lock(&inter->fpga_mutex); in altera_ci_init()
780 netup_fpga_op_rw(inter, NETUP_CI_TSA_DIV, 0x0, 0); in altera_ci_init()
781 netup_fpga_op_rw(inter, NETUP_CI_TSB_DIV, 0x0, 0); in altera_ci_init()
784 store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, 0, NETUP_CI_FLG_RD); in altera_ci_init()
786 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); in altera_ci_init()
788 ret = netup_fpga_op_rw(inter, NETUP_CI_REVISION, 0, NETUP_CI_FLG_RD); in altera_ci_init()
790 netup_fpga_op_rw(inter, NETUP_CI_INT_CTRL, 0x44, 0); in altera_ci_init()
792 mutex_unlock(&inter->fpga_mutex); in altera_ci_init()
796 schedule_work(&inter->work); in altera_ci_init()
803 kfree(inter); in altera_ci_init()
812 struct fpga_internal *inter = NULL; in altera_ci_tuner_reset() local
818 return -1; in altera_ci_tuner_reset()
820 if (temp_int->internal == NULL) in altera_ci_tuner_reset()
821 return -1; in altera_ci_tuner_reset()
823 inter = temp_int->internal; in altera_ci_tuner_reset()
825 mutex_lock(&inter->fpga_mutex); in altera_ci_tuner_reset()
827 store = netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, 0, NETUP_CI_FLG_RD); in altera_ci_tuner_reset()
828 store &= ~(4 << (2 - ci_nr)); in altera_ci_tuner_reset()
829 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); in altera_ci_tuner_reset()
831 store |= (4 << (2 - ci_nr)); in altera_ci_tuner_reset()
832 netup_fpga_op_rw(inter, NETUP_CI_BUSCTRL2, store, 0); in altera_ci_tuner_reset()
834 mutex_unlock(&inter->fpga_mutex); in altera_ci_tuner_reset()