1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Mantis PCI bridge driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/kernel.h>
10 #include <linux/signal.h>
11 #include <linux/sched.h>
13 #include <linux/interrupt.h>
16 #include <media/dmxdev.h>
17 #include <media/dvbdev.h>
18 #include <media/dvb_demux.h>
19 #include <media/dvb_frontend.h>
20 #include <media/dvb_net.h>
22 #include "mantis_common.h"
24 #include "mantis_hif.h"
25 #include "mantis_link.h" /* temporary due to physical layer stuff */
27 #include "mantis_reg.h"
30 static int mantis_hif_sbuf_opdone_wait(struct mantis_ca
*ca
)
32 struct mantis_pci
*mantis
= ca
->ca_priv
;
35 if (wait_event_timeout(ca
->hif_opdone_wq
,
36 ca
->hif_event
& MANTIS_SBUF_OPDONE
,
37 msecs_to_jiffies(500)) == -ERESTARTSYS
) {
39 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis
->num
);
42 dprintk(MANTIS_DEBUG
, 1, "Smart Buffer Operation complete");
43 ca
->hif_event
&= ~MANTIS_SBUF_OPDONE
;
47 static int mantis_hif_write_wait(struct mantis_ca
*ca
)
49 struct mantis_pci
*mantis
= ca
->ca_priv
;
50 u32 opdone
= 0, timeout
= 0;
53 if (wait_event_timeout(ca
->hif_write_wq
,
54 mantis
->gpif_status
& MANTIS_GPIF_WRACK
,
55 msecs_to_jiffies(500)) == -ERESTARTSYS
) {
57 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis
->num
);
60 dprintk(MANTIS_DEBUG
, 1, "Write Acknowledged");
61 mantis
->gpif_status
&= ~MANTIS_GPIF_WRACK
;
63 opdone
= (mmread(MANTIS_GPIF_STATUS
) & MANTIS_SBUF_OPDONE
);
67 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): Write operation timed out!", mantis
->num
);
72 dprintk(MANTIS_DEBUG
, 1, "HIF Write success");
77 int mantis_hif_read_mem(struct mantis_ca
*ca
, u32 addr
)
79 struct mantis_pci
*mantis
= ca
->ca_priv
;
80 u32 hif_addr
= 0, data
, count
= 4;
82 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis
->num
);
83 mutex_lock(&ca
->ca_lock
);
84 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
85 hif_addr
&= ~MANTIS_GPIF_PCMCIAIOM
;
86 hif_addr
|= MANTIS_HIF_STATUS
;
89 mmwrite(hif_addr
, MANTIS_GPIF_BRADDR
);
90 mmwrite(count
, MANTIS_GPIF_BRBYTES
);
92 mmwrite(hif_addr
| MANTIS_GPIF_HIFRDWRN
, MANTIS_GPIF_ADDR
);
94 if (mantis_hif_sbuf_opdone_wait(ca
) != 0) {
95 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis
->num
);
96 mutex_unlock(&ca
->ca_lock
);
99 data
= mmread(MANTIS_GPIF_DIN
);
100 mutex_unlock(&ca
->ca_lock
);
101 dprintk(MANTIS_DEBUG
, 1, "Mem Read: 0x%02x", data
);
102 return (data
>> 24) & 0xff;
105 int mantis_hif_write_mem(struct mantis_ca
*ca
, u32 addr
, u8 data
)
107 struct mantis_slot
*slot
= ca
->slot
;
108 struct mantis_pci
*mantis
= ca
->ca_priv
;
111 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis
->num
);
112 mutex_lock(&ca
->ca_lock
);
113 hif_addr
&= ~MANTIS_GPIF_HIFRDWRN
;
114 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
115 hif_addr
&= ~MANTIS_GPIF_PCMCIAIOM
;
116 hif_addr
|= MANTIS_HIF_STATUS
;
119 mmwrite(slot
->slave_cfg
, MANTIS_GPIF_CFGSLA
); /* Slot0 alone for now */
120 mmwrite(hif_addr
, MANTIS_GPIF_ADDR
);
121 mmwrite(data
, MANTIS_GPIF_DOUT
);
123 if (mantis_hif_write_wait(ca
) != 0) {
124 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
125 mutex_unlock(&ca
->ca_lock
);
128 dprintk(MANTIS_DEBUG
, 1, "Mem Write: (0x%02x to 0x%02x)", data
, addr
);
129 mutex_unlock(&ca
->ca_lock
);
134 int mantis_hif_read_iom(struct mantis_ca
*ca
, u32 addr
)
136 struct mantis_pci
*mantis
= ca
->ca_priv
;
137 u32 data
, hif_addr
= 0;
139 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis
->num
);
140 mutex_lock(&ca
->ca_lock
);
141 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
142 hif_addr
|= MANTIS_GPIF_PCMCIAIOM
;
143 hif_addr
|= MANTIS_HIF_STATUS
;
146 mmwrite(hif_addr
, MANTIS_GPIF_BRADDR
);
147 mmwrite(1, MANTIS_GPIF_BRBYTES
);
149 mmwrite(hif_addr
| MANTIS_GPIF_HIFRDWRN
, MANTIS_GPIF_ADDR
);
151 if (mantis_hif_sbuf_opdone_wait(ca
) != 0) {
152 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
153 mutex_unlock(&ca
->ca_lock
);
156 data
= mmread(MANTIS_GPIF_DIN
);
157 dprintk(MANTIS_DEBUG
, 1, "I/O Read: 0x%02x", data
);
159 mutex_unlock(&ca
->ca_lock
);
164 int mantis_hif_write_iom(struct mantis_ca
*ca
, u32 addr
, u8 data
)
166 struct mantis_pci
*mantis
= ca
->ca_priv
;
169 dprintk(MANTIS_DEBUG
, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis
->num
);
170 mutex_lock(&ca
->ca_lock
);
171 hif_addr
&= ~MANTIS_GPIF_PCMCIAREG
;
172 hif_addr
&= ~MANTIS_GPIF_HIFRDWRN
;
173 hif_addr
|= MANTIS_GPIF_PCMCIAIOM
;
174 hif_addr
|= MANTIS_HIF_STATUS
;
177 mmwrite(hif_addr
, MANTIS_GPIF_ADDR
);
178 mmwrite(data
, MANTIS_GPIF_DOUT
);
180 if (mantis_hif_write_wait(ca
) != 0) {
181 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis
->num
);
182 mutex_unlock(&ca
->ca_lock
);
185 dprintk(MANTIS_DEBUG
, 1, "I/O Write: (0x%02x to 0x%02x)", data
, addr
);
186 mutex_unlock(&ca
->ca_lock
);
192 int mantis_hif_init(struct mantis_ca
*ca
)
194 struct mantis_slot
*slot
= ca
->slot
;
195 struct mantis_pci
*mantis
= ca
->ca_priv
;
198 slot
[0].slave_cfg
= 0x70773028;
199 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis
->num
);
201 mutex_lock(&ca
->ca_lock
);
202 irqcfg
= mmread(MANTIS_GPIF_IRQCFG
);
203 irqcfg
= MANTIS_MASK_BRRDY
|
210 mmwrite(irqcfg
, MANTIS_GPIF_IRQCFG
);
211 mutex_unlock(&ca
->ca_lock
);
216 void mantis_hif_exit(struct mantis_ca
*ca
)
218 struct mantis_pci
*mantis
= ca
->ca_priv
;
221 dprintk(MANTIS_ERROR
, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis
->num
);
222 mutex_lock(&ca
->ca_lock
);
223 irqcfg
= mmread(MANTIS_GPIF_IRQCFG
);
224 irqcfg
&= ~MANTIS_MASK_BRRDY
;
225 mmwrite(irqcfg
, MANTIS_GPIF_IRQCFG
);
226 mutex_unlock(&ca
->ca_lock
);