2 Mantis PCI bridge driver
4 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
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.
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.
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.
21 #include <linux/kernel.h>
22 #include <linux/signal.h>
23 #include <linux/sched.h>
25 #include <linux/signal.h>
26 #include <linux/sched.h>
27 #include <linux/interrupt.h>
31 #include "dvb_demux.h"
32 #include "dvb_frontend.h"
35 #include "mantis_common.h"
37 #include "mantis_hif.h"
38 #include "mantis_link.h" /* temporary due to physical layer stuff */
40 #include "mantis_reg.h"
43 static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
45 struct mantis_pci *mantis = ca->ca_priv;
48 if (wait_event_timeout(ca->hif_opdone_wq,
49 ca->hif_event & MANTIS_SBUF_OPDONE,
50 msecs_to_jiffies(500)) == -ERESTARTSYS) {
52 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
55 dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
56 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
60 static int mantis_hif_write_wait(struct mantis_ca *ca)
62 struct mantis_pci *mantis = ca->ca_priv;
63 u32 opdone = 0, timeout = 0;
66 if (wait_event_timeout(ca->hif_write_wq,
67 mantis->gpif_status & MANTIS_GPIF_WRACK,
68 msecs_to_jiffies(500)) == -ERESTARTSYS) {
70 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);
73 dprintk(MANTIS_DEBUG, 1, "Write Acknowledged");
74 mantis->gpif_status &= ~MANTIS_GPIF_WRACK;
76 opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE);
80 dprintk(MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num);
85 dprintk(MANTIS_DEBUG, 1, "HIF Write success");
90 int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
92 struct mantis_pci *mantis = ca->ca_priv;
93 u32 hif_addr = 0, data, count = 4;
95 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
96 mutex_lock(&ca->ca_lock);
97 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
98 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
99 hif_addr |= MANTIS_HIF_STATUS;
102 mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
103 mmwrite(count, MANTIS_GPIF_BRBYTES);
105 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
107 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
108 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
109 mutex_unlock(&ca->ca_lock);
112 data = mmread(MANTIS_GPIF_DIN);
113 mutex_unlock(&ca->ca_lock);
114 dprintk(MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);
115 return (data >> 24) & 0xff;
118 int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
120 struct mantis_slot *slot = ca->slot;
121 struct mantis_pci *mantis = ca->ca_priv;
124 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
125 mutex_lock(&ca->ca_lock);
126 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
127 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
128 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
129 hif_addr |= MANTIS_HIF_STATUS;
132 mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
133 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
134 mmwrite(data, MANTIS_GPIF_DOUT);
136 if (mantis_hif_write_wait(ca) != 0) {
137 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
138 mutex_unlock(&ca->ca_lock);
141 dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
142 mutex_unlock(&ca->ca_lock);
147 int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
149 struct mantis_pci *mantis = ca->ca_priv;
150 u32 data, hif_addr = 0;
152 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
153 mutex_lock(&ca->ca_lock);
154 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
155 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
156 hif_addr |= MANTIS_HIF_STATUS;
159 mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
160 mmwrite(1, MANTIS_GPIF_BRBYTES);
162 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
164 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
165 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
166 mutex_unlock(&ca->ca_lock);
169 data = mmread(MANTIS_GPIF_DIN);
170 dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
172 mutex_unlock(&ca->ca_lock);
177 int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
179 struct mantis_pci *mantis = ca->ca_priv;
182 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
183 mutex_lock(&ca->ca_lock);
184 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
185 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
186 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
187 hif_addr |= MANTIS_HIF_STATUS;
190 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
191 mmwrite(data, MANTIS_GPIF_DOUT);
193 if (mantis_hif_write_wait(ca) != 0) {
194 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
195 mutex_unlock(&ca->ca_lock);
198 dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
199 mutex_unlock(&ca->ca_lock);
205 int mantis_hif_init(struct mantis_ca *ca)
207 struct mantis_slot *slot = ca->slot;
208 struct mantis_pci *mantis = ca->ca_priv;
211 slot[0].slave_cfg = 0x70773028;
212 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
214 mutex_lock(&ca->ca_lock);
215 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
216 irqcfg = MANTIS_MASK_BRRDY |
223 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
224 mutex_unlock(&ca->ca_lock);
229 void mantis_hif_exit(struct mantis_ca *ca)
231 struct mantis_pci *mantis = ca->ca_priv;
234 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
235 mutex_lock(&ca->ca_lock);
236 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
237 irqcfg &= ~MANTIS_MASK_BRRDY;
238 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
239 mutex_unlock(&ca->ca_lock);