blob: 42e0360e96d94f50fdfe014ff3d4627f71fe0cf3 [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
47 if (wait_event_interruptible_timeout(ca->hif_opdone_wq,
48 ca->hif_event & MANTIS_SBUF_OPDONE,
49 msecs_to_jiffies(500)) == -ERESTARTSYS) {
50
51 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
52 rc = -EREMOTEIO;
53 }
54 ca->hif_event &= ~MANTIS_SBUF_OPDONE;
55 udelay(5);
56 return rc;
57}
58
59int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
60{
61 struct mantis_pci *mantis = ca->ca_priv;
62 u32 hif_addr = 0, data, count = 4;
63
Manu Abraham2133ffb2009-12-04 05:12:16 -030064 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
Manu Abrahamd8b14f82009-12-04 05:09:47 -030065 hif_addr |= MANTIS_GPIF_HIFRDWRN;
66 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
67 hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
68 hif_addr |= addr;
69
70 mmwrite(hif_addr, MANTIS_GPIF_BRADDR);
71 mmwrite(count, MANTIS_GPIF_BRBYTES);
72
73 udelay(20);
74
75 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
76 if (mantis_hif_data_available(ca) != 0) {
77 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer burst read failed", mantis->num);
78 return -EREMOTEIO;
79 }
80 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
81 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
82 return -EREMOTEIO;
83 }
84 data = mmread(MANTIS_GPIF_HIFDIN);
85
86 return (data >> 24) & 0xff;
87}
88
89int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
90{
91 struct mantis_slot *slot = ca->slot;
92 struct mantis_pci *mantis = ca->ca_priv;
93 u32 hif_addr = 0;
94
Manu Abraham2133ffb2009-12-04 05:12:16 -030095 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", 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
101 mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
102
103 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
104 mmwrite(data, MANTIS_GPIF_HIFDOUT);
105 ca->hif_job_queue = MANTIS_HIF_MEMWR;
106
107 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
108 ca->hif_job_queue &= ~MANTIS_HIF_MEMWR;
109 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
110 return -EREMOTEIO;
111 }
112 ca->hif_job_queue &= ~MANTIS_HIF_MEMWR;
113 return 0;
114}
115
Manu Abraham60532402009-12-04 05:11:14 -0300116int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300117{
118 struct mantis_pci *mantis = ca->ca_priv;
Manu Abraham60532402009-12-04 05:11:14 -0300119 u32 data, hif_addr = 0;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300120
Manu Abraham2133ffb2009-12-04 05:12:16 -0300121 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300122 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
123 hif_addr |= MANTIS_GPIF_HIFRDWRN;
124 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
125 hif_addr |= addr;
126
127 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
128 ca->hif_job_queue = MANTIS_HIF_IOMRD;
129
130 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
131 ca->hif_job_queue &= ~MANTIS_HIF_IOMRD;
132 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
133 return -EREMOTEIO;
134 }
135 udelay(50);
136 ca->hif_job_queue &= ~MANTIS_HIF_IOMRD;
Manu Abraham60532402009-12-04 05:11:14 -0300137 data = mmread(MANTIS_GPIF_HIFDIN);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300138 hif_addr |= MANTIS_GPIF_PCMCIAREG;
139 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
140
Manu Abraham60532402009-12-04 05:11:14 -0300141 return data;
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300142}
143
Manu Abraham60532402009-12-04 05:11:14 -0300144int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300145{
146 struct mantis_pci *mantis = ca->ca_priv;
147 u32 hif_addr = 0;
148
Manu Abraham2133ffb2009-12-04 05:12:16 -0300149 dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
Manu Abrahamc9a750c2009-12-04 05:10:25 -0300150 hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
151 hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
152 hif_addr |= MANTIS_GPIF_PCMCIAIOM;
153 hif_addr |= addr;
154
155 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
156 mmwrite(data, MANTIS_GPIF_HIFDOUT);
157
158 ca->hif_job_queue = MANTIS_HIF_IOMWR;
159 if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
160 ca->hif_job_queue &= ~MANTIS_HIF_IOMWR;
161 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
162 return -EREMOTEIO;
163 }
164 udelay(50);
165 ca->hif_job_queue &= ~MANTIS_HIF_IOMWR;
166 hif_addr |= MANTIS_GPIF_PCMCIAREG;
167 mmwrite(hif_addr, MANTIS_GPIF_HIFADDR);
168
169 return 0;
170}
171
Manu Abrahamd8b14f82009-12-04 05:09:47 -0300172int mantis_hif_init(struct mantis_ca *ca)
173{
174 struct mantis_pci *mantis = ca->ca_priv;
175 u32 irqcfg;
176
177 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
178 init_waitqueue_head(&ca->hif_data_wq);
179 init_waitqueue_head(&ca->hif_opdone_wq);
180
181 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
182 irqcfg |= MANTIS_MASK_BRRDY;
183 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
184
185 return 0;
186}
187
188void mantis_hif_exit(struct mantis_ca *ca)
189{
190 struct mantis_pci *mantis = ca->ca_priv;
191 u32 irqcfg;
192
193 dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
194 irqcfg = mmread(MANTIS_GPIF_IRQCFG);
195 irqcfg &= ~MANTIS_MASK_BRRDY;
196 mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
197}