if_cs_smdk24x0.c revision 1.6
11.6Sskrll/*	$NetBSD: if_cs_smdk24x0.c,v 1.6 2012/11/12 18:00:39 skrll 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.6Sskrll__KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.6 2012/11/12 18:00:39 skrll 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 <sys/rnd.h>
831.1Sbsh
841.1Sbsh#include <net/if.h>
851.1Sbsh#include <net/if_ether.h>
861.1Sbsh#include <net/if_media.h>
871.1Sbsh
881.4Sdyoung#include <sys/bus.h>
891.1Sbsh#include <machine/intr.h>
901.1Sbsh
911.1Sbsh#include <arch/arm/s3c2xx0/s3c2410reg.h>
921.1Sbsh#include <arch/arm/s3c2xx0/s3c2410var.h>
931.1Sbsh
941.1Sbsh#include <dev/ic/cs89x0reg.h>
951.1Sbsh#include <dev/ic/cs89x0var.h>
961.1Sbsh
971.1Sbsh#include "locators.h"
981.1Sbsh#include "opt_smdk2xx0.h"		/* SMDK24X0_ETHER_ADDR_FIXED */
991.1Sbsh
1001.3Stsutsuiint	cs_ssextio_probe(device_t, cfdata_t, void *);
1011.3Stsutsuivoid	cs_ssextio_attach(device_t, device_t, void *);
1021.1Sbsh
1031.1Sbsh/*
1041.1Sbsh * I/O access is done when A24==1.
1051.1Sbsh * default value for I/O base address is 0x300
1061.1Sbsh */
1071.1Sbsh#define IOADDR(base)	(base + (1<<24) + 0x0300)
1081.1Sbsh
1091.3StsutsuiCFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc),
1101.1Sbsh    cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
1111.1Sbsh
1121.1Sbshint
1131.3Stsutsuics_ssextio_probe(device_t parent, cfdata_t cf, void *aux)
1141.1Sbsh{
1151.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1161.1Sbsh	bus_space_tag_t iot = sa->sa_iot;
1171.1Sbsh	bus_space_handle_t ioh;
1181.1Sbsh	struct cs_softc sc;
1191.1Sbsh	int rv = 0, have_io = 0;
1201.1Sbsh	vaddr_t ioaddr;
1211.1Sbsh
1221.1Sbsh	if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
1231.1Sbsh		sa->sa_intr = 9;
1241.1Sbsh	if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
1251.1Sbsh		sa->sa_addr = S3C2410_BANK_START(3);
1261.1Sbsh
1271.1Sbsh	/*
1281.1Sbsh	 * Map the I/O space.
1291.1Sbsh	 */
1301.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
1311.1Sbsh	if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
1321.1Sbsh		goto out;
1331.1Sbsh	have_io = 1;
1341.1Sbsh
1351.1Sbsh	memset(&sc, 0, sizeof sc);
1361.1Sbsh	sc.sc_iot = iot;
1371.1Sbsh	sc.sc_ioh = ioh;
1381.1Sbsh
1391.1Sbsh	if (0) {
1401.1Sbsh		int i;
1411.1Sbsh
1421.1Sbsh		for (i=0; i <=PKTPG_IND_ADDR; i += 2) {
1431.1Sbsh			if (i % 16 == 0)
1441.1Sbsh				printf( "\n%04x: ", i);
1451.1Sbsh			printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
1461.1Sbsh		}
1471.1Sbsh
1481.1Sbsh	}
1491.1Sbsh
1501.1Sbsh	/* Verify that it's a Crystal product. */
1511.1Sbsh	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
1521.1Sbsh		goto out;
1531.1Sbsh
1541.1Sbsh	/*
1551.1Sbsh	 * Verify that it's a supported chip.
1561.1Sbsh	 */
1571.1Sbsh	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
1581.1Sbsh	case PROD_ID_CS8900:
1591.1Sbsh#ifdef notyet
1601.1Sbsh	case PROD_ID_CS8920:
1611.1Sbsh	case PROD_ID_CS8920M:
1621.1Sbsh#endif
1631.1Sbsh		rv = 1;
1641.1Sbsh	}
1651.1Sbsh
1661.1Sbsh out:
1671.1Sbsh	if (have_io)
1681.1Sbsh		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
1691.1Sbsh
1701.1Sbsh	return (rv);
1711.1Sbsh}
1721.1Sbsh
1731.1Sbsh/* media selection: UTP only */
1741.1Sbshstatic int cs_media[] = {
1751.1Sbsh	IFM_ETHER|IFM_10_T,
1761.1Sbsh#if 0
1771.1Sbsh	IFM_ETHER|IFM_10_T|IFM_FDX,
1781.1Sbsh#endif
1791.1Sbsh};
1801.1Sbsh
1811.1Sbshvoid
1821.3Stsutsuics_ssextio_attach(device_t parent, device_t self, void *aux)
1831.1Sbsh{
1841.3Stsutsui	struct cs_softc *sc = device_private(self);
1851.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1861.1Sbsh	vaddr_t ioaddr;
1871.1Sbsh#ifdef	SMDK24X0_ETHER_ADDR_FIXED
1881.6Sskrll	static uint8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
1891.1Sbsh#else
1901.1Sbsh#define enaddr NULL
1911.1Sbsh#endif
1921.1Sbsh
1931.3Stsutsui	sc->sc_dev = self;
1941.1Sbsh	sc->sc_iot = sc->sc_memt = sa->sa_iot;
1951.1Sbsh	/* sc_irq is an IRQ number in ISA world. set 10 for INTRQ0 of CS8900A */
1961.1Sbsh	sc->sc_irq = 10;
1971.1Sbsh
1981.1Sbsh	/*
1991.1Sbsh	 * Map the device.
2001.1Sbsh	 */
2011.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
2021.1Sbsh	if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
2031.1Sbsh		aprint_error(": unable to map i/o space\n");
2041.1Sbsh		return;
2051.1Sbsh	}
2061.1Sbsh
2071.1Sbsh	if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
2081.1Sbsh			  0, &sc->sc_memh))
2091.1Sbsh		aprint_error(": unable to map memory space");
2101.1Sbsh	else {
2111.1Sbsh		sc->sc_cfgflags |= CFGFLG_MEM_MODE;
2121.1Sbsh		sc->sc_pktpgaddr = sa->sa_addr;
2131.1Sbsh	}
2141.1Sbsh
2151.1Sbsh	/* CS8900A is very slow. (nOE->Data valid: 135ns max.)
2161.1Sbsh	   We need to use IOCHRDY signal */
2171.1Sbsh	sc->sc_cfgflags |= CFGFLG_IOCHRDY;
2181.1Sbsh
2191.1Sbsh	sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING,
2201.1Sbsh	    cs_intr, sc);
2211.1Sbsh	if (sc->sc_ih == NULL) {
2221.1Sbsh		aprint_error(": unable to establish interrupt\n");
2231.1Sbsh		return;
2241.1Sbsh	}
2251.1Sbsh
2261.1Sbsh	aprint_normal("\n");
2271.1Sbsh
2281.1Sbsh	/* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
2291.1Sbsh	sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
2301.1Sbsh
2311.1Sbsh	cs_attach(sc, enaddr, cs_media,
2321.1Sbsh	    sizeof(cs_media) / sizeof(cs_media[0]), IFM_ETHER|IFM_10_T);
2331.1Sbsh}
234