Home | History | Annotate | Line # | Download | only in lubbock
      1 /*	$NetBSD: if_sm_obio.c,v 1.7 2018/02/08 09:05:17 dholland Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
      5  * Written by Hiroyuki Bessho for Genetec Corporation.
      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  * 3. The name of Genetec Corporation may not be used to endorse or
     16  *    promote products derived from this software without specific prior
     17  *    written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  *
     31  * attach sm driver to Lubbock on-board bus
     32  * based on sys/dev/isa/if_sm_isa.c
     33  *
     34  */
     35 
     36 /*-
     37  * Copyright (c) 1997 The NetBSD Foundation, Inc.
     38  * All rights reserved.
     39  *
     40  * This code is derived from software contributed to The NetBSD Foundation
     41  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     42  * NASA Ames Research Center.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     54  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     55  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     56  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     57  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     58  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     59  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     60  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     61  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     62  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     63  * POSSIBILITY OF SUCH DAMAGE.
     64  */
     65 
     66 #include <sys/cdefs.h>
     67 __KERNEL_RCSID(0, "$NetBSD: if_sm_obio.c,v 1.7 2018/02/08 09:05:17 dholland Exp $");
     68 
     69 #include <sys/param.h>
     70 #include <sys/systm.h>
     71 #include <sys/mbuf.h>
     72 #include <sys/socket.h>
     73 #include <sys/ioctl.h>
     74 #include <sys/errno.h>
     75 #include <sys/syslog.h>
     76 #include <sys/select.h>
     77 #include <sys/device.h>
     78 
     79 #include <net/if.h>
     80 #include <net/if_dl.h>
     81 #include <net/if_ether.h>
     82 #include <net/if_media.h>
     83 
     84 #include <machine/intr.h>
     85 #include <sys/bus.h>
     86 
     87 #include <dev/mii/mii.h>
     88 #include <dev/mii/miivar.h>
     89 
     90 #include <dev/ic/smc91cxxreg.h>
     91 #include <dev/ic/smc91cxxvar.h>
     92 
     93 #include <evbarm/lubbock/lubbock_var.h>
     94 
     95 #include "opt_lubbock.h"	/* LUBBOCK_SMC91C96_16BIT */
     96 
     97 int	sm_obio_match(device_t, cfdata_t, void *);
     98 void	sm_obio_attach(device_t, device_t, void *);
     99 
    100 struct sm_obio_softc {
    101 	struct	smc91cxx_softc sc_smc;		/* real "smc" softc */
    102 
    103 	/* OBIO-specific goo. */
    104 	void	*sc_ih;				/* interrupt handler */
    105 };
    106 
    107 CFATTACH_DECL_NEW(sm_obio, sizeof(struct sm_obio_softc), sm_obio_match,
    108     sm_obio_attach, NULL, NULL);
    109 
    110 extern struct bus_space  smobio8_bs_tag;
    111 
    112 #ifndef SM_OBIO_INTR_PARANOIA
    113 # define smintr	smc91cxx_intr
    114 #else
    115 # define smintr smc_obio_intr
    116 
    117 static int
    118 smc_obio_intr(void *arg)
    119 {
    120 	while (smc91cxx_intr(arg))
    121 		;
    122 	return 1;
    123 }
    124 #endif /* SM_OBIO_INTR_PARANOIA */
    125 
    126 int
    127 sm_obio_match(device_t parent, cfdata_t match, void *aux)
    128 {
    129 	struct obio_attach_args *oba = aux;
    130 	bus_space_tag_t iot = &smobio8_bs_tag;
    131 	bus_space_handle_t ioh;
    132 	uint16_t tmp;
    133 	int rv = 0;
    134 	extern const char *smc91cxx_idstrs[];
    135 
    136 
    137 	/* Map i/o space. */
    138 	if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
    139 		return (0);
    140 
    141 
    142 	/* Check that high byte of BANK_SELECT is what we expect. */
    143 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    144 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    145 		goto out;
    146 
    147 	/*
    148 	 * Switch to bank 0 and perform the test again.
    149 	 * XXX INVASIVE!
    150 	 */
    151 	bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 0);
    152 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    153 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    154 		goto out;
    155 
    156 	/*
    157 	 * Check for a recognized chip id.
    158 	 * XXX INVASIVE!
    159 	 */
    160 	bus_space_write_1(iot, ioh, BANK_SELECT_REG_W, 3);
    161 	tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
    162 	if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
    163 		goto out;
    164 
    165 	/*
    166 	 * Assume we have an SMC91Cxx.
    167 	 */
    168 
    169 	rv = 1;
    170 
    171  out:
    172 	bus_space_unmap(iot, ioh, SMC_IOSIZE);
    173 	if (!rv) {
    174 		printf("on-board SMC probe failed\n");
    175 	}
    176 	return (rv);
    177 }
    178 
    179 void
    180 sm_obio_attach(device_t parent, device_t self, void *aux)
    181 {
    182 	struct sm_obio_softc *isc = device_private(self);
    183 	struct smc91cxx_softc *sc = &isc->sc_smc;
    184 	struct obio_attach_args *oba = aux;
    185 	bus_space_handle_t ioh;
    186 #ifdef LUBBOCK_SMC91C96_16BIT
    187 	bus_space_tag_t iot = &pxa2x0_a4x_bs_tag;
    188 #else
    189 	bus_space_tag_t iot = &smobio8_bs_tag;
    190 #endif
    191 
    192 
    193 	printf("\n");
    194 
    195 	/* Map i/o space. */
    196 	if (bus_space_map(iot, oba->oba_addr, SMC_IOSIZE, 0, &ioh))
    197 		panic("sm_obio_attach: can't map i/o space");
    198 
    199 #ifdef LUBBOCK_SMC91C96_16BIT
    200 	/* RedBoot initializes on-board SMSC91C96 in 8-bit mode.
    201 	   we take it back to 16-bit by clearing ECSR.IOIs8 */
    202 	{
    203 		int tmp;
    204 
    205 		bus_space_write_1(&smobio8_bs_tag, ioh, BANK_SELECT_REG_W, 4);
    206 		tmp = bus_space_read_1(&smobio8_bs_tag, ioh, ECSR_REG_B);
    207 		bus_space_write_1(&smobio8_bs_tag, ioh,
    208 		    ECSR_REG_B, tmp & ~ECSR_IOIS8);
    209 	}
    210 
    211 	obio16_write(LUBBOCK_MISCWR,
    212 	    obio16_read(LUBBOCK_MISCWR) & ~MISCWR_ENETEN16 );
    213 
    214 #else
    215 	/* Force 8bit mode */
    216 	obio16_write(LUBBOCK_MISCWR,
    217 	    obio16_read(LUBBOCK_MISCWR) | MISCWR_ENETEN16);
    218 
    219 #endif /* LUBBOCK_SMC91C96_16BIT */
    220 
    221 	sc->sc_dev = self;
    222 	sc->sc_bst = iot;
    223 	sc->sc_bsh = ioh;
    224 
    225 	/* should always be enabled */
    226 	sc->sc_flags |= SMC_FLAGS_ENABLED;
    227 
    228 	/* Perform generic initialization. */
    229 	smc91cxx_attach(sc, NULL);
    230 
    231 	/* Establish the interrupt handler. */
    232 	isc->sc_ih = obio_intr_establish(device_private(parent),
    233 					 oba->oba_intr, IPL_NET, smintr, sc);
    234 
    235 	if (isc->sc_ih == NULL)
    236 		aprint_normal_dev(self, "couldn't establish interrupt handler\n");
    237 }
    238