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