xref: /linux/drivers/media/pci/mantis/mantis_pcmcia.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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" /* temporary due to physical layer stuff */
24 #include "mantis_reg.h"
25 
26 /*
27  * If Slot state is already PLUG_IN event and we are called
28  * again, definitely it is jitter alone
29  */
30 void mantis_event_cam_plugin(struct mantis_ca *ca)
31 {
32 	struct mantis_pci *mantis = ca->ca_priv;
33 
34 	u32 gpif_irqcfg;
35 
36 	if (ca->slot_state == MODULE_XTRACTED) {
37 		dprintk(MANTIS_DEBUG, 1, "Event: CAM Plugged IN: Adapter(%d) Slot(0)", mantis->num);
38 		udelay(50);
39 		mmwrite(0xda000000, MANTIS_CARD_RESET);
40 		gpif_irqcfg  = mmread(MANTIS_GPIF_IRQCFG);
41 		gpif_irqcfg |= MANTIS_MASK_PLUGOUT;
42 		gpif_irqcfg &= ~MANTIS_MASK_PLUGIN;
43 		mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
44 		udelay(500);
45 		ca->slot_state = MODULE_INSERTED;
46 	}
47 	udelay(100);
48 }
49 
50 /*
51  * If Slot state is already UN_PLUG event and we are called
52  * again, definitely it is jitter alone
53  */
54 void mantis_event_cam_unplug(struct mantis_ca *ca)
55 {
56 	struct mantis_pci *mantis = ca->ca_priv;
57 
58 	u32 gpif_irqcfg;
59 
60 	if (ca->slot_state == MODULE_INSERTED) {
61 		dprintk(MANTIS_DEBUG, 1, "Event: CAM Unplugged: Adapter(%d) Slot(0)", mantis->num);
62 		udelay(50);
63 		mmwrite(0x00da0000, MANTIS_CARD_RESET);
64 		gpif_irqcfg  = mmread(MANTIS_GPIF_IRQCFG);
65 		gpif_irqcfg |= MANTIS_MASK_PLUGIN;
66 		gpif_irqcfg &= ~MANTIS_MASK_PLUGOUT;
67 		mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
68 		udelay(500);
69 		ca->slot_state = MODULE_XTRACTED;
70 	}
71 	udelay(100);
72 }
73 
74 int mantis_pcmcia_init(struct mantis_ca *ca)
75 {
76 	struct mantis_pci *mantis = ca->ca_priv;
77 
78 	u32 gpif_stat, card_stat;
79 
80 	mantis_unmask_ints(mantis, MANTIS_INT_IRQ0);
81 	gpif_stat = mmread(MANTIS_GPIF_STATUS);
82 	card_stat = mmread(MANTIS_GPIF_IRQCFG);
83 
84 	if (gpif_stat & MANTIS_GPIF_DETSTAT) {
85 		dprintk(MANTIS_DEBUG, 1, "CAM found on Adapter(%d) Slot(0)", mantis->num);
86 		mmwrite(card_stat | MANTIS_MASK_PLUGOUT, MANTIS_GPIF_IRQCFG);
87 		ca->slot_state = MODULE_INSERTED;
88 		dvb_ca_en50221_camchange_irq(&ca->en50221,
89 					     0,
90 					     DVB_CA_EN50221_CAMCHANGE_INSERTED);
91 	} else {
92 		dprintk(MANTIS_DEBUG, 1, "Empty Slot on Adapter(%d) Slot(0)", mantis->num);
93 		mmwrite(card_stat | MANTIS_MASK_PLUGIN, MANTIS_GPIF_IRQCFG);
94 		ca->slot_state = MODULE_XTRACTED;
95 		dvb_ca_en50221_camchange_irq(&ca->en50221,
96 					     0,
97 					     DVB_CA_EN50221_CAMCHANGE_REMOVED);
98 	}
99 
100 	return 0;
101 }
102 
103 void mantis_pcmcia_exit(struct mantis_ca *ca)
104 {
105 	struct mantis_pci *mantis = ca->ca_priv;
106 
107 	mmwrite(mmread(MANTIS_GPIF_STATUS) & (~MANTIS_CARD_PLUGOUT | ~MANTIS_CARD_PLUGIN), MANTIS_GPIF_STATUS);
108 	mantis_mask_ints(mantis, MANTIS_INT_IRQ0);
109 }
110