Skip to content

Instantly share code, notes, and snippets.

@rkujawa
Created December 24, 2015 12:11
Show Gist options
  • Save rkujawa/4524f53ea03bb048845b to your computer and use it in GitHub Desktop.
Save rkujawa/4524f53ea03bb048845b to your computer and use it in GitHub Desktop.
/* $NetBSD$ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Radoslaw Kujawa.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD$");
/* Support for DM9000B on Z3SDRAM. */
#include <sys/param.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <amiga/amiga/device.h>
#include <amiga/amiga/isr.h>
#include <amiga/dev/zbusvar.h>
#include <dev/ic/dm9000reg.h>
#include <dev/ic/dm9000var.h>
#define Z3SDRAM_ETH_VENDOR 0x0A46
#define Z3SDRAM_ETH_DEVICE 0x9000
#define Z3SDRAM_ETH_INDEX 0x0
#define Z3SDRAM_ETH_DATA 0x1 /* stride 4, so 4*1 */
#define Z3SDRAM_ETH_SIZE 0x8
static int dme_zbus_match(device_t, cfdata_t , void *);
static void dme_zbus_attach(device_t, device_t, void *);
struct dme_zbus_softc {
struct dme_softc sc_sc;
struct bus_space_tag sc_bst;
struct isr sc_isr;
};
CFATTACH_DECL_NEW(dme_zbus, sizeof(struct dme_zbus_softc),
dme_zbus_match, dme_zbus_attach, NULL, NULL);
static int
dme_zbus_match(device_t parent, cfdata_t cf, void *aux)
{
struct zbus_args *zap = aux;
/* Ethernet on Z3SDRAM. */
if (zap->manid == Z3SDRAM_ETH_VENDOR &&
zap->prodid == Z3SDRAM_ETH_DEVICE) {
return 1;
}
return 0;
}
static void
dme_zbus_attach(device_t parent, device_t self, void *aux)
{
struct dme_zbus_softc *zsc;
struct dme_softc *sc;
struct zbus_args *zap;
uint8_t enaddr[ETHER_ADDR_LEN];
bus_space_tag_t iot;
bus_space_handle_t ioh;
zap = aux;
zsc = device_private(self);
sc = &zsc->sc_sc;
sc->sc_dev = self;
zsc->sc_bst.base = (bus_addr_t)zap->va;
zsc->sc_bst.absm = &amiga_bus_stride_4;
iot = &zsc->sc_bst;
aprint_normal(": Z3SDRAM Ethernet\n");
if (bus_space_map(iot, Z3SDRAM_ETH_INDEX, Z3SDRAM_ETH_SIZE, 0,
&ioh)) {
aprint_error_dev(sc->sc_dev, "can't map the bus\n");
}
sc->dme_io = Z3SDRAM_ETH_INDEX;
sc->dme_data = Z3SDRAM_ETH_DATA;
enaddr = { 0,0x0a,0xb1,0xc1,1,0xff };
/* Attach interrupt routine. */
zsc->sc_isr.isr_intr = dme_intr;
zsc->sc_isr.isr_arg = sc;
zsc->sc_isr.isr_ipl = 6;
add_isr(&zsc->sc_isr);
dme_attach(sc, enaddr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment