214ae5ee31ec7b1993ba12a0283f61c8d95ef772
[firefly-linux-kernel-4.4.55.git] / drivers / media / dvb / mantis / mantis_evm.c
1 /*
2         Mantis PCI bridge driver
3
4         Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6         This program is free software; you can redistribute it and/or modify
7         it under the terms of the GNU General Public License as published by
8         the Free Software Foundation; either version 2 of the License, or
9         (at your option) any later version.
10
11         This program is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14         GNU General Public License for more details.
15
16         You should have received a copy of the GNU General Public License
17         along with this program; if not, write to the Free Software
18         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "mantis_common.h"
22 #include "mantis_link.h"
23 #include "mantis_hif.h"
24
25 static void mantis_hifevm_work(struct work_struct *work)
26 {
27         struct mantis_ca *ca = container_of(work, struct mantis_ca, hif_evm_work);
28         struct mantis_pci *mantis = ca->ca_priv;
29
30         u32 gpif_stat, gpif_mask;
31
32         gpif_stat = mmread(MANTIS_GPIF_STATUS);
33         gpif_mask = mmread(MANTIS_GPIF_IRQCFG);
34
35         if (gpif_stat & MANTIS_GPIF_DETSTAT) {
36                 if (gpif_stat & MANTIS_CARD_PLUGIN) {
37                         dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Plugin", mantis->num);
38                         mmwrite(0xdada0000, MANTIS_CARD_RESET);
39                         mantis_event_cam_plugin(ca);
40                         dvb_ca_en50221_camchange_irq(&ca->en50221,
41                                                      0,
42                                                      DVB_CA_EN50221_CAMCHANGE_INSERTED);
43                 }
44         } else {
45                 if (gpif_stat & MANTIS_CARD_PLUGOUT) {
46                         dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Unplug", mantis->num);
47                         mmwrite(0xdada0000, MANTIS_CARD_RESET);
48                         mantis_event_cam_unplug(ca);
49                         dvb_ca_en50221_camchange_irq(&ca->en50221,
50                                                      0,
51                                                      DVB_CA_EN50221_CAMCHANGE_REMOVED);
52                 }
53         }
54
55         if (gpif_stat & MANTIS_GPIF_EXTIRQ)
56                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Ext IRQ", mantis->num);
57
58         if (gpif_stat & MANTIS_SBUF_WSTO)
59                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout", mantis->num);
60
61         if (gpif_stat & MANTIS_GPIF_OTHERR)
62                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Alignment Error", mantis->num);
63
64         if (gpif_stat & MANTIS_SBUF_OVFLW)
65                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Overflow", mantis->num);
66
67         if (gpif_stat & MANTIS_GPIF_BRRDY) {
68                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Read Ready", mantis->num);
69         }
70         if (gpif_stat & MANTIS_GPIF_WRACK)
71                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Slave Write ACK", mantis->num);
72
73         if (gpif_stat & MANTIS_GPIF_INTSTAT)
74                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): GPIF IRQ", mantis->num);
75
76         if (gpif_stat & MANTIS_SBUF_EMPTY)
77                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty", mantis->num);
78
79         if (gpif_stat & MANTIS_SBUF_OPDONE) {
80                 dprintk(verbose, MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete", mantis->num);
81                 ca->sbuf_status = MANTIS_SBUF_DATA_AVAIL;
82                 dvb_ca_en50221_frda_irq(&ca->en50221, 0);
83         }
84 }
85
86 int mantis_evmgr_init(struct mantis_ca *ca)
87 {
88         struct mantis_pci *mantis = ca->ca_priv;
89
90         dprintk(verbose, MANTIS_DEBUG, 1, "Initializing Mantis Host I/F Event manager");
91         INIT_WORK(&ca->hif_evm_work, mantis_hifevm_work);
92         mantis_pcmcia_init(ca);
93         schedule_work(&ca->hif_evm_work);
94         mantis_hif_init(ca);
95         return 0;
96 }
97
98 void mantis_evmgr_exit(struct mantis_ca *ca)
99 {
100         struct mantis_pci *mantis = ca->ca_priv;
101
102         dprintk(verbose, MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting");
103         flush_scheduled_work();
104         mantis_hif_exit(ca);
105         mantis_pcmcia_exit(ca);
106 }