blob: 323d1fb0a55e267654087cf64506ebc5f4ed0997 [file] [log] [blame]
Manu Abrahamd8b14f82009-12-04 05:09:47 -03001/*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 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 "mantis_common.h"
22#include "mantis_hif.h"
23#include "mantis_link.h" /* temporary due to physical layer stuff */
24
25static int mantis_hif_data_available(struct mantis_ca *ca)
26{
27 struct mantis_pci *mantis = ca->ca_priv;
28 int rc = 0;
29
30 if (wait_event_interruptible_timeout(ca->hif_data_wq,
31 ca->sbuf_status & MANTIS_SBUF_DATA_AVAIL,
32 msecs_to_jiffies(500)) == -ERESTARTSYS) {
33
34 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Read wait event timeout !", mantis->num);
35 rc = -EREMOTEIO;
36 }
37 ca->sbuf_status &= ~MANTIS_SBUF_DATA_AVAIL;
38 udelay(2);
39 return rc;
40}
41
42static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
43{
44 struct mantis_pci *mantis = ca->ca_priv;
45 int rc = 0;
46
Manu Abrahamac8f04d2009-12-04 05:29:25 -030047 if (wait_event_timeout(ca->hif_opdone_wq,
48 ca->hif_event & MANTIS_SBUF_OPDONE,
49 msecs_to_jiffies(500)) == -ERESTARTSYS) {
Manu Abrahamd8b14f82009-12-04 05:09:47 -030050
51 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
52 rc = -EREMOTEIO;
53 }
Manu Abraham8b9c3852009-12-04 05:23:38 -030054 dprintk(verbose, MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
Manu Abrahamd8b14f82009-12-04 05:09:47 -030055 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
56 udelay(5);
57 return rc;
58}
59
Manu Abrahame0e099a2009-12-04 05:29:48 -030060static 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(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Write ACK timed out !", mantis->num);
71 rc = -EREMOTEIO;
72 }
73 dprintk(verbose, 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(verbose, MANTIS_ERROR, 1, "Adater(%d) Slot(0): Write operation timed out!", mantis->num);
81 rc = -ETIMEDOUT;
82 break;
83 }
84 }
85 dprintk(verbose, MANTIS_DEBUG, 1, "HIF Write success");
86 return rc;
87}
88
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -030089
Manu Abrahamd8b14f82009-12-04 05:09:47 -030090int 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
Manu Abraham2133ffb2009-12-04 05:12:16 -030095 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
Manu Abrahamd8b14f82009-12-04 05:09:47 -030096 hif_addr |= MANTIS_GPIF_HIFRDWRN;
97 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
98 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
99 hif_addr |= addr;
100
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -0300101 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300102 mmwrite(count, MANTIS_GPIF_BRBYTES);
103
104 udelay(20);
105
Sigmund Augdala0c59062009-12-04 05:13:21 -0300106 mmwrite(hif_addr, MANTIS_GPIF_ADDR);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300107 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
108 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
109 return -EREMOTEIO;
110 }
Sigmund Augdala0c59062009-12-04 05:13:21 -0300111 data = mmread(MANTIS_GPIF_DIN);
Manu Abraham8b9c3852009-12-04 05:23:38 -0300112 dprintk(verbose, 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 Abraham2133ffb2009-12-04 05:12:16 -0300122 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300123 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
124 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
125 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
126 hif_addr |= addr;
127
128 mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -0300129 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
Sigmund Augdala0c59062009-12-04 05:13:21 -0300130 mmwrite(data, MANTIS_GPIF_DOUT);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300131
Manu Abrahame0e099a2009-12-04 05:29:48 -0300132 if (mantis_hif_write_wait(ca) != 0) {
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300133 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
134 return -EREMOTEIO;
135 }
Manu Abraham8b9c3852009-12-04 05:23:38 -0300136 dprintk(verbose, MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
137
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300138 return 0;
139}
140
Manu Abraham60532402009-12-04 05:11:14 -0300141int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300142{
143 struct mantis_pci *mantis = ca->ca_priv;
Manu Abraham60532402009-12-04 05:11:14 -0300144 u32 data, hif_addr = 0;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300145
Manu Abraham2133ffb2009-12-04 05:12:16 -0300146 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300147 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
148 hif_addr |= MANTIS_GPIF_HIFRDWRN;
149 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
150 hif_addr |= addr;
151
Sigmund Augdalc63e5072009-12-04 05:30:59 -0300152 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR);
153 mmwrite(1, MANTIS_GPIF_BRBYTES);
154
155 udelay(20);
156
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -0300157 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300158
159 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300160 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
161 return -EREMOTEIO;
162 }
Sigmund Augdala0c59062009-12-04 05:13:21 -0300163 data = mmread(MANTIS_GPIF_DIN);
Manu Abraham8b9c3852009-12-04 05:23:38 -0300164 dprintk(verbose, MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
Manu Abraham8e0d58e2009-12-04 05:22:57 -0300165 udelay(50);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300166
Manu Abraham9c867952009-12-04 05:21:05 -0300167 return (u8) data;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300168}
169
Manu Abraham60532402009-12-04 05:11:14 -0300170int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300171{
172 struct mantis_pci *mantis = ca->ca_priv;
173 u32 hif_addr = 0;
174
Manu Abraham2133ffb2009-12-04 05:12:16 -0300175 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300176 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
177 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
178 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
179 hif_addr |= addr;
180
Manu Abrahamb2d8f5e2009-12-04 05:16:24 -0300181 mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
Sigmund Augdala0c59062009-12-04 05:13:21 -0300182 mmwrite(data, MANTIS_GPIF_DOUT);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300183
Manu Abrahame0e099a2009-12-04 05:29:48 -0300184 if (mantis_hif_write_wait(ca) != 0) {
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300185 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
186 return -EREMOTEIO;
187 }
Manu Abraham8b9c3852009-12-04 05:23:38 -0300188 dprintk(verbose, MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
Manu Abraham8e0d58e2009-12-04 05:22:57 -0300189 udelay(50);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300190
191 return 0;
192}
193
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300194int mantis_hif_init(struct mantis_ca *ca)
195{
Manu Abrahamac23f4c2009-12-04 05:15:10 -0300196 struct mantis_slot *slot = ca->slot;
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300197 struct mantis_pci *mantis = ca->ca_priv;
198 u32 irqcfg;
199
Manu Abrahamac23f4c2009-12-04 05:15:10 -0300200 slot[0].slave_cfg = 0x70773028;
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300201 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
202 init_waitqueue_head(&ca->hif_data_wq);
203 init_waitqueue_head(&ca->hif_opdone_wq);
Manu Abrahame0e099a2009-12-04 05:29:48 -0300204 init_waitqueue_head(&ca->hif_write_wq);
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300205
Manu Abrahamc90d3452009-12-04 05:27:53 -0300206 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
207 irqcfg = MANTIS_MASK_BRRDY |
208 MANTIS_MASK_WRACK |
209 MANTIS_MASK_EXTIRQ |
210 MANTIS_MASK_WSTO |
211 MANTIS_MASK_OTHERR |
212 MANTIS_MASK_OVFLW;
213
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300214 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
215
216 return 0;
217}
218
219void mantis_hif_exit(struct mantis_ca *ca)
220{
221 struct mantis_pci *mantis = ca->ca_priv;
222 u32 irqcfg;
223
224 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
225 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
226 irqcfg &= ~MANTIS_MASK_BRRDY;
227 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
228}