xref: /openbmc/linux/drivers/media/pci/mantis/mantis_pcmcia.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*74ba9207SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
225aee3deSMauro Carvalho Chehab /*
325aee3deSMauro Carvalho Chehab 	Mantis PCI bridge driver
425aee3deSMauro Carvalho Chehab 
525aee3deSMauro Carvalho Chehab 	Copyright (C) Manu Abraham (abraham.manu@gmail.com)
625aee3deSMauro Carvalho Chehab 
725aee3deSMauro Carvalho Chehab */
825aee3deSMauro Carvalho Chehab 
925aee3deSMauro Carvalho Chehab #include <linux/kernel.h>
1025aee3deSMauro Carvalho Chehab 
1125aee3deSMauro Carvalho Chehab #include <linux/signal.h>
1225aee3deSMauro Carvalho Chehab #include <linux/sched.h>
1325aee3deSMauro Carvalho Chehab #include <linux/interrupt.h>
1425aee3deSMauro Carvalho Chehab #include <asm/io.h>
1525aee3deSMauro Carvalho Chehab 
16fada1935SMauro Carvalho Chehab #include <media/dmxdev.h>
17fada1935SMauro Carvalho Chehab #include <media/dvbdev.h>
18fada1935SMauro Carvalho Chehab #include <media/dvb_demux.h>
19fada1935SMauro Carvalho Chehab #include <media/dvb_frontend.h>
20fada1935SMauro Carvalho Chehab #include <media/dvb_net.h>
2125aee3deSMauro Carvalho Chehab 
2225aee3deSMauro Carvalho Chehab #include "mantis_common.h"
2325aee3deSMauro Carvalho Chehab #include "mantis_link.h" /* temporary due to physical layer stuff */
2425aee3deSMauro Carvalho Chehab #include "mantis_reg.h"
2525aee3deSMauro Carvalho Chehab 
2625aee3deSMauro Carvalho Chehab /*
2725aee3deSMauro Carvalho Chehab  * If Slot state is already PLUG_IN event and we are called
2825aee3deSMauro Carvalho Chehab  * again, definitely it is jitter alone
2925aee3deSMauro Carvalho Chehab  */
mantis_event_cam_plugin(struct mantis_ca * ca)3025aee3deSMauro Carvalho Chehab void mantis_event_cam_plugin(struct mantis_ca *ca)
3125aee3deSMauro Carvalho Chehab {
3225aee3deSMauro Carvalho Chehab 	struct mantis_pci *mantis = ca->ca_priv;
3325aee3deSMauro Carvalho Chehab 
3425aee3deSMauro Carvalho Chehab 	u32 gpif_irqcfg;
3525aee3deSMauro Carvalho Chehab 
3625aee3deSMauro Carvalho Chehab 	if (ca->slot_state == MODULE_XTRACTED) {
3725aee3deSMauro Carvalho Chehab 		dprintk(MANTIS_DEBUG, 1, "Event: CAM Plugged IN: Adapter(%d) Slot(0)", mantis->num);
3825aee3deSMauro Carvalho Chehab 		udelay(50);
3925aee3deSMauro Carvalho Chehab 		mmwrite(0xda000000, MANTIS_CARD_RESET);
4025aee3deSMauro Carvalho Chehab 		gpif_irqcfg  = mmread(MANTIS_GPIF_IRQCFG);
4125aee3deSMauro Carvalho Chehab 		gpif_irqcfg |= MANTIS_MASK_PLUGOUT;
4225aee3deSMauro Carvalho Chehab 		gpif_irqcfg &= ~MANTIS_MASK_PLUGIN;
4325aee3deSMauro Carvalho Chehab 		mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
4425aee3deSMauro Carvalho Chehab 		udelay(500);
4525aee3deSMauro Carvalho Chehab 		ca->slot_state = MODULE_INSERTED;
4625aee3deSMauro Carvalho Chehab 	}
4725aee3deSMauro Carvalho Chehab 	udelay(100);
4825aee3deSMauro Carvalho Chehab }
4925aee3deSMauro Carvalho Chehab 
5025aee3deSMauro Carvalho Chehab /*
5125aee3deSMauro Carvalho Chehab  * If Slot state is already UN_PLUG event and we are called
5225aee3deSMauro Carvalho Chehab  * again, definitely it is jitter alone
5325aee3deSMauro Carvalho Chehab  */
mantis_event_cam_unplug(struct mantis_ca * ca)5425aee3deSMauro Carvalho Chehab void mantis_event_cam_unplug(struct mantis_ca *ca)
5525aee3deSMauro Carvalho Chehab {
5625aee3deSMauro Carvalho Chehab 	struct mantis_pci *mantis = ca->ca_priv;
5725aee3deSMauro Carvalho Chehab 
5825aee3deSMauro Carvalho Chehab 	u32 gpif_irqcfg;
5925aee3deSMauro Carvalho Chehab 
6025aee3deSMauro Carvalho Chehab 	if (ca->slot_state == MODULE_INSERTED) {
6125aee3deSMauro Carvalho Chehab 		dprintk(MANTIS_DEBUG, 1, "Event: CAM Unplugged: Adapter(%d) Slot(0)", mantis->num);
6225aee3deSMauro Carvalho Chehab 		udelay(50);
6325aee3deSMauro Carvalho Chehab 		mmwrite(0x00da0000, MANTIS_CARD_RESET);
6425aee3deSMauro Carvalho Chehab 		gpif_irqcfg  = mmread(MANTIS_GPIF_IRQCFG);
6525aee3deSMauro Carvalho Chehab 		gpif_irqcfg |= MANTIS_MASK_PLUGIN;
6625aee3deSMauro Carvalho Chehab 		gpif_irqcfg &= ~MANTIS_MASK_PLUGOUT;
6725aee3deSMauro Carvalho Chehab 		mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
6825aee3deSMauro Carvalho Chehab 		udelay(500);
6925aee3deSMauro Carvalho Chehab 		ca->slot_state = MODULE_XTRACTED;
7025aee3deSMauro Carvalho Chehab 	}
7125aee3deSMauro Carvalho Chehab 	udelay(100);
7225aee3deSMauro Carvalho Chehab }
7325aee3deSMauro Carvalho Chehab 
mantis_pcmcia_init(struct mantis_ca * ca)7425aee3deSMauro Carvalho Chehab int mantis_pcmcia_init(struct mantis_ca *ca)
7525aee3deSMauro Carvalho Chehab {
7625aee3deSMauro Carvalho Chehab 	struct mantis_pci *mantis = ca->ca_priv;
7725aee3deSMauro Carvalho Chehab 
7825aee3deSMauro Carvalho Chehab 	u32 gpif_stat, card_stat;
7925aee3deSMauro Carvalho Chehab 
80a96762daSJan Klötzke 	mantis_unmask_ints(mantis, MANTIS_INT_IRQ0);
8125aee3deSMauro Carvalho Chehab 	gpif_stat = mmread(MANTIS_GPIF_STATUS);
8225aee3deSMauro Carvalho Chehab 	card_stat = mmread(MANTIS_GPIF_IRQCFG);
8325aee3deSMauro Carvalho Chehab 
8425aee3deSMauro Carvalho Chehab 	if (gpif_stat & MANTIS_GPIF_DETSTAT) {
8525aee3deSMauro Carvalho Chehab 		dprintk(MANTIS_DEBUG, 1, "CAM found on Adapter(%d) Slot(0)", mantis->num);
8625aee3deSMauro Carvalho Chehab 		mmwrite(card_stat | MANTIS_MASK_PLUGOUT, MANTIS_GPIF_IRQCFG);
8725aee3deSMauro Carvalho Chehab 		ca->slot_state = MODULE_INSERTED;
8825aee3deSMauro Carvalho Chehab 		dvb_ca_en50221_camchange_irq(&ca->en50221,
8925aee3deSMauro Carvalho Chehab 					     0,
9025aee3deSMauro Carvalho Chehab 					     DVB_CA_EN50221_CAMCHANGE_INSERTED);
9125aee3deSMauro Carvalho Chehab 	} else {
9225aee3deSMauro Carvalho Chehab 		dprintk(MANTIS_DEBUG, 1, "Empty Slot on Adapter(%d) Slot(0)", mantis->num);
9325aee3deSMauro Carvalho Chehab 		mmwrite(card_stat | MANTIS_MASK_PLUGIN, MANTIS_GPIF_IRQCFG);
9425aee3deSMauro Carvalho Chehab 		ca->slot_state = MODULE_XTRACTED;
9525aee3deSMauro Carvalho Chehab 		dvb_ca_en50221_camchange_irq(&ca->en50221,
9625aee3deSMauro Carvalho Chehab 					     0,
9725aee3deSMauro Carvalho Chehab 					     DVB_CA_EN50221_CAMCHANGE_REMOVED);
9825aee3deSMauro Carvalho Chehab 	}
9925aee3deSMauro Carvalho Chehab 
10025aee3deSMauro Carvalho Chehab 	return 0;
10125aee3deSMauro Carvalho Chehab }
10225aee3deSMauro Carvalho Chehab 
mantis_pcmcia_exit(struct mantis_ca * ca)10325aee3deSMauro Carvalho Chehab void mantis_pcmcia_exit(struct mantis_ca *ca)
10425aee3deSMauro Carvalho Chehab {
10525aee3deSMauro Carvalho Chehab 	struct mantis_pci *mantis = ca->ca_priv;
10625aee3deSMauro Carvalho Chehab 
10725aee3deSMauro Carvalho Chehab 	mmwrite(mmread(MANTIS_GPIF_STATUS) & (~MANTIS_CARD_PLUGOUT | ~MANTIS_CARD_PLUGIN), MANTIS_GPIF_STATUS);
108a96762daSJan Klötzke 	mantis_mask_ints(mantis, MANTIS_INT_IRQ0);
10925aee3deSMauro Carvalho Chehab }
110