1 /* $NetBSD: if_sm_mainbus.c,v 1.4 2012/10/27 17:17:51 chs Exp $ */ 2 3 /*- 4 * Copyright (C) 2009 NONAKA Kimihiro <nonaka@netbsd.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: if_sm_mainbus.c,v 1.4 2012/10/27 17:17:51 chs Exp $"); 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/device.h> 34 #include <sys/bus.h> 35 36 #include <net/if.h> 37 #include <net/if_ether.h> 38 #include <net/if_media.h> 39 40 #include <machine/autoconf.h> 41 #include <machine/intr.h> 42 43 #include <dev/mii/mii.h> 44 #include <dev/mii/miivar.h> 45 46 #include <dev/ic/smc91cxxreg.h> 47 #include <dev/ic/smc91cxxvar.h> 48 49 #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4reg.h> 50 #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4var.h> 51 52 static int sm_mainbus_match(device_t, cfdata_t, void *); 53 static void sm_mainbus_attach(device_t, device_t, void *); 54 55 struct sm_mainbus_softc { 56 struct smc91cxx_softc sc_sm; 57 58 void *sc_ih; 59 }; 60 61 CFATTACH_DECL_NEW(sm_mainbus, sizeof(struct sm_mainbus_softc), 62 sm_mainbus_match, sm_mainbus_attach, NULL, NULL); 63 64 static int 65 sm_mainbus_match(device_t parent, cfdata_t cf, void *aux) 66 { 67 struct mainbus_attach_args *maa = (struct mainbus_attach_args *)aux; 68 69 if (strcmp(maa->ma_name, "sm") != 0) 70 return 0; 71 return 1; 72 } 73 74 static void 75 sm_mainbus_attach(device_t parent, device_t self, void *aux) 76 { 77 struct sm_mainbus_softc *smsc = device_private(self); 78 struct smc91cxx_softc *sc = &smsc->sc_sm; 79 bus_space_tag_t bst = &ap_ms104_sh4_bus_io; 80 bus_space_handle_t bsh; 81 82 aprint_naive("\n"); 83 aprint_normal("\n"); 84 85 /* map i/o space */ 86 if (bus_space_map(bst, 0x08000000, SMC_IOSIZE, 0, &bsh) != 0) { 87 aprint_error_dev(self, "can't map i/o space"); 88 return; 89 } 90 91 /* register the interrupt handler */ 92 smsc->sc_ih = extintr_establish(EXTINTR_INTR_SMC91C111, IST_LEVEL, 93 IPL_NET, smc91cxx_intr, sc); 94 if (smsc->sc_ih == NULL) { 95 aprint_error_dev(self, "couldn't establish interrupt\n"); 96 bus_space_unmap(bst, bsh, SMC_IOSIZE); 97 return; 98 } 99 100 /* fill in master sc */ 101 sc->sc_dev = self; 102 sc->sc_bst = bst; 103 sc->sc_bsh = bsh; 104 105 sc->sc_flags = SMC_FLAGS_ENABLED; 106 smc91cxx_attach(sc, NULL); 107 } 108