Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | static 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 | |
| 42 | static 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 Abraham | ac8f04d | 2009-12-04 05:29:25 -0300 | [diff] [blame] | 47 | if (wait_event_timeout(ca->hif_opdone_wq, |
| 48 | ca->hif_event & MANTIS_SBUF_OPDONE, |
| 49 | msecs_to_jiffies(500)) == -ERESTARTSYS) { |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 50 | |
| 51 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num); |
| 52 | rc = -EREMOTEIO; |
| 53 | } |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 54 | dprintk(verbose, MANTIS_DEBUG, 1, "Smart Buffer Operation complete"); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 55 | ca->hif_event &= ~MANTIS_SBUF_OPDONE; |
| 56 | udelay(5); |
| 57 | return rc; |
| 58 | } |
| 59 | |
Manu Abraham | e0e099a | 2009-12-04 05:29:48 -0300 | [diff] [blame] | 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(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 Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 89 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 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 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 95 | dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 96 | hif_addr |= MANTIS_GPIF_HIFRDWRN; |
| 97 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 98 | hif_addr &= ~MANTIS_GPIF_PCMCIAIOM; |
| 99 | hif_addr |= addr; |
| 100 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 101 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 102 | mmwrite(count, MANTIS_GPIF_BRBYTES); |
| 103 | |
| 104 | udelay(20); |
| 105 | |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 106 | mmwrite(hif_addr, MANTIS_GPIF_ADDR); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 107 | 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 Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 111 | data = mmread(MANTIS_GPIF_DIN); |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 112 | dprintk(verbose, MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 113 | return (data >> 24) & 0xff; |
| 114 | } |
| 115 | |
| 116 | int 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 Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 122 | dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 123 | 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 Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 129 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 130 | mmwrite(data, MANTIS_GPIF_DOUT); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 131 | |
Manu Abraham | e0e099a | 2009-12-04 05:29:48 -0300 | [diff] [blame] | 132 | if (mantis_hif_write_wait(ca) != 0) { |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 133 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 134 | return -EREMOTEIO; |
| 135 | } |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 136 | dprintk(verbose, MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr); |
| 137 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 141 | int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr) |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 142 | { |
| 143 | struct mantis_pci *mantis = ca->ca_priv; |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 144 | u32 data, hif_addr = 0; |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 145 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 146 | dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 147 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 148 | hif_addr |= MANTIS_GPIF_HIFRDWRN; |
| 149 | hif_addr |= MANTIS_GPIF_PCMCIAIOM; |
| 150 | hif_addr |= addr; |
| 151 | |
Sigmund Augdal | c63e507 | 2009-12-04 05:30:59 -0300 | [diff] [blame^] | 152 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR); |
| 153 | mmwrite(1, MANTIS_GPIF_BRBYTES); |
| 154 | |
| 155 | udelay(20); |
| 156 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 157 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 158 | |
| 159 | if (mantis_hif_sbuf_opdone_wait(ca) != 0) { |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 160 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 161 | return -EREMOTEIO; |
| 162 | } |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 163 | data = mmread(MANTIS_GPIF_DIN); |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 164 | dprintk(verbose, MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data); |
Manu Abraham | 8e0d58e | 2009-12-04 05:22:57 -0300 | [diff] [blame] | 165 | udelay(50); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 166 | |
Manu Abraham | 9c86795 | 2009-12-04 05:21:05 -0300 | [diff] [blame] | 167 | return (u8) data; |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 168 | } |
| 169 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 170 | int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data) |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 171 | { |
| 172 | struct mantis_pci *mantis = ca->ca_priv; |
| 173 | u32 hif_addr = 0; |
| 174 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 175 | dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 176 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 177 | hif_addr &= ~MANTIS_GPIF_HIFRDWRN; |
| 178 | hif_addr |= MANTIS_GPIF_PCMCIAIOM; |
| 179 | hif_addr |= addr; |
| 180 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 181 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 182 | mmwrite(data, MANTIS_GPIF_DOUT); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 183 | |
Manu Abraham | e0e099a | 2009-12-04 05:29:48 -0300 | [diff] [blame] | 184 | if (mantis_hif_write_wait(ca) != 0) { |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 185 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 186 | return -EREMOTEIO; |
| 187 | } |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 188 | dprintk(verbose, MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr); |
Manu Abraham | 8e0d58e | 2009-12-04 05:22:57 -0300 | [diff] [blame] | 189 | udelay(50); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 194 | int mantis_hif_init(struct mantis_ca *ca) |
| 195 | { |
Manu Abraham | ac23f4c | 2009-12-04 05:15:10 -0300 | [diff] [blame] | 196 | struct mantis_slot *slot = ca->slot; |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 197 | struct mantis_pci *mantis = ca->ca_priv; |
| 198 | u32 irqcfg; |
| 199 | |
Manu Abraham | ac23f4c | 2009-12-04 05:15:10 -0300 | [diff] [blame] | 200 | slot[0].slave_cfg = 0x70773028; |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 201 | 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 Abraham | e0e099a | 2009-12-04 05:29:48 -0300 | [diff] [blame] | 204 | init_waitqueue_head(&ca->hif_write_wq); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 205 | |
Manu Abraham | c90d345 | 2009-12-04 05:27:53 -0300 | [diff] [blame] | 206 | 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 Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 214 | mmwrite(irqcfg, MANTIS_GPIF_IRQCFG); |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | void 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 | } |