Home | History | Annotate | Line # | Download | only in g42xxeb
if_ne_obio.c revision 1.2.2.1
      1  1.2.2.1  yamt /*	$NetBSD: if_ne_obio.c,v 1.2.2.1 2006/03/01 09:27:46 yamt 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.2.2.1  yamt __KERNEL_RCSID(0, "$NetBSD: if_ne_obio.c,v 1.2.2.1 2006/03/01 09:27:46 yamt 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.1   bsh int	ne_obio_match( struct device *, struct cfdata *, void * );
     72      1.1   bsh void	ne_obio_attach( struct device *, struct device *, void * );
     73      1.1   bsh 
     74      1.1   bsh 
     75      1.1   bsh CFATTACH_DECL(ne_obio, sizeof (struct ne_obio_softc), ne_obio_match, ne_obio_attach,
     76      1.1   bsh     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.1   bsh 	printf("%s: enabled\n", dsc->sc_dev.dv_xname);
    121      1.1   bsh 
    122  1.2.2.1  yamt 	psc = (struct obio_softc *)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.1   bsh ne_obio_match( struct device *parent, struct cfdata *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.1   bsh ne_obio_attach( struct device *parent, struct device *self, void *aux )
    143      1.1   bsh {
    144      1.1   bsh 	struct ne_obio_softc *sc = (struct ne_obio_softc *)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.1   bsh 	printf("\n");
    152      1.1   bsh 
    153      1.1   bsh 	/* Map i/o space. */
    154      1.1   bsh 	if (bus_space_map(iot, oba->oba_addr, NE2000_NPORTS, 0, &nioh))
    155      1.1   bsh 		return;
    156      1.1   bsh 
    157      1.1   bsh 	if (bus_space_subregion(iot, nioh, NE2000_ASIC_OFFSET,
    158      1.1   bsh 	    NE2000_ASIC_NPORTS, &aioh))
    159      1.1   bsh 		goto out2;
    160      1.1   bsh 
    161      1.1   bsh 	sc->nsc.sc_dp8390.sc_regt = iot;
    162      1.1   bsh 	sc->nsc.sc_dp8390.sc_regh = nioh;
    163      1.1   bsh 
    164      1.1   bsh 	sc->nsc.sc_asict = iot;
    165      1.1   bsh 	sc->nsc.sc_asich = aioh;
    166      1.1   bsh 
    167      1.1   bsh 	/*
    168      1.1   bsh 	 * XXX:
    169      1.1   bsh 	 * AX88796's reset register doesn't seem to work, and
    170      1.1   bsh 	 * ne2000_detect() fails.  We hardcord NIC type here.
    171      1.1   bsh 	 */
    172      1.1   bsh 	sc->nsc.sc_type = NE2000_TYPE_NE2000; /* XXX _AX88796 ? */
    173      1.1   bsh 	sc->nsc.sc_dp8390.sc_flags = DP8390_NO_REMOTE_DMA_COMPLETE;
    174      1.1   bsh 	/* DP8390_NO_MULTI_BUFFERING; XXX */
    175      1.1   bsh 
    176      1.1   bsh 	/* G4250EBX doesn't have EEPROM hooked to AX88796.  Read MAC
    177      1.1   bsh 	 * address set by Redboot and don't let ne2000_atthch() try to
    178      1.1   bsh 	 * read MAC from hardware.  (current ne2000 driver doesn't
    179      1.1   bsh 	 * support AX88796's EEPROM interface)
    180      1.1   bsh 	 */
    181      1.1   bsh 
    182      1.1   bsh 	bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_1 );
    183      1.1   bsh 
    184      1.1   bsh 	for( i=0; i < ETHER_ADDR_LEN; ++i )
    185      1.1   bsh 		my_ea[i] = bus_space_read_1( iot, nioh, ED_P1_PAR0+i );
    186      1.1   bsh 
    187      1.1   bsh 	bus_space_write_1( iot, nioh, ED_P0_CR, ED_CR_RD2|ED_CR_PAGE_0 );
    188      1.1   bsh 
    189      1.1   bsh 	/* disable all interrupts */
    190      1.1   bsh 	bus_space_write_1(iot, nioh, ED_P0_IMR, 0);
    191      1.1   bsh 
    192      1.1   bsh #ifdef DEBUG_GPIO
    193      1.1   bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
    194      1.1   bsh 	    pxa2x0_softc->saip.sc_gpioh,
    195      1.1   bsh 	    GPIO_GPDR0, (0x01<<DEBUG_GPIO) | (0x01<<DEBUG_GPIO2) |
    196      1.1   bsh 	    bus_space_read_4(pxa2x0_softc->saip.sc_iot, pxa2x0_softc->saip.sc_gpioh,
    197      1.1   bsh 		GPIO_GPDR0));
    198      1.1   bsh 
    199      1.1   bsh #endif
    200      1.1   bsh 	/* delay intr_establish until this IF is enabled
    201      1.1   bsh 	   to avoid spurious interrupts. */
    202      1.1   bsh 	sc->nsc.sc_dp8390.sc_enabled = 0;
    203      1.1   bsh 	sc->nsc.sc_dp8390.sc_enable = ne_obio_enable;
    204      1.1   bsh 	sc->intr_no = oba->oba_intr;
    205      1.1   bsh 
    206      1.1   bsh 	if( ne2000_attach( &sc->nsc, my_ea ) )
    207      1.1   bsh 		goto out;
    208      1.1   bsh 
    209      1.1   bsh #ifndef ED_DCR_RDCR
    210      1.1   bsh #define ED_DCR_RDCR 0
    211      1.1   bsh #endif
    212      1.1   bsh 
    213      1.1   bsh 	bus_space_write_1(iot, nioh, ED_P0_DCR, ED_DCR_RDCR|ED_DCR_WTS);
    214      1.1   bsh 
    215      1.1   bsh 	return;
    216      1.1   bsh 
    217      1.1   bsh  out:
    218      1.1   bsh 	bus_space_unmap( iot, aioh, NE2000_ASIC_NPORTS );
    219      1.1   bsh  out2:
    220      1.1   bsh 	bus_space_unmap( iot, nioh, NE2000_NPORTS );
    221      1.1   bsh 	return;
    222      1.1   bsh }
    223      1.1   bsh 
    224      1.1   bsh #if 0
    225      1.1   bsh void debug_obio_ne(struct dp8390_softc *);
    226      1.1   bsh void
    227      1.1   bsh debug_obio_ne(struct dp8390_softc *sc)
    228      1.1   bsh {
    229  1.2.2.1  yamt 	struct obio_softc *osc =
    230  1.2.2.1  yamt 	    (struct obio_softc *)device_parent(&sc->sc_dev);
    231  1.2.2.1  yamt 	struct pxa2x0_softc *psc =
    232  1.2.2.1  yamt 	    (struct pxa2x0_softc *)device_parent(&osc->sc_dev);
    233      1.1   bsh 
    234      1.1   bsh 	printf( "ISR=%02x obio: pending=(%x,%x) mask=%x pending=%x mask=%x\n",
    235      1.1   bsh 	    bus_space_read_1(sc->sc_regt, sc->sc_regh,
    236      1.1   bsh 		ED_P0_ISR ),
    237      1.1   bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS1),
    238      1.1   bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTSTS2),
    239      1.1   bsh 	    bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G4250EBX_INTMASK),
    240      1.1   bsh 	    osc->sc_intr_pending,
    241      1.1   bsh 	    osc->sc_intr_mask );
    242      1.1   bsh 
    243      1.1   bsh 	printf( "intc: mask=%08x pending=%08x\n",
    244      1.1   bsh 	    bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_MR ),
    245      1.1   bsh 	    bus_space_read_4(psc->saip.sc_iot, psc->saip.sc_ioh, SAIPIC_IP ) );
    246      1.1   bsh }
    247      1.1   bsh #endif
    248      1.1   bsh 
    249      1.1   bsh #ifdef DEBUG_GPIO2
    250      1.1   bsh void dp8390_debug_overrun(void);
    251      1.1   bsh void dp8390_debug_overrun(void)
    252      1.1   bsh {
    253      1.1   bsh 	static int toggle=0;
    254      1.1   bsh 
    255      1.1   bsh 	//printf( "ne_obio_intr arg=%p\n", arg );
    256      1.1   bsh 	bus_space_write_4( pxa2x0_softc->saip.sc_iot,
    257      1.1   bsh 	    pxa2x0_softc->saip.sc_gpioh,
    258      1.1   bsh 	    toggle ? GPIO_GPCR0 : GPIO_GPSR0,
    259      1.1   bsh 			   1U<<DEBUG_GPIO2 );
    260      1.1   bsh 	toggle ^= 1;
    261      1.1   bsh 
    262      1.1   bsh }
    263      1.1   bsh #endif
    264