11.8Smsaitoh/*	$NetBSD: if_cs_smdk24x0.c,v 1.8 2019/04/25 05:42:43 msaitoh 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.8Smsaitoh__KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.8 2019/04/25 05:42:43 msaitoh 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 <net/if.h>
831.1Sbsh#include <net/if_ether.h>
841.1Sbsh#include <net/if_media.h>
851.1Sbsh
861.4Sdyoung#include <sys/bus.h>
871.1Sbsh#include <machine/intr.h>
881.1Sbsh
891.1Sbsh#include <arch/arm/s3c2xx0/s3c2410reg.h>
901.1Sbsh#include <arch/arm/s3c2xx0/s3c2410var.h>
911.1Sbsh
921.1Sbsh#include <dev/ic/cs89x0reg.h>
931.1Sbsh#include <dev/ic/cs89x0var.h>
941.1Sbsh
951.1Sbsh#include "locators.h"
961.1Sbsh#include "opt_smdk2xx0.h"		/* SMDK24X0_ETHER_ADDR_FIXED */
971.1Sbsh
981.3Stsutsuiint	cs_ssextio_probe(device_t, cfdata_t, void *);
991.3Stsutsuivoid	cs_ssextio_attach(device_t, device_t, void *);
1001.1Sbsh
1011.1Sbsh/*
1021.1Sbsh * I/O access is done when A24==1.
1031.1Sbsh * default value for I/O base address is 0x300
1041.1Sbsh */
1051.1Sbsh#define IOADDR(base)	(base + (1<<24) + 0x0300)
1061.1Sbsh
1071.3StsutsuiCFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc),
1081.1Sbsh    cs_ssextio_probe, cs_ssextio_attach, NULL, NULL);
1091.1Sbsh
1101.1Sbshint
1111.3Stsutsuics_ssextio_probe(device_t parent, cfdata_t cf, void *aux)
1121.1Sbsh{
1131.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1141.1Sbsh	bus_space_tag_t iot = sa->sa_iot;
1151.1Sbsh	bus_space_handle_t ioh;
1161.1Sbsh	struct cs_softc sc;
1171.1Sbsh	int rv = 0, have_io = 0;
1181.1Sbsh	vaddr_t ioaddr;
1191.1Sbsh
1201.1Sbsh	if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT)
1211.1Sbsh		sa->sa_intr = 9;
1221.1Sbsh	if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT)
1231.1Sbsh		sa->sa_addr = S3C2410_BANK_START(3);
1241.1Sbsh
1251.8Smsaitoh	/* Map the I/O space. */
1261.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
1271.1Sbsh	if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh))
1281.1Sbsh		goto out;
1291.1Sbsh	have_io = 1;
1301.1Sbsh
1311.1Sbsh	memset(&sc, 0, sizeof sc);
1321.1Sbsh	sc.sc_iot = iot;
1331.1Sbsh	sc.sc_ioh = ioh;
1341.1Sbsh
1351.1Sbsh	if (0) {
1361.1Sbsh		int i;
1371.1Sbsh
1381.8Smsaitoh		for (i = 0; i <= PKTPG_IND_ADDR; i += 2) {
1391.1Sbsh			if (i % 16 == 0)
1401.1Sbsh				printf( "\n%04x: ", i);
1411.1Sbsh			printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i));
1421.1Sbsh		}
1431.1Sbsh
1441.1Sbsh	}
1451.1Sbsh
1461.1Sbsh	/* Verify that it's a Crystal product. */
1471.1Sbsh	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL)
1481.1Sbsh		goto out;
1491.1Sbsh
1501.8Smsaitoh	/* Verify that it's a supported chip. */
1511.1Sbsh	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) {
1521.1Sbsh	case PROD_ID_CS8900:
1531.1Sbsh#ifdef notyet
1541.1Sbsh	case PROD_ID_CS8920:
1551.1Sbsh	case PROD_ID_CS8920M:
1561.1Sbsh#endif
1571.1Sbsh		rv = 1;
1581.1Sbsh	}
1591.1Sbsh
1601.1Sbsh out:
1611.1Sbsh	if (have_io)
1621.1Sbsh		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
1631.1Sbsh
1641.8Smsaitoh	return rv;
1651.1Sbsh}
1661.1Sbsh
1671.1Sbsh/* media selection: UTP only */
1681.1Sbshstatic int cs_media[] = {
1691.8Smsaitoh	IFM_ETHER | IFM_10_T,
1701.1Sbsh#if 0
1711.8Smsaitoh	IFM_ETHER | IFM_10_T | IFM_FDX,
1721.1Sbsh#endif
1731.1Sbsh};
1741.1Sbsh
1751.1Sbshvoid
1761.3Stsutsuics_ssextio_attach(device_t parent, device_t self, void *aux)
1771.1Sbsh{
1781.3Stsutsui	struct cs_softc *sc = device_private(self);
1791.1Sbsh	struct s3c2xx0_attach_args *sa = aux;
1801.1Sbsh	vaddr_t ioaddr;
1811.1Sbsh#ifdef	SMDK24X0_ETHER_ADDR_FIXED
1821.6Sskrll	static uint8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED};
1831.1Sbsh#else
1841.1Sbsh#define enaddr NULL
1851.1Sbsh#endif
1861.1Sbsh
1871.3Stsutsui	sc->sc_dev = self;
1881.1Sbsh	sc->sc_iot = sc->sc_memt = sa->sa_iot;
1891.8Smsaitoh	/*
1901.8Smsaitoh	 * sc_irq is an IRQ number in ISA world. Set 10 for INTRQ0 of CS8900A.
1911.8Smsaitoh	 */
1921.1Sbsh	sc->sc_irq = 10;
1931.1Sbsh
1941.8Smsaitoh	/* Map the device. */
1951.1Sbsh	ioaddr = IOADDR(sa->sa_addr);
1961.1Sbsh	if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) {
1971.1Sbsh		aprint_error(": unable to map i/o space\n");
1981.1Sbsh		return;
1991.1Sbsh	}
2001.1Sbsh
2011.1Sbsh	if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE,
2021.1Sbsh			  0, &sc->sc_memh))
2031.1Sbsh		aprint_error(": unable to map memory space");
2041.1Sbsh	else {
2051.1Sbsh		sc->sc_cfgflags |= CFGFLG_MEM_MODE;
2061.1Sbsh		sc->sc_pktpgaddr = sa->sa_addr;
2071.1Sbsh	}
2081.1Sbsh
2091.8Smsaitoh	/*
2101.8Smsaitoh	 * CS8900A is very slow. (nOE->Data valid: 135ns max.)
2111.8Smsaitoh	 * We need to use IOCHRDY signal.
2121.8Smsaitoh	 */
2131.1Sbsh	sc->sc_cfgflags |= CFGFLG_IOCHRDY;
2141.1Sbsh
2151.8Smsaitoh	sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET,
2161.8Smsaitoh	    IST_EDGE_RISING, cs_intr, sc);
2171.1Sbsh	if (sc->sc_ih == NULL) {
2181.1Sbsh		aprint_error(": unable to establish interrupt\n");
2191.1Sbsh		return;
2201.1Sbsh	}
2211.1Sbsh
2221.1Sbsh	aprint_normal("\n");
2231.1Sbsh
2241.1Sbsh	/* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */
2251.1Sbsh	sc->sc_cfgflags |= CFGFLG_NOT_EEPROM;
2261.1Sbsh
2271.8Smsaitoh	cs_attach(sc, enaddr, cs_media, __arraycount(cs_media),
2281.8Smsaitoh	    IFM_ETHER | IFM_10_T);
2291.1Sbsh}
230