Merge branch 'bcache-for-upstream' of git://evilpiepirate.org/~kent/linux-bcache...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / pci / mantis / mantis_evm.c
CommitLineData
d575571e
MA
1/*
2 Mantis PCI bridge driver
3
8825a097 4 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
d575571e
MA
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
b3b96144
MA
21#include <linux/kernel.h>
22
b3b96144
MA
23#include <linux/signal.h>
24#include <linux/sched.h>
25#include <linux/interrupt.h>
b7f080cf 26#include <asm/io.h>
b3b96144
MA
27
28#include "dmxdev.h"
29#include "dvbdev.h"
30#include "dvb_demux.h"
31#include "dvb_frontend.h"
32#include "dvb_net.h"
33
d575571e
MA
34#include "mantis_common.h"
35#include "mantis_link.h"
fadfa070 36#include "mantis_hif.h"
b3b96144 37#include "mantis_reg.h"
fadfa070 38
12855cac 39static void mantis_hifevm_work(struct work_struct *work)
fadfa070 40{
12855cac 41 struct mantis_ca *ca = container_of(work, struct mantis_ca, hif_evm_work);
fadfa070
MA
42 struct mantis_pci *mantis = ca->ca_priv;
43
5becbc58 44 u32 gpif_stat;
fadfa070
MA
45
46 gpif_stat = mmread(MANTIS_GPIF_STATUS);
47
48 if (gpif_stat & MANTIS_GPIF_DETSTAT) {
49 if (gpif_stat & MANTIS_CARD_PLUGIN) {
b3b96144 50 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Plugin", mantis->num);
fadfa070 51 mmwrite(0xdada0000, MANTIS_CARD_RESET);
12855cac 52 mantis_event_cam_plugin(ca);
05691cdb
MA
53 dvb_ca_en50221_camchange_irq(&ca->en50221,
54 0,
55 DVB_CA_EN50221_CAMCHANGE_INSERTED);
fadfa070
MA
56 }
57 } else {
58 if (gpif_stat & MANTIS_CARD_PLUGOUT) {
b3b96144 59 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): CAM Unplug", mantis->num);
fadfa070 60 mmwrite(0xdada0000, MANTIS_CARD_RESET);
12855cac 61 mantis_event_cam_unplug(ca);
05691cdb
MA
62 dvb_ca_en50221_camchange_irq(&ca->en50221,
63 0,
64 DVB_CA_EN50221_CAMCHANGE_REMOVED);
fadfa070
MA
65 }
66 }
67
17b77fc2 68 if (mantis->gpif_status & MANTIS_GPIF_EXTIRQ)
b3b96144 69 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Ext IRQ", mantis->num);
fadfa070 70
17b77fc2 71 if (mantis->gpif_status & MANTIS_SBUF_WSTO)
b3b96144 72 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout", mantis->num);
fadfa070 73
17b77fc2 74 if (mantis->gpif_status & MANTIS_GPIF_OTHERR)
b3b96144 75 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Alignment Error", mantis->num);
fadfa070
MA
76
77 if (gpif_stat & MANTIS_SBUF_OVFLW)
b3b96144 78 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Overflow", mantis->num);
fadfa070 79
9e49e8d9 80 if (gpif_stat & MANTIS_GPIF_BRRDY)
b3b96144 81 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Read Ready", mantis->num);
9e49e8d9 82
fadfa070 83 if (gpif_stat & MANTIS_GPIF_INTSTAT)
b3b96144 84 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): GPIF IRQ", mantis->num);
fadfa070
MA
85
86 if (gpif_stat & MANTIS_SBUF_EMPTY)
b3b96144 87 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty", mantis->num);
fadfa070
MA
88
89 if (gpif_stat & MANTIS_SBUF_OPDONE) {
b3b96144 90 dprintk(MANTIS_DEBUG, 1, "Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete", mantis->num);
cc0e4aac 91 ca->sbuf_status = MANTIS_SBUF_DATA_AVAIL;
c02e1515
SA
92 ca->hif_event = MANTIS_SBUF_OPDONE;
93 wake_up(&ca->hif_opdone_wq);
fadfa070
MA
94 }
95}
d575571e
MA
96
97int mantis_evmgr_init(struct mantis_ca *ca)
98{
99 struct mantis_pci *mantis = ca->ca_priv;
100
b3b96144 101 dprintk(MANTIS_DEBUG, 1, "Initializing Mantis Host I/F Event manager");
12855cac 102 INIT_WORK(&ca->hif_evm_work, mantis_hifevm_work);
50d82602 103 mantis_pcmcia_init(ca);
12855cac 104 schedule_work(&ca->hif_evm_work);
d8b14f8a 105 mantis_hif_init(ca);
d575571e
MA
106 return 0;
107}
108
109void mantis_evmgr_exit(struct mantis_ca *ca)
110{
111 struct mantis_pci *mantis = ca->ca_priv;
112
b3b96144 113 dprintk(MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting");
43829731 114 flush_work(&ca->hif_evm_work);
d8b14f8a 115 mantis_hif_exit(ca);
50d82602 116 mantis_pcmcia_exit(ca);
d575571e 117}