Home | History | Annotate | Line # | Download | only in ifpga
      1 /*	$NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2013 Sergio Lopez <slp (at) sinrega.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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 
     36 #include <net/if.h>
     37 #include <net/if_ether.h>
     38 #include <net/if_media.h>
     39 
     40 #include <machine/intr.h>
     41 #include <sys/bus.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 <evbarm/ifpga/ifpgareg.h>
     50 #include <evbarm/ifpga/ifpgavar.h>
     51 
     52 static int	sm_ifpga_match(device_t, cfdata_t, void *);
     53 static void	sm_ifpga_attach(device_t, device_t, void *);
     54 
     55 struct sm_ifpga_softc {
     56 	struct smc91cxx_softc sc_sm;
     57 	void *ih;
     58 };
     59 
     60 CFATTACH_DECL_NEW(sm_ifpga, sizeof(struct sm_ifpga_softc), sm_ifpga_match,
     61     sm_ifpga_attach, NULL, NULL);
     62 
     63 static int
     64 sm_ifpga_match(device_t parent, cfdata_t match, void *aux)
     65 {
     66 	struct ifpga_attach_args *ifa = aux;
     67 
     68 	if (ifa->ifa_addr == IFPGA_SMC911_BASE)
     69 		return 1;
     70 	return 0;
     71 }
     72 
     73 static void
     74 sm_ifpga_attach(device_t parent, device_t self, void *aux)
     75 {
     76 	struct sm_ifpga_softc *isc = device_private(self);
     77 	struct smc91cxx_softc *sc = &isc->sc_sm;
     78 	struct ifpga_attach_args *ifa = aux;
     79 	bus_space_tag_t bst = ifa->ifa_iot;
     80 	bus_space_handle_t bsh;
     81 
     82 	/* map i/o space */
     83 	if (bus_space_map(bst, ifa->ifa_addr, SMC_IOSIZE, 0, &bsh) != 0) {
     84 		aprint_error(": sm_ifpga_attach: can't map i/o space");
     85 		return;
     86 	}
     87 
     88  	isc->ih = ifpga_intr_establish(ifa->ifa_irq, IPL_NET, smc91cxx_intr, sc);
     89 	if (isc->ih == NULL) {
     90 		aprint_error(": couldn't establish interrupt\n");
     91 		bus_space_unmap(bst, bsh, SMC_IOSIZE);
     92 		return;
     93 	}
     94 
     95 	aprint_normal("\n");
     96 
     97 	/* fill in master sc */
     98 	sc->sc_dev = self;
     99 	sc->sc_bst = bst;
    100 	sc->sc_bsh = bsh;
    101 
    102 	sc->sc_flags = SMC_FLAGS_ENABLED;
    103 	smc91cxx_attach(sc, NULL);
    104 }
    105 
    106