mantis_hif.c 6.6 KB
Newer Older
1 2 3
/*
	Mantis PCI bridge driver

4
	Copyright (C) Manu Abraham (abraham.manu@gmail.com)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

21 22 23 24 25
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/sched.h>

#include <linux/interrupt.h>
26
#include <asm/io.h>
27 28 29 30 31 32 33

#include "dmxdev.h"
#include "dvbdev.h"
#include "dvb_demux.h"
#include "dvb_frontend.h"
#include "dvb_net.h"

34
#include "mantis_common.h"
35

36 37 38
#include "mantis_hif.h"
#include "mantis_link.h" /* temporary due to physical layer stuff */

39 40
#include "mantis_reg.h"

41 42 43 44 45 46

static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
{
	struct mantis_pci *mantis = ca->ca_priv;
	int rc = 0;

47 48 49
	if (wait_event_timeout(ca->hif_opdone_wq,
			       ca->hif_event & MANTIS_SBUF_OPDONE,
			       msecs_to_jiffies(500)) == -ERESTARTSYS) {
50

51
		dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
52 53
		rc = -EREMOTEIO;
	}
54
	dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
55 56 57 58
	ca->hif_event &= ~MANTIS_SBUF_OPDONE;
	return rc;
}

59 60 61 62 63 64 65 66 67 68
static int mantis_hif_write_wait(struct mantis_ca *ca)
{
	struct mantis_pci *mantis = ca->ca_priv;
	u32 opdone = 0, timeout = 0;
	int rc = 0;

	if (wait_event_timeout(ca->hif_write_wq,
			       mantis->gpif_status & MANTIS_GPIF_WRACK,
			       msecs_to_jiffies(500)) == -ERESTARTSYS) {

69
		dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);
70 71
		rc = -EREMOTEIO;
	}
72
	dprintk(MANTIS_DEBUG, 1, "Write Acknowledged");
73 74 75 76 77 78
	mantis->gpif_status &= ~MANTIS_GPIF_WRACK;
	while (!opdone) {
		opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE);
		udelay(500);
		timeout++;
		if (timeout > 100) {
79
			dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write operation timed out!", mantis->num);
80 81 82 83
			rc = -ETIMEDOUT;
			break;
		}
	}
84
	dprintk(MANTIS_DEBUG, 1, "HIF Write success");
85 86 87
	return rc;
}

88

89 90 91 92 93
int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
{
	struct mantis_pci *mantis = ca->ca_priv;
	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 97
	hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
	hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
98
	hif_addr |=  MANTIS_HIF_STATUS;
99 100
	hif_addr |=  addr;

101
	mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
102 103
	mmwrite(count, MANTIS_GPIF_BRBYTES);
	udelay(20);
104
	mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
105 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);
109 110
		return -EREMOTEIO;
	}
111
	data = mmread(MANTIS_GPIF_DIN);
112
	mutex_unlock(&ca->ca_lock);
113
	dprintk(MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);
114 115 116 117 118 119 120 121 122
	return (data >> 24) & 0xff;
}

int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
{
	struct mantis_slot *slot = ca->slot;
	struct mantis_pci *mantis = ca->ca_priv;
	u32 hif_addr = 0;

123
	dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
124
	mutex_lock(&ca->ca_lock);
125 126 127
	hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
	hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
	hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
128 129
	hif_addr |=  MANTIS_HIF_STATUS;
	hif_addr |=  addr;
130 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);
134

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);
138 139
		return -EREMOTEIO;
	}
140
	dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
141
	mutex_unlock(&ca->ca_lock);
142

143 144 145
	return 0;
}

146
int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
147 148
{
	struct mantis_pci *mantis = ca->ca_priv;
149
	u32 data, hif_addr = 0;
150

151
	dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
152
	mutex_lock(&ca->ca_lock);
153 154
	hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
	hif_addr |=  MANTIS_GPIF_PCMCIAIOM;
155
	hif_addr |=  MANTIS_HIF_STATUS;
156 157
	hif_addr |=  addr;

158
	mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
159 160
	mmwrite(1, MANTIS_GPIF_BRBYTES);
	udelay(20);
161
	mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
162 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);
166 167
		return -EREMOTEIO;
	}
168
	data = mmread(MANTIS_GPIF_DIN);
169
	dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
170
	udelay(50);
171
	mutex_unlock(&ca->ca_lock);
172

173
	return (u8) data;
174 175
}

176
int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
177 178 179 180
{
	struct mantis_pci *mantis = ca->ca_priv;
	u32 hif_addr = 0;

181
	dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
182
	mutex_lock(&ca->ca_lock);
183 184 185
	hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
	hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
	hif_addr |=  MANTIS_GPIF_PCMCIAIOM;
186
	hif_addr |=  MANTIS_HIF_STATUS;
187 188
	hif_addr |=  addr;

189
	mmwrite(hif_addr, MANTIS_GPIF_ADDR);
190
	mmwrite(data, MANTIS_GPIF_DOUT);
191

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);
195 196
		return -EREMOTEIO;
	}
197
	dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
198
	mutex_unlock(&ca->ca_lock);
199
	udelay(50);
200 201 202 203

	return 0;
}

204 205
int mantis_hif_init(struct mantis_ca *ca)
{
206
	struct mantis_slot *slot = ca->slot;
207 208 209
	struct mantis_pci *mantis = ca->ca_priv;
	u32 irqcfg;

210
	slot[0].slave_cfg = 0x70773028;
211
	dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
212

213
	mutex_lock(&ca->ca_lock);
214 215 216 217 218 219 220 221
	irqcfg = mmread(MANTIS_GPIF_IRQCFG);
	irqcfg = MANTIS_MASK_BRRDY	|
		 MANTIS_MASK_WRACK	|
		 MANTIS_MASK_EXTIRQ	|
		 MANTIS_MASK_WSTO	|
		 MANTIS_MASK_OTHERR	|
		 MANTIS_MASK_OVFLW;

222
	mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
223
	mutex_unlock(&ca->ca_lock);
224 225 226 227 228 229 230 231 232

	return 0;
}

void mantis_hif_exit(struct mantis_ca *ca)
{
	struct mantis_pci *mantis = ca->ca_priv;
	u32 irqcfg;

233
	dprintk(MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
234
	mutex_lock(&ca->ca_lock);
235 236 237
	irqcfg = mmread(MANTIS_GPIF_IRQCFG);
	irqcfg &= ~MANTIS_MASK_BRRDY;
	mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
238
	mutex_unlock(&ca->ca_lock);
239
}