blob: 2f188c089666c1988817b7ef35065a1d210cba90 [file] [log] [blame]
Manu Abrahambc4ed422009-12-04 05:03:35 -03001/*
2 Mantis PCI bridge driver
3
Manu Abraham8825a092009-12-15 09:13:49 -03004 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
Manu Abrahambc4ed422009-12-04 05:03:35 -03005
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
Manu Abrahamb3b96142009-12-04 05:41:11 -030021#include <linux/kernel.h>
22
Manu Abrahamb3b96142009-12-04 05:41:11 -030023#include <linux/signal.h>
24#include <linux/sched.h>
25#include <linux/interrupt.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000026#include <asm/io.h>
Manu Abrahamb3b96142009-12-04 05:41:11 -030027
28#include "dmxdev.h"
29#include "dvbdev.h"
30#include "dvb_demux.h"
31#include "dvb_frontend.h"
32#include "dvb_net.h"
33
Manu Abrahambc4ed422009-12-04 05:03:35 -030034#include "mantis_common.h"
Manu Abraham8ce571f2009-12-04 05:06:00 -030035#include "mantis_link.h" /* temporary due to physical layer stuff */
Manu Abrahamb3b96142009-12-04 05:41:11 -030036#include "mantis_reg.h"
Manu Abraham8ce571f2009-12-04 05:06:00 -030037
38/*
39 * If Slot state is already PLUG_IN event and we are called
40 * again, definitely it is jitter alone
41 */
42void mantis_event_cam_plugin(struct mantis_ca *ca)
43{
44 struct mantis_pci *mantis = ca->ca_priv;
45
46 u32 gpif_irqcfg;
47
48 if (ca->slot_state == MODULE_XTRACTED) {
Manu Abrahamb3b96142009-12-04 05:41:11 -030049 dprintk(MANTIS_DEBUG, 1, "Event: CAM Plugged IN: Adapter(%d) Slot(0)", mantis->num);
Manu Abraham8ce571f2009-12-04 05:06:00 -030050 udelay(50);
51 mmwrite(0xda000000, MANTIS_CARD_RESET);
52 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG);
53 gpif_irqcfg |= MANTIS_MASK_PLUGOUT;
54 gpif_irqcfg &= ~MANTIS_MASK_PLUGIN;
55 mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
56 udelay(500);
57 ca->slot_state = MODULE_INSERTED;
58 }
59 udelay(100);
60}
61
62/*
63 * If Slot state is already UN_PLUG event and we are called
64 * again, definitely it is jitter alone
65 */
66void mantis_event_cam_unplug(struct mantis_ca *ca)
67{
68 struct mantis_pci *mantis = ca->ca_priv;
69
70 u32 gpif_irqcfg;
71
72 if (ca->slot_state == MODULE_INSERTED) {
Manu Abrahamb3b96142009-12-04 05:41:11 -030073 dprintk(MANTIS_DEBUG, 1, "Event: CAM Unplugged: Adapter(%d) Slot(0)", mantis->num);
Manu Abraham8ce571f2009-12-04 05:06:00 -030074 udelay(50);
75 mmwrite(0x00da0000, MANTIS_CARD_RESET);
76 gpif_irqcfg = mmread(MANTIS_GPIF_IRQCFG);
77 gpif_irqcfg |= MANTIS_MASK_PLUGIN;
78 gpif_irqcfg &= ~MANTIS_MASK_PLUGOUT;
79 mmwrite(gpif_irqcfg, MANTIS_GPIF_IRQCFG);
80 udelay(500);
81 ca->slot_state = MODULE_XTRACTED;
82 }
83 udelay(100);
84}
Manu Abrahambc4ed422009-12-04 05:03:35 -030085
86int mantis_pcmcia_init(struct mantis_ca *ca)
87{
88 struct mantis_pci *mantis = ca->ca_priv;
89
Manu Abraham8ce571f2009-12-04 05:06:00 -030090 u32 gpif_stat, card_stat;
91
Manu Abrahamd9dd5f72009-12-04 05:07:41 -030092 mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_IRQ0, MANTIS_INT_MASK);
Manu Abraham8ce571f2009-12-04 05:06:00 -030093 gpif_stat = mmread(MANTIS_GPIF_STATUS);
94 card_stat = mmread(MANTIS_GPIF_IRQCFG);
95
96 if (gpif_stat & MANTIS_GPIF_DETSTAT) {
Manu Abrahamb3b96142009-12-04 05:41:11 -030097 dprintk(MANTIS_DEBUG, 1, "CAM found on Adapter(%d) Slot(0)", mantis->num);
Manu Abraham8ce571f2009-12-04 05:06:00 -030098 mmwrite(card_stat | MANTIS_MASK_PLUGOUT, MANTIS_GPIF_IRQCFG);
99 ca->slot_state = MODULE_INSERTED;
Sigmund Augdal86c75c52009-12-04 05:21:27 -0300100 dvb_ca_en50221_camchange_irq(&ca->en50221,
101 0,
102 DVB_CA_EN50221_CAMCHANGE_INSERTED);
Manu Abraham8ce571f2009-12-04 05:06:00 -0300103 } else {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300104 dprintk(MANTIS_DEBUG, 1, "Empty Slot on Adapter(%d) Slot(0)", mantis->num);
Manu Abraham8ce571f2009-12-04 05:06:00 -0300105 mmwrite(card_stat | MANTIS_MASK_PLUGIN, MANTIS_GPIF_IRQCFG);
106 ca->slot_state = MODULE_XTRACTED;
Manu Abraham88a6fa92009-12-04 05:22:33 -0300107 dvb_ca_en50221_camchange_irq(&ca->en50221,
108 0,
109 DVB_CA_EN50221_CAMCHANGE_REMOVED);
Manu Abraham8ce571f2009-12-04 05:06:00 -0300110 }
111
Manu Abrahambc4ed422009-12-04 05:03:35 -0300112 return 0;
113}
114
115void mantis_pcmcia_exit(struct mantis_ca *ca)
116{
117 struct mantis_pci *mantis = ca->ca_priv;
118
Manu Abraham8ce571f2009-12-04 05:06:00 -0300119 mmwrite(mmread(MANTIS_GPIF_STATUS) & (~MANTIS_CARD_PLUGOUT | ~MANTIS_CARD_PLUGIN), MANTIS_GPIF_STATUS);
120 mmwrite(mmread(MANTIS_INT_MASK) & ~MANTIS_INT_IRQ0, MANTIS_INT_MASK);
Manu Abrahambc4ed422009-12-04 05:03:35 -0300121}