1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 	Mantis PCI bridge driver
4 
5 	Copyright (C) Manu Abraham (abraham.manu@gmail.com)
6 
7 */
8 
9 #include <linux/kernel.h>
10 
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/interrupt.h>
14 #include <asm/io.h>
15 
16 #include <media/dmxdev.h>
17 #include <media/dvbdev.h>
18 #include <media/dvb_demux.h>
19 #include <media/dvb_frontend.h>
20 #include <media/dvb_net.h>
21 
22 #include "mantis_common.h"
23 #include "mantis_link.h"
24 #include "mantis_hif.h"
25 #include "mantis_reg.h"
26 
mantis_hifevm_work(struct work_struct * work)27 static void mantis_hifevm_work(struct work_struct *work)
28 {
29 	struct mantis_ca *ca = container_of(work, struct mantis_ca, hif_evm_work);
30 	struct mantis_pci *mantis = ca->ca_priv;
31 
32 	u32 gpif_stat;
33 
34 	gpif_stat = mmread(MANTIS_GPIF_STATUS);
35 
36 	if (gpif_stat & MANTIS_GPIF_DETSTAT) {
37 		if (gpif_stat & MANTIS_CARD_PLUGIN) {
38 			dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Plugin", mantis->num);
39 			mmwrite(0xdada0000, MANTIS_CARD_RESET);
40 			mantis_event_cam_plugin(ca);
41 			dvb_ca_en50221_camchange_irq(&ca->en50221,
42 						     0,
43 						     DVB_CA_EN50221_CAMCHANGE_INSERTED);
44 		}
45 	} else {
46 		if (gpif_stat & MANTIS_CARD_PLUGOUT) {
47 			dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Unplug", mantis->num);
48 			mmwrite(0xdada0000, MANTIS_CARD_RESET);
49 			mantis_event_cam_unplug(ca);
50 			dvb_ca_en50221_camchange_irq(&ca->en50221,
51 						     0,
52 						     DVB_CA_EN50221_CAMCHANGE_REMOVED);
53 		}
54 	}
55 
56 	if (mantis->gpif_status & MANTIS_GPIF_EXTIRQ)
57 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Ext IRQ", mantis->num);
58 
59 	if (mantis->gpif_status & MANTIS_SBUF_WSTO)
60 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout", mantis->num);
61 
62 	if (mantis->gpif_status & MANTIS_GPIF_OTHERR)
63 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Alignment Error", mantis->num);
64 
65 	if (gpif_stat & MANTIS_SBUF_OVFLW)
66 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Overflow", mantis->num);
67 
68 	if (gpif_stat & MANTIS_GPIF_BRRDY)
69 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Read Ready", mantis->num);
70 
71 	if (gpif_stat & MANTIS_GPIF_INTSTAT)
72 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): GPIF IRQ", mantis->num);
73 
74 	if (gpif_stat & MANTIS_SBUF_EMPTY)
75 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty", mantis->num);
76 
77 	if (gpif_stat & MANTIS_SBUF_OPDONE) {
78 		dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete", mantis->num);
79 		ca->sbuf_status = MANTIS_SBUF_DATA_AVAIL;
80 		ca->hif_event = MANTIS_SBUF_OPDONE;
81 		wake_up(&ca->hif_opdone_wq);
82 	}
83 }
84 
mantis_evmgr_init(struct mantis_ca * ca)85 int mantis_evmgr_init(struct mantis_ca *ca)
86 {
87 	struct mantis_pci *mantis = ca->ca_priv;
88 
89 	dprintk(MANTIS_DEBUG, 1, "Initializing Mantis Host I/F Event manager");
90 	INIT_WORK(&ca->hif_evm_work, mantis_hifevm_work);
91 	mantis_pcmcia_init(ca);
92 	schedule_work(&ca->hif_evm_work);
93 	mantis_hif_init(ca);
94 	return 0;
95 }
96 
mantis_evmgr_exit(struct mantis_ca * ca)97 void mantis_evmgr_exit(struct mantis_ca *ca)
98 {
99 	struct mantis_pci *mantis = ca->ca_priv;
100 
101 	dprintk(MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting");
102 	flush_work(&ca->hif_evm_work);
103 	mantis_hif_exit(ca);
104 	mantis_pcmcia_exit(ca);
105 }
106