blob: 5772ebb3a69ed9ba494a0a043ca1f7582ac65902 [file] [log] [blame]
Manu Abrahamd8b14f82009-12-04 05:09:47 -03001/*
2 Mantis PCI bridge driver
3
Manu Abraham8825a092009-12-15 09:13:49 -03004 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
Manu Abrahamd8b14f82009-12-04 05:09:47 -03005
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
Manu Abrahamb3b96142009-12-04 05:41:11 -030021#include <linux/kernel.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24
Manu Abrahamb3b96142009-12-04 05:41:11 -030025#include <linux/interrupt.h>
26
27#include "dmxdev.h"
28#include "dvbdev.h"
29#include "dvb_demux.h"
30#include "dvb_frontend.h"
31#include "dvb_net.h"
32
Manu Abrahamd8b14f82009-12-04 05:09:47 -030033#include "mantis_common.h"
Manu Abrahamb3b96142009-12-04 05:41:11 -030034
Manu Abrahamd8b14f82009-12-04 05:09:47 -030035#include "mantis_hif.h"
36#include "mantis_link.h" /* temporary due to physical layer stuff */
37
Manu Abrahamb3b96142009-12-04 05:41:11 -030038#include "mantis_reg.h"
39
Manu Abrahamd8b14f82009-12-04 05:09:47 -030040
41static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
42{
43 struct mantis_pci *mantis = ca->ca_priv;
44 int rc = 0;
45
Manu Abrahamac8f04d2009-12-04 05:29:25 -030046 if (wait_event_timeout(ca->hif_opdone_wq,
47 ca->hif_event & MANTIS_SBUF_OPDONE,
48 msecs_to_jiffies(500)) == -ERESTARTSYS) {
Manu Abrahamd8b14f82009-12-04 05:09:47 -030049
Manu Abrahamb3b96142009-12-04 05:41:11 -030050 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
Manu Abrahamd8b14f82009-12-04 05:09:47 -030051 rc = -EREMOTEIO;
52 }
Manu Abrahamb3b96142009-12-04 05:41:11 -030053 dprintk(MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
Manu Abrahamd8b14f82009-12-04 05:09:47 -030054 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
Manu Abrahamd8b14f82009-12-04 05:09:47 -030055 return rc;
56}
57
Manu Abrahame0e099a2009-12-04 05:29:48 -030058static int mantis_hif_write_wait(struct mantis_ca *ca)
59{
60 struct mantis_pci *mantis = ca->ca_priv;
61 u32 opdone = 0, timeout = 0;
62 int rc = 0;
63
64 if (wait_event_timeout(ca->hif_write_wq,
65 mantis->gpif_status & MANTIS_GPIF_WRACK,
66 msecs_to_jiffies(500)) == -ERESTARTSYS) {
67
Manu Abrahamb3b96142009-12-04 05:41:11 -030068 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);
Manu Abrahame0e099a2009-12-04 05:29:48 -030069 rc = -EREMOTEIO;
70 }
Manu Abrahamb3b96142009-12-04 05:41:11 -030071 dprintk(MANTIS_DEBUG, 1, "Write Acknowledged");
Manu Abrahame0e099a2009-12-04 05:29:48 -030072 mantis->gpif_status &= ~MANTIS_GPIF_WRACK;
73 while (!opdone) {
74 opdone = (mmread(MANTIS_GPIF_STATUS) & MANTIS_SBUF_OPDONE);
75 udelay(500);
76 timeout++;
77 if (timeout > 100) {
Manu Abrahamb3b96142009-12-04 05:41:11 -030078 dprintk(MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num);
Manu Abrahame0e099a2009-12-04 05:29:48 -030079 rc = -ETIMEDOUT;
80 break;
81 }
82 }
Manu Abrahamb3b96142009-12-04 05:41:11 -030083 dprintk(MANTIS_DEBUG, 1, "HIF Write success");
Manu Abrahame0e099a2009-12-04 05:29:48 -030084 return rc;
85}
86
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -030087
Manu Abrahamd8b14f82009-12-04 05:09:47 -030088int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
89{
90 struct mantis_pci *mantis = ca->ca_priv;
91 u32 hif_addr = 0, data, count = 4;
92
Manu Abrahamb3b96142009-12-04 05:41:11 -030093 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -030094 mutex_lock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -030095 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
96 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
Manu Abrahamb29f6ac2009-12-04 05:31:21 -030097 hif_addr |= MANTIS_HIF_STATUS;
Manu Abrahamd8b14f82009-12-04 05:09:47 -030098 hif_addr |= addr;
99
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300100 mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300101 mmwrite(count, MANTIS_GPIF_BRBYTES);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300102 udelay(20);
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300103 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300104
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300105 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300106 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300107 mutex_unlock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300108 return -EREMOTEIO;
109 }
Sigmund Augdala0c59062009-12-04 05:13:21 -0300110 data = mmread(MANTIS_GPIF_DIN);
Manu Abrahamf6843362009-12-04 05:34:19 -0300111 mutex_unlock(&ca->ca_lock);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300112 dprintk(MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300113 return (data >> 24) & 0xff;
114}
115
116int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
117{
118 struct mantis_slot *slot = ca->slot;
119 struct mantis_pci *mantis = ca->ca_priv;
120 u32 hif_addr = 0;
121
Manu Abrahamb3b96142009-12-04 05:41:11 -0300122 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300123 mutex_lock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300124 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
125 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
126 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300127 hif_addr |= MANTIS_HIF_STATUS;
128 hif_addr |= addr;
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300129
130 mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300131 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
Sigmund Augdala0c59062009-12-04 05:13:21 -0300132 mmwrite(data, MANTIS_GPIF_DOUT);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300133
Manu Abrahame0e099a2009-12-04 05:29:48 -0300134 if (mantis_hif_write_wait(ca) != 0) {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300135 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300136 mutex_unlock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300137 return -EREMOTEIO;
138 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300139 dprintk(MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
Manu Abrahamf6843362009-12-04 05:34:19 -0300140 mutex_unlock(&ca->ca_lock);
Manu Abraham8b9c3852009-12-04 05:23:38 -0300141
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300142 return 0;
143}
144
Manu Abraham60532402009-12-04 05:11:14 -0300145int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300146{
147 struct mantis_pci *mantis = ca->ca_priv;
Manu Abraham60532402009-12-04 05:11:14 -0300148 u32 data, hif_addr = 0;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300149
Manu Abrahamb3b96142009-12-04 05:41:11 -0300150 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300151 mutex_lock(&ca->ca_lock);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300152 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300153 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300154 hif_addr |= MANTIS_HIF_STATUS;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300155 hif_addr |= addr;
156
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300157 mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
Sigmund Augdalc63e5072009-12-04 05:30:59 -0300158 mmwrite(1, MANTIS_GPIF_BRBYTES);
Sigmund Augdalc63e5072009-12-04 05:30:59 -0300159 udelay(20);
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300160 mmwrite(hif_addr | MANTIS_GPIF_HIFRDWRN, MANTIS_GPIF_ADDR);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300161
162 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300163 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300164 mutex_unlock(&ca->ca_lock);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300165 return -EREMOTEIO;
166 }
Sigmund Augdala0c59062009-12-04 05:13:21 -0300167 data = mmread(MANTIS_GPIF_DIN);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300168 dprintk(MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
Manu Abraham8e0d58e2009-12-04 05:22:57 -0300169 udelay(50);
Manu Abrahamf6843362009-12-04 05:34:19 -0300170 mutex_unlock(&ca->ca_lock);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300171
Manu Abraham9c867952009-12-04 05:21:05 -0300172 return (u8) data;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300173}
174
Manu Abraham60532402009-12-04 05:11:14 -0300175int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300176{
177 struct mantis_pci *mantis = ca->ca_priv;
178 u32 hif_addr = 0;
179
Manu Abrahamb3b96142009-12-04 05:41:11 -0300180 dprintk(MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300181 mutex_lock(&ca->ca_lock);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300182 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
183 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
184 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300185 hif_addr |= MANTIS_HIF_STATUS;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300186 hif_addr |= addr;
187
Manu Abrahamb29f6ac2009-12-04 05:31:21 -0300188 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
Sigmund Augdala0c59062009-12-04 05:13:21 -0300189 mmwrite(data, MANTIS_GPIF_DOUT);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300190
Manu Abrahame0e099a2009-12-04 05:29:48 -0300191 if (mantis_hif_write_wait(ca) != 0) {
Manu Abrahamb3b96142009-12-04 05:41:11 -0300192 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300193 mutex_unlock(&ca->ca_lock);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300194 return -EREMOTEIO;
195 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300196 dprintk(MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
Manu Abrahamf6843362009-12-04 05:34:19 -0300197 mutex_unlock(&ca->ca_lock);
Manu Abraham8e0d58e2009-12-04 05:22:57 -0300198 udelay(50);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300199
200 return 0;
201}
202
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300203int mantis_hif_init(struct mantis_ca *ca)
204{
Manu Abrahamac23f4c2009-12-04 05:15:10 -0300205 struct mantis_slot *slot = ca->slot;
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300206 struct mantis_pci *mantis = ca->ca_priv;
207 u32 irqcfg;
208
Manu Abrahamac23f4c2009-12-04 05:15:10 -0300209 slot[0].slave_cfg = 0x70773028;
Manu Abrahamb3b96142009-12-04 05:41:11 -0300210 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300211
Manu Abrahamf6843362009-12-04 05:34:19 -0300212 mutex_lock(&ca->ca_lock);
Manu Abrahamc90d345f2009-12-04 05:27:53 -0300213 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
214 irqcfg = MANTIS_MASK_BRRDY |
215 MANTIS_MASK_WRACK |
216 MANTIS_MASK_EXTIRQ |
217 MANTIS_MASK_WSTO |
218 MANTIS_MASK_OTHERR |
219 MANTIS_MASK_OVFLW;
220
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300221 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
Manu Abrahamf6843362009-12-04 05:34:19 -0300222 mutex_unlock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300223
224 return 0;
225}
226
227void mantis_hif_exit(struct mantis_ca *ca)
228{
229 struct mantis_pci *mantis = ca->ca_priv;
230 u32 irqcfg;
231
Manu Abrahamb3b96142009-12-04 05:41:11 -0300232 dprintk(MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
Manu Abrahamf6843362009-12-04 05:34:19 -0300233 mutex_lock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300234 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
235 irqcfg &= ~MANTIS_MASK_BRRDY;
236 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
Manu Abrahamf6843362009-12-04 05:34:19 -0300237 mutex_unlock(&ca->ca_lock);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300238}