diff options
Diffstat (limited to 'drivers/media/dvb/mantis/mantis_hif.c')
-rw-r--r-- | drivers/media/dvb/mantis/mantis_hif.c | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/drivers/media/dvb/mantis/mantis_hif.c b/drivers/media/dvb/mantis/mantis_hif.c new file mode 100644 index 000000000000..7477dac628b4 --- /dev/null +++ b/drivers/media/dvb/mantis/mantis_hif.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | Mantis PCI bridge driver | ||
3 | |||
4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) | ||
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 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/signal.h> | ||
23 | #include <linux/sched.h> | ||
24 | |||
25 | #include <linux/signal.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | |||
29 | #include "dmxdev.h" | ||
30 | #include "dvbdev.h" | ||
31 | #include "dvb_demux.h" | ||
32 | #include "dvb_frontend.h" | ||
33 | #include "dvb_net.h" | ||
34 | |||
35 | #include "mantis_common.h" | ||
36 | |||
37 | #include "mantis_hif.h" | ||
38 | #include "mantis_link.h" /* temporary due to physical layer stuff */ | ||
39 | |||
40 | #include "mantis_reg.h" | ||
41 | |||
42 | |||
43 | static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca) | ||
44 | { | ||
45 | struct mantis_pci *mantis = ca->ca_priv; | ||
46 | int rc = 0; | ||
47 | |||
48 | if (wait_event_timeout(ca->hif_opdone_wq, | ||
49 | ca->hif_event & MANTIS_SBUF_OPDONE, | ||
50 | msecs_to_jiffies(500)) == -ERESTARTSYS) { | ||
51 | |||
52 | dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num); | ||
53 | rc = -EREMOTEIO; | ||
54 | } | ||
55 | dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete"); | ||
56 | ca->hif_event &= ~MANTIS_SBUF_OPDONE; | ||
57 | return rc; | ||
58 | } | ||
59 | |||
60 | static int mantis_hif_write_wait(struct mantis_ca *ca) | ||
61 | { | ||
62 | struct mantis_pci *mantis = ca->ca_priv; | ||
63 | u32 opdone = 0, timeout = 0; | ||
64 | int rc = 0; | ||
65 | |||
66 | if (wait_event_timeout(ca->hif_write_wq, | ||
67 | mantis->gpif_status & MANTIS_GPIF_WRACK, | ||
68 | msecs_to_jiffies(500)) == -ERESTARTSYS) { | ||
69 | |||
70 | dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num); | ||
71 | rc = -EREMOTEIO; | ||
72 | } | ||
73 | dprintk(MANTIS_DEBUG, 1, "Write Acknowledged"); | ||
74 | mantis->gpif_status &= ~MANTIS_GPIF_WRACK; | ||
75 | while (!opdone) { | ||
76 | opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE); | ||
77 | udelay(500); | ||
78 | timeout++; | ||
79 | if (timeout > 100) { | ||
80 | dprintk(MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num); | ||
81 | rc = -ETIMEDOUT; | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | dprintk(MANTIS_DEBUG, 1, "HIF Write success"); | ||
86 | return rc; | ||
87 | } | ||
88 | |||
89 | |||
90 | int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr) | ||
91 | { | ||
92 | struct mantis_pci *mantis = ca->ca_priv; | ||
93 | u32 hif_addr = 0, data, count = 4; | ||
94 | |||
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; | ||
100 | hif_addr |= addr; | ||
101 | |||
102 | mmwrite(hif_addr, MANTIS_GPIF_BRADDR); | ||
103 | mmwrite(count, MANTIS_GPIF_BRBYTES); | ||
104 | udelay(20); | ||
105 | mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR); | ||
106 | |||
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); | ||
110 | return -EREMOTEIO; | ||
111 | } | ||
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; | ||
116 | } | ||
117 | |||
118 | int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data) | ||
119 | { | ||
120 | struct mantis_slot *slot = ca->slot; | ||
121 | struct mantis_pci *mantis = ca->ca_priv; | ||
122 | u32 hif_addr = 0; | ||
123 | |||
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; | ||
130 | hif_addr |= addr; | ||
131 | |||
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); | ||
135 | |||
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); | ||
139 | return -EREMOTEIO; | ||
140 | } | ||
141 | dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr); | ||
142 | mutex_unlock(&ca->ca_lock); | ||
143 | |||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr) | ||
148 | { | ||
149 | struct mantis_pci *mantis = ca->ca_priv; | ||
150 | u32 data, hif_addr = 0; | ||
151 | |||
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; | ||
157 | hif_addr |= addr; | ||
158 | |||
159 | mmwrite(hif_addr, MANTIS_GPIF_BRADDR); | ||
160 | mmwrite(1, MANTIS_GPIF_BRBYTES); | ||
161 | udelay(20); | ||
162 | mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR); | ||
163 | |||
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); | ||
167 | return -EREMOTEIO; | ||
168 | } | ||
169 | data = mmread(MANTIS_GPIF_DIN); | ||
170 | dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data); | ||
171 | udelay(50); | ||
172 | mutex_unlock(&ca->ca_lock); | ||
173 | |||
174 | return (u8) data; | ||
175 | } | ||
176 | |||
177 | int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data) | ||
178 | { | ||
179 | struct mantis_pci *mantis = ca->ca_priv; | ||
180 | u32 hif_addr = 0; | ||
181 | |||
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; | ||
188 | hif_addr |= addr; | ||
189 | |||
190 | mmwrite(hif_addr, MANTIS_GPIF_ADDR); | ||
191 | mmwrite(data, MANTIS_GPIF_DOUT); | ||
192 | |||
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); | ||
196 | return -EREMOTEIO; | ||
197 | } | ||
198 | dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr); | ||
199 | mutex_unlock(&ca->ca_lock); | ||
200 | udelay(50); | ||
201 | |||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | int mantis_hif_init(struct mantis_ca *ca) | ||
206 | { | ||
207 | struct mantis_slot *slot = ca->slot; | ||
208 | struct mantis_pci *mantis = ca->ca_priv; | ||
209 | u32 irqcfg; | ||
210 | |||
211 | slot[0].slave_cfg = 0x70773028; | ||
212 | dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num); | ||
213 | |||
214 | mutex_lock(&ca->ca_lock); | ||
215 | irqcfg = mmread(MANTIS_GPIF_IRQCFG); | ||
216 | irqcfg = MANTIS_MASK_BRRDY | | ||
217 | MANTIS_MASK_WRACK | | ||
218 | MANTIS_MASK_EXTIRQ | | ||
219 | MANTIS_MASK_WSTO | | ||
220 | MANTIS_MASK_OTHERR | | ||
221 | MANTIS_MASK_OVFLW; | ||
222 | |||
223 | mmwrite(irqcfg, MANTIS_GPIF_IRQCFG); | ||
224 | mutex_unlock(&ca->ca_lock); | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | void mantis_hif_exit(struct mantis_ca *ca) | ||
230 | { | ||
231 | struct mantis_pci *mantis = ca->ca_priv; | ||
232 | u32 irqcfg; | ||
233 | |||
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); | ||
240 | } | ||