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