if_smc.c (179592) | if_smc.c (179718) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2006 Benno Rice. All rights reserved. | 2 * Copyright (c) 2008 Benno Rice. All rights reserved. |
3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the --- 7 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> | 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the --- 7 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> |
26__FBSDID("$FreeBSD: head/sys/dev/smc/if_smc.c 179592 2008-06-06 05:00:49Z benno $"); | 26__FBSDID("$FreeBSD: head/sys/dev/smc/if_smc.c 179718 2008-06-11 06:53:55Z benno $"); |
27 28/* 29 * Driver for SMSC LAN91C111, may work for older variants. 30 */ 31 32#ifdef HAVE_KERNEL_OPTION_HEADERS 33#include "opt_device_polling.h" 34#endif --- 77 unchanged lines hidden (view full) --- 112#ifdef DEVICE_POLLING 113static poll_handler_t smc_poll; 114#endif 115 116static __inline void 117smc_select_bank(struct smc_softc *sc, uint16_t bank) 118{ 119 | 27 28/* 29 * Driver for SMSC LAN91C111, may work for older variants. 30 */ 31 32#ifdef HAVE_KERNEL_OPTION_HEADERS 33#include "opt_device_polling.h" 34#endif --- 77 unchanged lines hidden (view full) --- 112#ifdef DEVICE_POLLING 113static poll_handler_t smc_poll; 114#endif 115 116static __inline void 117smc_select_bank(struct smc_softc *sc, uint16_t bank) 118{ 119 |
120 bus_space_write_2(sc->smc_bst, sc->smc_bsh, BSR, bank & BSR_BANK_MASK); | 120 bus_write_2(sc->smc_reg, BSR, bank & BSR_BANK_MASK); |
121} 122 123/* Never call this when not in bank 2. */ 124static __inline void 125smc_mmu_wait(struct smc_softc *sc) 126{ 127 | 121} 122 123/* Never call this when not in bank 2. */ 124static __inline void 125smc_mmu_wait(struct smc_softc *sc) 126{ 127 |
128 KASSERT((bus_space_read_2(sc->smc_bst, sc->smc_bsh, BSR) & | 128 KASSERT((bus_read_2(sc->smc_reg, BSR) & |
129 BSR_BANK_MASK) == 2, ("%s: smc_mmu_wait called when not in bank 2", 130 device_get_nameunit(sc->smc_dev))); | 129 BSR_BANK_MASK) == 2, ("%s: smc_mmu_wait called when not in bank 2", 130 device_get_nameunit(sc->smc_dev))); |
131 while (bus_space_read_2(sc->smc_bst, sc->smc_bsh, MMUCR) & MMUCR_BUSY) | 131 while (bus_read_2(sc->smc_reg, MMUCR) & MMUCR_BUSY) |
132 ; 133} 134 135static __inline uint8_t 136smc_read_1(struct smc_softc *sc, bus_addr_t offset) 137{ 138 | 132 ; 133} 134 135static __inline uint8_t 136smc_read_1(struct smc_softc *sc, bus_addr_t offset) 137{ 138 |
139 return (bus_space_read_1(sc->smc_bst, sc->smc_bsh, offset)); | 139 return (bus_read_1(sc->smc_reg, offset)); |
140} 141 142static __inline void 143smc_write_1(struct smc_softc *sc, bus_addr_t offset, uint8_t val) 144{ 145 | 140} 141 142static __inline void 143smc_write_1(struct smc_softc *sc, bus_addr_t offset, uint8_t val) 144{ 145 |
146 bus_space_write_1(sc->smc_bst, sc->smc_bsh, offset, val); | 146 bus_write_1(sc->smc_reg, offset, val); |
147} 148 149static __inline uint16_t 150smc_read_2(struct smc_softc *sc, bus_addr_t offset) 151{ 152 | 147} 148 149static __inline uint16_t 150smc_read_2(struct smc_softc *sc, bus_addr_t offset) 151{ 152 |
153 return (bus_space_read_2(sc->smc_bst, sc->smc_bsh, offset)); | 153 return (bus_read_2(sc->smc_reg, offset)); |
154} 155 156static __inline void 157smc_write_2(struct smc_softc *sc, bus_addr_t offset, uint16_t val) 158{ 159 | 154} 155 156static __inline void 157smc_write_2(struct smc_softc *sc, bus_addr_t offset, uint16_t val) 158{ 159 |
160 bus_space_write_2(sc->smc_bst, sc->smc_bsh, offset, val); | 160 bus_write_2(sc->smc_reg, offset, val); |
161} 162 163static __inline void 164smc_read_multi_2(struct smc_softc *sc, bus_addr_t offset, uint16_t *datap, 165 bus_size_t count) 166{ 167 | 161} 162 163static __inline void 164smc_read_multi_2(struct smc_softc *sc, bus_addr_t offset, uint16_t *datap, 165 bus_size_t count) 166{ 167 |
168 bus_space_read_multi_2(sc->smc_bst, sc->smc_bsh, offset, datap, count); | 168 bus_read_multi_2(sc->smc_reg, offset, datap, count); |
169} 170 171static __inline void 172smc_write_multi_2(struct smc_softc *sc, bus_addr_t offset, uint16_t *datap, 173 bus_size_t count) 174{ 175 | 169} 170 171static __inline void 172smc_write_multi_2(struct smc_softc *sc, bus_addr_t offset, uint16_t *datap, 173 bus_size_t count) 174{ 175 |
176 bus_space_write_multi_2(sc->smc_bst, sc->smc_bsh, offset, datap, count); | 176 bus_write_multi_2(sc->smc_reg, offset, datap, count); |
177} 178 179int 180smc_probe(device_t dev) 181{ 182 int rid, type, error; 183 uint16_t val; 184 struct smc_softc *sc; 185 struct resource *reg; | 177} 178 179int 180smc_probe(device_t dev) 181{ 182 int rid, type, error; 183 uint16_t val; 184 struct smc_softc *sc; 185 struct resource *reg; |
186 bus_space_tag_t bst; 187 bus_space_handle_t bsh; | |
188 189 sc = device_get_softc(dev); 190 rid = 0; 191 type = SYS_RES_IOPORT; 192 error = 0; 193 194 if (sc->smc_usemem) 195 type = SYS_RES_MEMORY; 196 197 reg = bus_alloc_resource(dev, type, &rid, 0, ~0, 16, RF_ACTIVE); 198 if (reg == NULL) { 199 if (bootverbose) 200 device_printf(dev, 201 "could not allocate I/O resource for probe\n"); 202 return (ENXIO); 203 } 204 | 186 187 sc = device_get_softc(dev); 188 rid = 0; 189 type = SYS_RES_IOPORT; 190 error = 0; 191 192 if (sc->smc_usemem) 193 type = SYS_RES_MEMORY; 194 195 reg = bus_alloc_resource(dev, type, &rid, 0, ~0, 16, RF_ACTIVE); 196 if (reg == NULL) { 197 if (bootverbose) 198 device_printf(dev, 199 "could not allocate I/O resource for probe\n"); 200 return (ENXIO); 201 } 202 |
205 bst = rman_get_bustag(reg); 206 bsh = rman_get_bushandle(reg); 207 | |
208 /* Check for the identification value in the BSR. */ | 203 /* Check for the identification value in the BSR. */ |
209 val = bus_space_read_2(bst, bsh, BSR); | 204 val = bus_read_2(reg, BSR); |
210 if ((val & BSR_IDENTIFY_MASK) != BSR_IDENTIFY) { 211 if (bootverbose) 212 device_printf(dev, "identification value not in BSR\n"); 213 error = ENXIO; 214 goto done; 215 } 216 217 /* 218 * Try switching banks and make sure we still get the identification 219 * value. 220 */ | 205 if ((val & BSR_IDENTIFY_MASK) != BSR_IDENTIFY) { 206 if (bootverbose) 207 device_printf(dev, "identification value not in BSR\n"); 208 error = ENXIO; 209 goto done; 210 } 211 212 /* 213 * Try switching banks and make sure we still get the identification 214 * value. 215 */ |
221 bus_space_write_2(bst, bsh, BSR, 0); 222 val = bus_space_read_2(bst, bsh, BSR); | 216 bus_write_2(reg, BSR, 0); 217 val = bus_read_2(reg, BSR); |
223 if ((val & BSR_IDENTIFY_MASK) != BSR_IDENTIFY) { 224 if (bootverbose) 225 device_printf(dev, 226 "identification value not in BSR after write\n"); 227 error = ENXIO; 228 goto done; 229 } 230 231#if 0 232 /* Check the BAR. */ | 218 if ((val & BSR_IDENTIFY_MASK) != BSR_IDENTIFY) { 219 if (bootverbose) 220 device_printf(dev, 221 "identification value not in BSR after write\n"); 222 error = ENXIO; 223 goto done; 224 } 225 226#if 0 227 /* Check the BAR. */ |
233 bus_space_write_2(bst, bsh, BSR, 1); 234 val = bus_space_read_2(bst, bsh, BAR); | 228 bus_write_2(reg, BSR, 1); 229 val = bus_read_2(reg, BAR); |
235 val = BAR_ADDRESS(val); 236 if (rman_get_start(reg) != val) { 237 if (bootverbose) 238 device_printf(dev, "BAR address %x does not match " 239 "I/O resource address %lx\n", val, 240 rman_get_start(reg)); 241 error = ENXIO; 242 goto done; 243 } 244#endif 245 246 /* Compare REV against known chip revisions. */ | 230 val = BAR_ADDRESS(val); 231 if (rman_get_start(reg) != val) { 232 if (bootverbose) 233 device_printf(dev, "BAR address %x does not match " 234 "I/O resource address %lx\n", val, 235 rman_get_start(reg)); 236 error = ENXIO; 237 goto done; 238 } 239#endif 240 241 /* Compare REV against known chip revisions. */ |
247 bus_space_write_2(bst, bsh, BSR, 3); 248 val = bus_space_read_2(bst, bsh, REV); | 242 bus_write_2(reg, BSR, 3); 243 val = bus_read_2(reg, REV); |
249 val = (val & REV_CHIP_MASK) >> REV_CHIP_SHIFT; 250 if (smc_chip_ids[val] == NULL) { 251 if (bootverbose) 252 device_printf(dev, "Unknown chip revision: %d\n", val); 253 error = ENXIO; 254 goto done; 255 } 256 --- 43 unchanged lines hidden (view full) --- 300 301 sc->smc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->smc_irq_rid, 0, 302 ~0, 1, RF_ACTIVE | RF_SHAREABLE); 303 if (sc->smc_irq == NULL) { 304 error = ENXIO; 305 goto done; 306 } 307 | 244 val = (val & REV_CHIP_MASK) >> REV_CHIP_SHIFT; 245 if (smc_chip_ids[val] == NULL) { 246 if (bootverbose) 247 device_printf(dev, "Unknown chip revision: %d\n", val); 248 error = ENXIO; 249 goto done; 250 } 251 --- 43 unchanged lines hidden (view full) --- 295 296 sc->smc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->smc_irq_rid, 0, 297 ~0, 1, RF_ACTIVE | RF_SHAREABLE); 298 if (sc->smc_irq == NULL) { 299 error = ENXIO; 300 goto done; 301 } 302 |
308 sc->smc_bst = rman_get_bustag(sc->smc_reg); 309 sc->smc_bsh = rman_get_bushandle(sc->smc_reg); 310 | |
311 SMC_LOCK(sc); 312 smc_reset(sc); 313 SMC_UNLOCK(sc); 314 315 smc_select_bank(sc, 3); 316 val = smc_read_2(sc, REV); 317 sc->smc_chip = (val & REV_CHIP_MASK) >> REV_CHIP_SHIFT; 318 sc->smc_rev = (val * REV_REV_MASK) >> REV_REV_SHIFT; --- 994 unchanged lines hidden --- | 303 SMC_LOCK(sc); 304 smc_reset(sc); 305 SMC_UNLOCK(sc); 306 307 smc_select_bank(sc, 3); 308 val = smc_read_2(sc, REV); 309 sc->smc_chip = (val & REV_CHIP_MASK) >> REV_CHIP_SHIFT; 310 sc->smc_rev = (val * REV_REV_MASK) >> REV_REV_SHIFT; --- 994 unchanged lines hidden --- |