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/interrupt.h>
28 #include <media/dmxdev.h>
29 #include <media/dvbdev.h>
30 #include <media/dvb_demux.h>
31 #include <media/dvb_frontend.h>
32 #include <media/dvb_net.h>
34 #include "mantis_common.h"
36 #include "mantis_hif.h"
37 #include "mantis_link.h" /* temporary due to physical layer stuff */
39 #include "mantis_reg.h"
42 static int mantis_hif_sbuf_opdone_wait(struct mantis_ca
*ca
)
44 struct mantis_pci
*mantis
= ca
->ca_priv
;
47 if (wait_event_timeout(ca
->hif_opdone_wq
,
48 ca
->hif_event
& MANTIS_SBUF_OPDONE
,
49 msecs_to_jiffies(500)) == -ERESTARTSYS
) {
51 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis
->num
);
54 dprintk(MANTIS_DEBUG
, 1, "Smart Buffer Operation complete");
55 ca
->hif_event
&= ~MANTIS_SBUF_OPDONE
;
59 static int mantis_hif_write_wait(struct mantis_ca
*ca
)
61 struct mantis_pci
*mantis
= ca
->ca_priv
;
62 u32 opdone
= 0, timeout
= 0;
65 if (wait_event_timeout(ca
->hif_write_wq
,
66 mantis
->gpif_status
& MANTIS_GPIF_WRACK
,
67 msecs_to_jiffies(500)) == -ERESTARTSYS
) {
69 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis
->num
);
72 dprintk(MANTIS_DEBUG
, 1, "Write Acknowledged");
73 mantis
->gpif_status
&= ~MANTIS_GPIF_WRACK
;
75 opdone
= (mmread(MANTIS_GPIF_STATUS
) & MANTIS_SBUF_OPDONE
);
79 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Write operation timed out!", mantis
->num
);
84 dprintk(MANTIS_DEBUG
, 1, "HIF Write success");
89 int mantis_hif_read_mem(struct mantis_ca
*ca
, u32 addr
)
91 struct mantis_pci
*mantis
= ca
->ca_priv
;
92 u32 hif_addr
= 0, data
, count
= 4;
94 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis
->num
);
95 mutex_lock(&ca
->ca_lock
);
96 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
97 hif_addr
&= ~MANTIS_GPIF_PCMCIAIOM
;
98 hif_addr
|= MANTIS_HIF_STATUS
;
101 mmwrite(hif_addr
, MANTIS_GPIF_BRADDR
);
102 mmwrite(count
, MANTIS_GPIF_BRBYTES
);
104 mmwrite(hif_addr
| MANTIS_GPIF_HIFRDWRN
, MANTIS_GPIF_ADDR
);
106 if (mantis_hif_sbuf_opdone_wait(ca
) != 0) {
107 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis
->num
);
108 mutex_unlock(&ca
->ca_lock
);
111 data
= mmread(MANTIS_GPIF_DIN
);
112 mutex_unlock(&ca
->ca_lock
);
113 dprintk(MANTIS_DEBUG
, 1, "Mem Read: 0x%02x", data
);
114 return (data
>> 24) & 0xff;
117 int mantis_hif_write_mem(struct mantis_ca
*ca
, u32 addr
, u8 data
)
119 struct mantis_slot
*slot
= ca
->slot
;
120 struct mantis_pci
*mantis
= ca
->ca_priv
;
123 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis
->num
);
124 mutex_lock(&ca
->ca_lock
);
125 hif_addr
&= ~MANTIS_GPIF_HIFRDWRN
;
126 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
127 hif_addr
&= ~MANTIS_GPIF_PCMCIAIOM
;
128 hif_addr
|= MANTIS_HIF_STATUS
;
131 mmwrite(slot
->slave_cfg
, MANTIS_GPIF_CFGSLA
); /* Slot0 alone for now */
132 mmwrite(hif_addr
, MANTIS_GPIF_ADDR
);
133 mmwrite(data
, MANTIS_GPIF_DOUT
);
135 if (mantis_hif_write_wait(ca
) != 0) {
136 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
137 mutex_unlock(&ca
->ca_lock
);
140 dprintk(MANTIS_DEBUG
, 1, "Mem Write: (0x%02x to 0x%02x)", data
, addr
);
141 mutex_unlock(&ca
->ca_lock
);
146 int mantis_hif_read_iom(struct mantis_ca
*ca
, u32 addr
)
148 struct mantis_pci
*mantis
= ca
->ca_priv
;
149 u32 data
, hif_addr
= 0;
151 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis
->num
);
152 mutex_lock(&ca
->ca_lock
);
153 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
154 hif_addr
|= MANTIS_GPIF_PCMCIAIOM
;
155 hif_addr
|= MANTIS_HIF_STATUS
;
158 mmwrite(hif_addr
, MANTIS_GPIF_BRADDR
);
159 mmwrite(1, MANTIS_GPIF_BRBYTES
);
161 mmwrite(hif_addr
| MANTIS_GPIF_HIFRDWRN
, MANTIS_GPIF_ADDR
);
163 if (mantis_hif_sbuf_opdone_wait(ca
) != 0) {
164 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
165 mutex_unlock(&ca
->ca_lock
);
168 data
= mmread(MANTIS_GPIF_DIN
);
169 dprintk(MANTIS_DEBUG
, 1, "I/O Read: 0x%02x", data
);
171 mutex_unlock(&ca
->ca_lock
);
176 int mantis_hif_write_iom(struct mantis_ca
*ca
, u32 addr
, u8 data
)
178 struct mantis_pci
*mantis
= ca
->ca_priv
;
181 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis
->num
);
182 mutex_lock(&ca
->ca_lock
);
183 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
184 hif_addr
&= ~MANTIS_GPIF_HIFRDWRN
;
185 hif_addr
|= MANTIS_GPIF_PCMCIAIOM
;
186 hif_addr
|= MANTIS_HIF_STATUS
;
189 mmwrite(hif_addr
, MANTIS_GPIF_ADDR
);
190 mmwrite(data
, MANTIS_GPIF_DOUT
);
192 if (mantis_hif_write_wait(ca
) != 0) {
193 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
194 mutex_unlock(&ca
->ca_lock
);
197 dprintk(MANTIS_DEBUG
, 1, "I/O Write: (0x%02x to 0x%02x)", data
, addr
);
198 mutex_unlock(&ca
->ca_lock
);
204 int mantis_hif_init(struct mantis_ca
*ca
)
206 struct mantis_slot
*slot
= ca
->slot
;
207 struct mantis_pci
*mantis
= ca
->ca_priv
;
210 slot
[0].slave_cfg
= 0x70773028;
211 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis
->num
);
213 mutex_lock(&ca
->ca_lock
);
214 irqcfg
= mmread(MANTIS_GPIF_IRQCFG
);
215 irqcfg
= MANTIS_MASK_BRRDY
|
222 mmwrite(irqcfg
, MANTIS_GPIF_IRQCFG
);
223 mutex_unlock(&ca
->ca_lock
);
228 void mantis_hif_exit(struct mantis_ca
*ca
)
230 struct mantis_pci
*mantis
= ca
->ca_priv
;
233 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis
->num
);
234 mutex_lock(&ca
->ca_lock
);
235 irqcfg
= mmread(MANTIS_GPIF_IRQCFG
);
236 irqcfg
&= ~MANTIS_MASK_BRRDY
;
237 mmwrite(irqcfg
, MANTIS_GPIF_IRQCFG
);
238 mutex_unlock(&ca
->ca_lock
);