if_cs_smdk24x0.c revision 1.1
11.1Sbsh/*	$NetBSD: if_cs_smdk24x0.c,v 1.1 2003/08/29 13:54:03 bsh Exp $ */
21.1Sbsh
31.1Sbsh/*
41.1Sbsh * Copyright (c) 2003  Genetec corporation.  All rights reserved.
51.1Sbsh * Written by Hiroyuki Bessho for Genetec corporation.
61.1Sbsh *
71.1Sbsh * Redistribution and use in source and binary forms, with or without
81.1Sbsh * modification, are permitted provided that the following conditions
91.1Sbsh * are met:
101.1Sbsh * 1. Redistributions of source code must retain the above copyright
111.1Sbsh *    notice, this list of conditions and the following disclaimer.
121.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
131.1Sbsh *    notice, this list of conditions and the following disclaimer in the
141.1Sbsh *    documentation and/or other materials provided with the distribution.
151.1Sbsh * 3. The name of Genetec corporation may not be used to endorse
161.1Sbsh *    or promote products derived from this software without specific prior
171.1Sbsh *    written permission.
181.1Sbsh *
191.1Sbsh * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND
201.1Sbsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sbsh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORP.
231.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sbsh * POSSIBILITY OF SUCH DAMAGE.
301.1Sbsh */
311.1Sbsh
321.1Sbsh/* derived from sys/dev/isa/if_cs_isa.c */
331.1Sbsh/*
341.1Sbsh * Copyright 1997
351.1Sbsh * Digital Equipment Corporation. All rights reserved.
361.1Sbsh *
371.1Sbsh * This software is furnished under license and may be used and
381.1Sbsh * copied only in accordance with the following terms and conditions.
391.1Sbsh * Subject to these conditions, you may download, copy, install,
401.1Sbsh * use, modify and distribute this software in source and/or binary
411.1Sbsh * form. No title or ownership is transferred hereby.
421.1Sbsh *
431.1Sbsh * 1) Any source code used, modified or distributed must reproduce
441.1Sbsh *    and retain this copyright notice and list of conditions as
451.1Sbsh *    they appear in the source file.
461.1Sbsh *
471.1Sbsh * 2) No right is granted to use any trade name, trademark, or logo of
481.1Sbsh *    Digital Equipment Corporation. Neither the "Digital Equipment
491.1Sbsh *    Corporation" name nor any trademark or logo of Digital Equipment
501.1Sbsh *    Corporation may be used to endorse or promote products derived
511.1Sbsh *    from this software without the prior written permission of
521.1Sbsh *    Digital Equipment Corporation.
531.1Sbsh *
541.1Sbsh * 3) This software is provided "AS-IS" and any express or implied
551.1Sbsh *    warranties, including but not limited to, any implied warranties
561.1Sbsh *    of merchantability, fitness for a particular purpose, or
571.1Sbsh *    non-infringement are disclaimed. In no event shall DIGITAL be
581.1Sbsh *    liable for any damages whatsoever, and in particular, DIGITAL
591.1Sbsh *    shall not be liable for special, indirect, consequential, or
601.1Sbsh *    incidental damages or damages for lost profits, loss of
611.1Sbsh *    revenue or loss of use, whether such damages arise in contract,
621.1Sbsh *    negligence, tort, under statute, in equity, at law or otherwise,
631.1Sbsh *    even if advised of the possibility of such damage.
641.1Sbsh */
651.1Sbsh
661.1Sbsh/*
671.1Sbsh * driver for SMDK24[10]0's on-board CS8900A Ethernet
681.1Sbsh *
691.1Sbsh * CS8900A is located at CS3 area.
701.1Sbsh *    A24=1: I/O access
711.1Sbsh *    A24=0: Memory access
721.1Sbsh */
731.1Sbsh
741.1Sbsh#include <sys/cdefs.h>
751.1Sbsh__KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.1 2003/08/29 13:54:03 bsh Exp $");
761.1Sbsh
771.1Sbsh#include <sys/param.h>
781.1Sbsh#include <sys/systm.h>
791.1Sbsh#include <sys/socket.h>
801.1Sbsh#include <sys/device.h>
811.1Sbsh
821.1Sbsh#include "rnd.h"
831.1Sbsh#if NRND > 0
841.1Sbsh#include <sys/rnd.h>
851.1Sbsh#endif
861.1Sbsh
871.1Sbsh#include <net/if.h>
881.1Sbsh#include <net/if_ether.h>
891.1Sbsh#include <net/if_media.h>
901.1Sbsh
911.1Sbsh#include <machine/bus.h>
921.1Sbsh#include <machine/intr.h>
931.1Sbsh
941.1Sbsh#include <arch/arm/s3c2xx0/s3c2410reg.h>
951.1Sbsh#include <arch/arm/s3c2xx0/s3c2410var.h>
961.1Sbsh
971.1Sbsh#include <dev/ic/cs89x0reg.h>
981.1Sbsh#include <dev/ic/cs89x0var.h>
991.1Sbsh
1001.1Sbsh#include "locators.h"
1011.1Sbsh#include "opt_smdk2xx0.h"		/* SMDK24X0_ETHER_ADDR_FIXED */
1021.1Sbsh
1031.1Sbshint	cs_ssextio_probe(struct device *, struct cfdata *, void *);
1041.1Sbshvoid	cs_ssextio_attach(struct device *, struct device *, void *);
1051.1Sbsh
1061.1Sbsh/*
1071.1Sbsh * I/O access is done when A24==1.
1081.1Sbsh * default value for I/O base address is 0x300
1091.1Sbsh */
1101.1Sbsh#define IOADDR(base)	(base + (1<<24) + 0x0300)
1111.1Sbsh
1121.1SbshCFATTACH_DECL(cs_ssextio, sizeof(struct cs_softc),
1131.1Sbsh    cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
1141.1Sbsh
1151.1Sbshint
1161.1Sbshcs_ssextio_probe(struct device *parent, struct cfdata *cf, void *aux)
1171.1Sbsh{
1181.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1191.1Sbsh	bus_space_tag_t iot = sa->sa_iot;
1201.1Sbsh	bus_space_handle_t ioh;
1211.1Sbsh	struct cs_softc sc;
1221.1Sbsh	int rv = 0, have_io = 0;
1231.1Sbsh	vaddr_t ioaddr;
1241.1Sbsh
1251.1Sbsh	if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
1261.1Sbsh		sa->sa_intr = 9;
1271.1Sbsh	if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
1281.1Sbsh		sa->sa_addr = S3C2410_BANK_START(3);
1291.1Sbsh
1301.1Sbsh	/*
1311.1Sbsh	 * Map the I/O space.
1321.1Sbsh	 */
1331.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
1341.1Sbsh	if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
1351.1Sbsh		goto out;
1361.1Sbsh	have_io = 1;
1371.1Sbsh
1381.1Sbsh	memset(&sc, 0, sizeof sc);
1391.1Sbsh	sc.sc_iot = iot;
1401.1Sbsh	sc.sc_ioh = ioh;
1411.1Sbsh
1421.1Sbsh	if (0) {
1431.1Sbsh		int i;
1441.1Sbsh
1451.1Sbsh		for (i=0; i <=PKTPG_IND_ADDR; i += 2) {
1461.1Sbsh			if (i % 16 == 0)
1471.1Sbsh				printf( "\n%04x: ", i);
1481.1Sbsh			printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
1491.1Sbsh		}
1501.1Sbsh
1511.1Sbsh	}
1521.1Sbsh
1531.1Sbsh	/* Verify that it's a Crystal product. */
1541.1Sbsh	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
1551.1Sbsh		goto out;
1561.1Sbsh
1571.1Sbsh	/*
1581.1Sbsh	 * Verify that it's a supported chip.
1591.1Sbsh	 */
1601.1Sbsh	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
1611.1Sbsh	case PROD_ID_CS8900:
1621.1Sbsh#ifdef notyet
1631.1Sbsh	case PROD_ID_CS8920:
1641.1Sbsh	case PROD_ID_CS8920M:
1651.1Sbsh#endif
1661.1Sbsh		rv = 1;
1671.1Sbsh	}
1681.1Sbsh
1691.1Sbsh out:
1701.1Sbsh	if (have_io)
1711.1Sbsh		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
1721.1Sbsh
1731.1Sbsh	return (rv);
1741.1Sbsh}
1751.1Sbsh
1761.1Sbsh/* media selection: UTP only */
1771.1Sbshstatic int cs_media[] = {
1781.1Sbsh	IFM_ETHER|IFM_10_T,
1791.1Sbsh#if 0
1801.1Sbsh	IFM_ETHER|IFM_10_T|IFM_FDX,
1811.1Sbsh#endif
1821.1Sbsh};
1831.1Sbsh
1841.1Sbshvoid
1851.1Sbshcs_ssextio_attach(struct device *parent, struct device *self, void *aux)
1861.1Sbsh{
1871.1Sbsh	struct cs_softc *sc = (struct cs_softc *) self;
1881.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1891.1Sbsh	vaddr_t ioaddr;
1901.1Sbsh#ifdef	SMDK24X0_ETHER_ADDR_FIXED
1911.1Sbsh	static u_int8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
1921.1Sbsh#else
1931.1Sbsh#define enaddr NULL
1941.1Sbsh#endif
1951.1Sbsh
1961.1Sbsh	sc->sc_iot = sc->sc_memt = sa->sa_iot;
1971.1Sbsh	/* sc_irq is an IRQ number in ISA world. set 10 for INTRQ0 of CS8900A */
1981.1Sbsh	sc->sc_irq = 10;
1991.1Sbsh
2001.1Sbsh	/*
2011.1Sbsh	 * Map the device.
2021.1Sbsh	 */
2031.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
2041.1Sbsh	if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
2051.1Sbsh		aprint_error(": unable to map i/o space\n");
2061.1Sbsh		return;
2071.1Sbsh	}
2081.1Sbsh
2091.1Sbsh	if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
2101.1Sbsh			  0, &sc->sc_memh))
2111.1Sbsh		aprint_error(": unable to map memory space");
2121.1Sbsh	else {
2131.1Sbsh		sc->sc_cfgflags |= CFGFLG_MEM_MODE;
2141.1Sbsh		sc->sc_pktpgaddr = sa->sa_addr;
2151.1Sbsh	}
2161.1Sbsh
2171.1Sbsh	/* CS8900A is very slow. (nOE->Data valid: 135ns max.)
2181.1Sbsh	   We need to use IOCHRDY signal */
2191.1Sbsh	sc->sc_cfgflags |= CFGFLG_IOCHRDY;
2201.1Sbsh
2211.1Sbsh	sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING,
2221.1Sbsh	    cs_intr, sc);
2231.1Sbsh	if (sc->sc_ih == NULL) {
2241.1Sbsh		aprint_error(": unable to establish interrupt\n");
2251.1Sbsh		return;
2261.1Sbsh	}
2271.1Sbsh
2281.1Sbsh	aprint_normal("\n");
2291.1Sbsh
2301.1Sbsh	/* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
2311.1Sbsh	sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
2321.1Sbsh
2331.1Sbsh	cs_attach(sc, enaddr, cs_media,
2341.1Sbsh	    sizeof(cs_media) / sizeof(cs_media[0]), IFM_ETHER|IFM_10_T);
2351.1Sbsh}
236