1/* $NetBSD: if_sm_emifs.c,v 1.3 2007/10/17 19:54:13 garbled Exp $ */ 2 3/* 4 * OSK5912 SMC91Cxx wrapper, based on sys/arch/evbarm/viper/if_sm_pxaip.c 5 * 6 * Copyright (c) 2005 Antti Kantee. All Rights Reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the company nor the name of the author may be used to 17 * endorse or promote products derived from this software without specific 18 * prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> 34__KERNEL_RCSID(0, "$NetBSD: if_sm_emifs.c,v 1.3 2007/10/17 19:54:13 garbled Exp $"); 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/device.h> 39 40#include <net/if.h> 41#include <net/if_ether.h> 42#include <net/if_media.h> 43 44#include <machine/intr.h> 45#include <sys/bus.h> 46 47#include <dev/mii/mii.h> 48#include <dev/mii/miivar.h> 49 50#include <dev/ic/smc91cxxreg.h> 51#include <dev/ic/smc91cxxvar.h> 52 53#include <arch/arm/omap/omap_emifs.h> 54#include <arch/arm/omap/omap_gpio.h> 55 56static int sm_emifs_match(struct device *, struct cfdata *, void *); 57static void sm_emifs_attach(struct device *, struct device *, void *); 58 59struct sm_emifs_softc { 60 struct smc91cxx_softc sc_sm; 61 void *ih; 62}; 63 64CFATTACH_DECL(sm_emifs, sizeof(struct sm_emifs_softc), sm_emifs_match, 65 sm_emifs_attach, NULL, NULL); 66 67static int 68sm_emifs_match(struct device *parent, struct cfdata *match, void *aux) 69{ 70 struct emifs_attach_args *emifs = aux; 71 72 if (emifs->emifs_addr == -1) 73 panic("sm must have addr specified in config."); 74 75 /* Trust the config file. */ 76 return (1); 77} 78 79static void 80sm_emifs_attach(struct device *parent, struct device *self, void *aux) 81{ 82 struct sm_emifs_softc *emifssc = (struct sm_emifs_softc *)self; 83 struct smc91cxx_softc *sc = &emifssc->sc_sm; 84 struct emifs_attach_args *emifs = aux; 85 bus_space_tag_t bst; 86 bus_space_handle_t bsh; 87 88 bst = emifs->emifs_iot; 89 90 /* map i/o space */ 91 if (bus_space_map(bst, emifs->emifs_addr, SMC_IOSIZE, 0, &bsh) != 0) { 92 aprint_error(": sm_emifs_attach: can't map i/o space"); 93 return; 94 } 95 96 aprint_normal("\n"); 97 98 /* fill in master sc */ 99 sc->sc_bst = bst; 100 sc->sc_bsh = bsh; 101 102 /* register the interrupt handler */ 103 emifssc->ih = 104 omap_gpio_intr_establish(emifs->emifs_intr, IST_EDGE_RISING, 105 IPL_NET, sc->sc_dev.dv_xname, 106 smc91cxx_intr, sc); 107 108 if (emifssc->ih == NULL) { 109 aprint_error(": couldn't establish interrupt\n"); 110 bus_space_unmap(bst, bsh, SMC_IOSIZE); 111 return; 112 } 113 114 /* Perform generic attach. */ 115 sc->sc_flags |= SMC_FLAGS_ENABLED; 116 smc91cxx_attach(sc, NULL); 117} 118 119