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 | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 60 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 61 | int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr) |
| 62 | { |
| 63 | struct mantis_pci *mantis = ca->ca_priv; |
| 64 | u32 hif_addr = 0, data, count = 4; |
| 65 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 66 | 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] | 67 | hif_addr |= MANTIS_GPIF_HIFRDWRN; |
| 68 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 69 | hif_addr &= ~MANTIS_GPIF_PCMCIAIOM; |
| 70 | hif_addr |= addr; |
| 71 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 72 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 73 | mmwrite(count, MANTIS_GPIF_BRBYTES); |
| 74 | |
| 75 | udelay(20); |
| 76 | |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 77 | mmwrite(hif_addr, MANTIS_GPIF_ADDR); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 78 | if (mantis_hif_sbuf_opdone_wait(ca) != 0) { |
| 79 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num); |
| 80 | return -EREMOTEIO; |
| 81 | } |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 82 | data = mmread(MANTIS_GPIF_DIN); |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 83 | dprintk(verbose, MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 84 | return (data >> 24) & 0xff; |
| 85 | } |
| 86 | |
| 87 | int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data) |
| 88 | { |
| 89 | struct mantis_slot *slot = ca->slot; |
| 90 | struct mantis_pci *mantis = ca->ca_priv; |
| 91 | u32 hif_addr = 0; |
| 92 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 93 | 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] | 94 | hif_addr &= ~MANTIS_GPIF_HIFRDWRN; |
| 95 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 96 | hif_addr &= ~MANTIS_GPIF_PCMCIAIOM; |
| 97 | hif_addr |= addr; |
| 98 | |
| 99 | mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */ |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 100 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 101 | mmwrite(data, MANTIS_GPIF_DOUT); |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 102 | |
| 103 | if (mantis_hif_sbuf_opdone_wait(ca) != 0) { |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 104 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 105 | return -EREMOTEIO; |
| 106 | } |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 107 | dprintk(verbose, MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr); |
| 108 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 112 | int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr) |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 113 | { |
| 114 | struct mantis_pci *mantis = ca->ca_priv; |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 115 | u32 data, hif_addr = 0; |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 116 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 117 | 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] | 118 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 119 | hif_addr |= MANTIS_GPIF_HIFRDWRN; |
| 120 | hif_addr |= MANTIS_GPIF_PCMCIAIOM; |
| 121 | hif_addr |= addr; |
| 122 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 123 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 124 | |
| 125 | if (mantis_hif_sbuf_opdone_wait(ca) != 0) { |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 126 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 127 | return -EREMOTEIO; |
| 128 | } |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 129 | data = mmread(MANTIS_GPIF_DIN); |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 130 | dprintk(verbose, MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data); |
Manu Abraham | 8e0d58e | 2009-12-04 05:22:57 -0300 | [diff] [blame] | 131 | udelay(50); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 132 | |
Manu Abraham | 9c86795 | 2009-12-04 05:21:05 -0300 | [diff] [blame] | 133 | return (u8) data; |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 134 | } |
| 135 | |
Manu Abraham | 6053240 | 2009-12-04 05:11:14 -0300 | [diff] [blame] | 136 | 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] | 137 | { |
| 138 | struct mantis_pci *mantis = ca->ca_priv; |
| 139 | u32 hif_addr = 0; |
| 140 | |
Manu Abraham | 2133ffb | 2009-12-04 05:12:16 -0300 | [diff] [blame] | 141 | 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] | 142 | hif_addr &= ~MANTIS_GPIF_PCMCIAREG; |
| 143 | hif_addr &= ~MANTIS_GPIF_HIFRDWRN; |
| 144 | hif_addr |= MANTIS_GPIF_PCMCIAIOM; |
| 145 | hif_addr |= addr; |
| 146 | |
Manu Abraham | b2d8f5e | 2009-12-04 05:16:24 -0300 | [diff] [blame] | 147 | mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR); |
Sigmund Augdal | a0c5906 | 2009-12-04 05:13:21 -0300 | [diff] [blame] | 148 | mmwrite(data, MANTIS_GPIF_DOUT); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 149 | |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 150 | if (mantis_hif_sbuf_opdone_wait(ca) != 0) { |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 151 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num); |
| 152 | return -EREMOTEIO; |
| 153 | } |
Manu Abraham | 8b9c385 | 2009-12-04 05:23:38 -0300 | [diff] [blame] | 154 | 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] | 155 | udelay(50); |
Manu Abraham | c9a750c | 2009-12-04 05:10:25 -0300 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 160 | int mantis_hif_init(struct mantis_ca *ca) |
| 161 | { |
Manu Abraham | ac23f4c | 2009-12-04 05:15:10 -0300 | [diff] [blame] | 162 | struct mantis_slot *slot = ca->slot; |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 163 | struct mantis_pci *mantis = ca->ca_priv; |
| 164 | u32 irqcfg; |
| 165 | |
Manu Abraham | ac23f4c | 2009-12-04 05:15:10 -0300 | [diff] [blame] | 166 | slot[0].slave_cfg = 0x70773028; |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 167 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num); |
| 168 | init_waitqueue_head(&ca->hif_data_wq); |
| 169 | init_waitqueue_head(&ca->hif_opdone_wq); |
| 170 | |
Manu Abraham | c90d345f | 2009-12-04 05:27:53 -0300 | [diff] [blame] | 171 | irqcfg = mmread(MANTIS_GPIF_IRQCFG); |
| 172 | irqcfg = MANTIS_MASK_BRRDY | |
| 173 | MANTIS_MASK_WRACK | |
| 174 | MANTIS_MASK_EXTIRQ | |
| 175 | MANTIS_MASK_WSTO | |
| 176 | MANTIS_MASK_OTHERR | |
| 177 | MANTIS_MASK_OVFLW; |
| 178 | |
Manu Abraham | d8b14f8 | 2009-12-04 05:09:47 -0300 | [diff] [blame] | 179 | mmwrite(irqcfg, MANTIS_GPIF_IRQCFG); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | void mantis_hif_exit(struct mantis_ca *ca) |
| 185 | { |
| 186 | struct mantis_pci *mantis = ca->ca_priv; |
| 187 | u32 irqcfg; |
| 188 | |
| 189 | dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num); |
| 190 | irqcfg = mmread(MANTIS_GPIF_IRQCFG); |
| 191 | irqcfg &= ~MANTIS_MASK_BRRDY; |
| 192 | mmwrite(irqcfg, MANTIS_GPIF_IRQCFG); |
| 193 | } |