Home | History | Annotate | Line # | Download | only in g42xxeb
if_ne_obio.c revision 1.4.20.1
      1  1.4.20.1     matt /*	if_ne_obio.c,v 1.4 2007/03/04 05:59:44 christos Exp */
      2       1.1      bsh 
      3       1.1      bsh /*
      4       1.1      bsh  * Copyright (c) 2002, 2003  Genetec corp.  All rights reserved.
      5       1.1      bsh  * Written by Hiroyuki Bessho for Genetec corp.
      6       1.1      bsh  *
      7       1.1      bsh  * Redistribution and use in source and binary forms, with or without
      8       1.1      bsh  * modification, are permitted provided that the following conditions
      9       1.1      bsh  * are met:
     10       1.1      bsh  * 1. Redistributions of source code must retain the above copyright
     11       1.1      bsh  *    notice, this list of conditions and the following disclaimer.
     12       1.1      bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1      bsh  *    notice, this list of conditions and the following disclaimer in the
     14       1.1      bsh  *    documentation and/or other materials provided with the distribution.
     15       1.1      bsh  * 3. The name of Genetec corp. may not be used to endorse
     16       1.1      bsh  *    or promote products derived from this software without specific prior
     17       1.1      bsh  *    written permission.
     18       1.1      bsh  *
     19       1.1      bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND
     20       1.1      bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORP.
     23       1.1      bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      bsh  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      bsh  */
     31       1.1      bsh 
     32       1.1      bsh #include <sys/cdefs.h>
     33  1.4.20.1     matt __KERNEL_RCSID(0, "if_ne_obio.c,v 1.4 2007/03/04 05:59:44 christos Exp");
     34       1.1      bsh 
     35       1.1      bsh #include <sys/param.h>
     36       1.1      bsh #include <sys/systm.h>
     37       1.1      bsh #include <sys/mbuf.h>
     38       1.1      bsh #include <sys/socket.h>
     39       1.1      bsh #include <sys/ioctl.h>
     40       1.1      bsh #include <sys/errno.h>
     41       1.1      bsh #include <sys/syslog.h>
     42       1.1      bsh #include <sys/select.h>
     43       1.1      bsh #include <sys/device.h>
     44       1.1      bsh 
     45       1.1      bsh #include <net/if.h>
     46       1.1      bsh #include <net/if_dl.h>
     47       1.1      bsh #include <net/if_ether.h>
     48       1.1      bsh #include <net/if_media.h>
     49       1.1      bsh 
     50       1.1      bsh #include <machine/intr.h>
     51       1.1      bsh #include <machine/bus.h>
     52       1.1      bsh 
     53       1.1      bsh #include <dev/mii/mii.h>
     54       1.1      bsh #include <dev/mii/miivar.h>
     55       1.1      bsh 
     56       1.1      bsh #include <dev/ic/dp8390reg.h>
     57       1.1      bsh #include <dev/ic/dp8390var.h>
     58       1.1      bsh #include <dev/ic/ne2000reg.h>
     59       1.1      bsh #include <dev/ic/ne2000var.h>
     60       1.1      bsh 
     61       1.1      bsh #include <evbarm/g42xxeb/g42xxeb_var.h>
     62       1.1      bsh #include <arm/xscale/pxa2x0var.h>
     63       1.1      bsh 
     64       1.1      bsh struct ne_obio_softc {
     65       1.1      bsh 	struct ne2000_softc nsc;
     66       1.1      bsh 
     67       1.1      bsh 	void  *sc_ih;			/* interrupt handler */
     68       1.1      bsh 	int  intr_no;
     69       1.1      bsh };
     70       1.1      bsh 
     71  1.4.20.1     matt int	ne_obio_match(device_t, cfdata_t , void *);
     72  1.4.20.1     matt void	ne_obio_attach(device_t, device_t, void *);
     73       1.1      bsh 
     74       1.1      bsh 
     75  1.4.20.1     matt CFATTACH_DECL_NEW(ne_obio, sizeof (struct ne_obio_softc), ne_obio_match,
     76  1.4.20.1     matt     ne_obio_attach, NULL, NULL);
     77       1.1      bsh 
     78       1.1      bsh //#define DEBUG_GPIO  2
     79       1.1      bsh //#define DEBUG_GPIO2  5
     80       1.1      bsh 
     81       1.1      bsh #if 1
     82       1.1      bsh #define	intr_handler	dp8390_intr
     83       1.1      bsh #else
     84       1.1      bsh #define	intr_handler	ne_obio_intr
     85       1.1      bsh 
     86       1.1      bsh static int
     87       1.1      bsh ne_obio_intr(void *arg)
     88       1.1      bsh {
     89       1.1      bsh 	int rv=1;
     90       1.1      bsh 
     91       1.1      bsh #ifdef DEBUG_GPIO
     92       1.1      bsh 	//printf( "ne_obio_intr arg=%p\n", arg );
     93       1.1      bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
     94       1.1      bsh 	    pxa2x0_softc->saip.sc_gpioh,
     95       1.1      bsh 	    GPIO_GPSR0, 1U<<DEBUG_GPIO );
     96       1.1      bsh #endif
     97       1.1      bsh 
     98       1.1      bsh #if 0
     99       1.1      bsh 	while( (rv = dp8390_intr(arg)) != 0)
    100       1.1      bsh 		/*continue*/;
    101       1.1      bsh #else
    102       1.1      bsh 	rv = dp8390_intr(arg);
    103       1.1      bsh #endif
    104       1.1      bsh 
    105       1.1      bsh #ifdef DEBUG_GPIO
    106       1.1      bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
    107       1.1      bsh 	    pxa2x0_softc->saip.sc_gpioh,
    108       1.1      bsh 	    GPIO_GPCR0, 1U<<DEBUG_GPIO );
    109       1.1      bsh #endif
    110       1.1      bsh 	return rv;
    111       1.1      bsh }
    112       1.1      bsh #endif
    113       1.1      bsh 
    114       1.1      bsh static int
    115       1.1      bsh ne_obio_enable(struct dp8390_softc *dsc)
    116       1.1      bsh {
    117       1.1      bsh 	struct ne_obio_softc *sc = (struct ne_obio_softc *)dsc;
    118       1.1      bsh 	struct obio_softc *psc;
    119       1.1      bsh 
    120  1.4.20.1     matt 	aprint_normal_dev(dsc->sc_dev, "enabled\n");
    121       1.1      bsh 
    122  1.4.20.1     matt 	psc = device_private(device_parent(dsc->sc_dev));
    123       1.1      bsh 
    124       1.1      bsh 	/* Establish the interrupt handler. */
    125       1.1      bsh 	sc->sc_ih = obio_intr_establish(psc, sc->intr_no, IPL_NET,
    126       1.1      bsh 	    IST_LEVEL_LOW,
    127       1.1      bsh 	    intr_handler,
    128       1.1      bsh 	    sc);
    129       1.1      bsh 
    130       1.1      bsh 	return 0;
    131       1.1      bsh }
    132       1.1      bsh 
    133       1.1      bsh 
    134       1.1      bsh int
    135  1.4.20.1     matt ne_obio_match(device_t parent, cfdata_t match, void *aux )
    136       1.1      bsh {
    137       1.1      bsh 	/* XXX: probe? */
    138       1.1      bsh 	return 1;
    139       1.1      bsh }
    140       1.1      bsh 
    141       1.1      bsh void
    142  1.4.20.1     matt ne_obio_attach(device_t parent, device_t self, void *aux )
    143       1.1      bsh {
    144  1.4.20.1     matt 	struct ne_obio_softc *sc = device_private(self);
    145       1.1      bsh 	struct obio_attach_args *oba = aux;
    146       1.1      bsh 	bus_space_tag_t iot = oba->oba_iot;
    147       1.1      bsh 	bus_space_handle_t  nioh, aioh;
    148       1.1      bsh 	uint8_t my_ea[ETHER_ADDR_LEN];
    149       1.1      bsh 	int i;
    150       1.1      bsh 
    151  1.4.20.1     matt 	aprint_normal("\n");
    152  1.4.20.1     matt 	sc->nsc.sc_dp8390.sc_dev = self;
    153       1.1      bsh 
    154       1.1      bsh 	/* Map i/o space. */
    155       1.1      bsh 	if (bus_space_map(iot, oba->oba_addr, NE2000_NPORTS, 0, &nioh))
    156       1.1      bsh 		return;
    157       1.1      bsh 
    158       1.1      bsh 	if (bus_space_subregion(iot, nioh, NE2000_ASIC_OFFSET,
    159       1.1      bsh 	    NE2000_ASIC_NPORTS, &aioh))
    160       1.1      bsh 		goto out2;
    161       1.1      bsh 
    162       1.1      bsh 	sc->nsc.sc_dp8390.sc_regt = iot;
    163       1.1      bsh 	sc->nsc.sc_dp8390.sc_regh = nioh;
    164       1.1      bsh 
    165       1.1      bsh 	sc->nsc.sc_asict = iot;
    166       1.1      bsh 	sc->nsc.sc_asich = aioh;
    167       1.1      bsh 
    168       1.1      bsh 	/*
    169       1.1      bsh 	 * XXX:
    170       1.1      bsh 	 * AX88796's reset register doesn't seem to work, and
    171       1.1      bsh 	 * ne2000_detect() fails.  We hardcord NIC type here.
    172       1.1      bsh 	 */
    173       1.1      bsh 	sc->nsc.sc_type = NE2000_TYPE_NE2000; /* XXX _AX88796 ? */
    174       1.1      bsh 	sc->nsc.sc_dp8390.sc_flags = DP8390_NO_REMOTE_DMA_COMPLETE;
    175       1.1      bsh 	/* DP8390_NO_MULTI_BUFFERING; XXX */
    176       1.1      bsh 
    177       1.1      bsh 	/* G4250EBX doesn't have EEPROM hooked to AX88796.  Read MAC
    178       1.1      bsh 	 * address set by Redboot and don't let ne2000_atthch() try to
    179       1.1      bsh 	 * read MAC from hardware.  (current ne2000 driver doesn't
    180       1.1      bsh 	 * support AX88796's EEPROM interface)
    181       1.1      bsh 	 */
    182       1.1      bsh 
    183       1.1      bsh 	bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_1 );
    184       1.1      bsh 
    185       1.1      bsh 	for( i=0; i < ETHER_ADDR_LEN; ++i )
    186       1.1      bsh 		my_ea[i] = bus_space_read_1( iot, nioh, ED_P1_PAR0+i );
    187       1.1      bsh 
    188       1.1      bsh 	bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_0 );
    189       1.1      bsh 
    190       1.1      bsh 	/* disable all interrupts */
    191       1.1      bsh 	bus_space_write_1(iot, nioh, ED_P0_IMR, 0);
    192       1.1      bsh 
    193       1.1      bsh #ifdef DEBUG_GPIO
    194       1.1      bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
    195       1.1      bsh 	    pxa2x0_softc->saip.sc_gpioh,
    196       1.1      bsh 	    GPIO_GPDR0, (0x01<<DEBUG_GPIO) | (0x01<<DEBUG_GPIO2) |
    197       1.1      bsh 	    bus_space_read_4(pxa2x0_softc->saip.sc_iot, pxa2x0_softc->saip.sc_gpioh,
    198       1.1      bsh 		GPIO_GPDR0));
    199       1.1      bsh 
    200       1.1      bsh #endif
    201       1.1      bsh 	/* delay intr_establish until this IF is enabled
    202       1.1      bsh 	   to avoid spurious interrupts. */
    203       1.1      bsh 	sc->nsc.sc_dp8390.sc_enabled = 0;
    204       1.1      bsh 	sc->nsc.sc_dp8390.sc_enable = ne_obio_enable;
    205       1.1      bsh 	sc->intr_no = oba->oba_intr;
    206       1.1      bsh 
    207       1.1      bsh 	if( ne2000_attach( &sc->nsc, my_ea ) )
    208       1.1      bsh 		goto out;
    209       1.1      bsh 
    210       1.1      bsh #ifndef ED_DCR_RDCR
    211       1.1      bsh #define ED_DCR_RDCR 0
    212       1.1      bsh #endif
    213       1.1      bsh 
    214       1.1      bsh 	bus_space_write_1(iot, nioh, ED_P0_DCR, ED_DCR_RDCR|ED_DCR_WTS);
    215       1.1      bsh 
    216       1.1      bsh 	return;
    217       1.1      bsh 
    218       1.1      bsh  out:
    219       1.1      bsh 	bus_space_unmap( iot, aioh, NE2000_ASIC_NPORTS );
    220       1.1      bsh  out2:
    221       1.1      bsh 	bus_space_unmap( iot, nioh, NE2000_NPORTS );
    222       1.1      bsh 	return;
    223       1.1      bsh }
    224       1.1      bsh 
    225       1.1      bsh #if 0
    226       1.1      bsh void debug_obio_ne(struct dp8390_softc *);
    227       1.1      bsh void
    228       1.1      bsh debug_obio_ne(struct dp8390_softc *sc)
    229       1.1      bsh {
    230       1.3  thorpej 	struct obio_softc *osc =
    231       1.3  thorpej 	    (struct obio_softc *)device_parent(&sc->sc_dev);
    232       1.3  thorpej 	struct pxa2x0_softc *psc =
    233       1.3  thorpej 	    (struct pxa2x0_softc *)device_parent(&osc->sc_dev);
    234       1.1      bsh 
    235       1.1      bsh 	printf( "ISR=%02x obio: pending=(%x,%x) mask=%x pending=%x mask=%x\n",
    236       1.1      bsh 	    bus_space_read_1(sc->sc_regt, sc->sc_regh,
    237       1.1      bsh 		ED_P0_ISR ),
    238       1.1      bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS1),
    239       1.1      bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS2),
    240       1.1      bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTMASK),
    241       1.1      bsh 	    osc->sc_intr_pending,
    242       1.1      bsh 	    osc->sc_intr_mask );
    243       1.1      bsh 
    244       1.1      bsh 	printf( "intc: mask=%08x pending=%08x\n",
    245       1.1      bsh 	    bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_MR ),
    246       1.1      bsh 	    bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_IP ) );
    247       1.1      bsh }
    248       1.1      bsh #endif
    249       1.1      bsh 
    250       1.1      bsh #ifdef DEBUG_GPIO2
    251       1.1      bsh void dp8390_debug_overrun(void);
    252       1.1      bsh void dp8390_debug_overrun(void)
    253       1.1      bsh {
    254       1.1      bsh 	static int toggle=0;
    255       1.1      bsh 
    256       1.1      bsh 	//printf( "ne_obio_intr arg=%p\n", arg );
    257       1.1      bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
    258       1.1      bsh 	    pxa2x0_softc->saip.sc_gpioh,
    259       1.1      bsh 	    toggle ? GPIO_GPCR0 : GPIO_GPSR0,
    260       1.1      bsh 			   1U<<DEBUG_GPIO2 );
    261       1.1      bsh 	toggle ^= 1;
    262       1.1      bsh 
    263       1.1      bsh }
    264       1.1      bsh #endif
    265