if_cm_isa.c revision 147256
189099Sfjoe/*	$NetBSD: if_bah_zbus.c,v 1.6 2000/01/23 21:06:12 aymeric Exp $ */
289099Sfjoe
3119418Sobrien#include <sys/cdefs.h>
4119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/cm/if_cm_isa.c 147256 2005-06-10 16:49:24Z brooks $");
5119418Sobrien
689099Sfjoe/*-
789099Sfjoe * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
889099Sfjoe * All rights reserved.
989099Sfjoe *
1089099Sfjoe * This code is derived from software contributed to The NetBSD Foundation
1189099Sfjoe * by Ignatios Souvatzis.
1289099Sfjoe *
1389099Sfjoe * Redistribution and use in source and binary forms, with or without
1489099Sfjoe * modification, are permitted provided that the following conditions
1589099Sfjoe * are met:
1689099Sfjoe * 1. Redistributions of source code must retain the above copyright
1789099Sfjoe *    notice, this list of conditions and the following disclaimer.
1889099Sfjoe * 2. Redistributions in binary form must reproduce the above copyright
1989099Sfjoe *    notice, this list of conditions and the following disclaimer in the
2089099Sfjoe *    documentation and/or other materials provided with the distribution.
2189099Sfjoe * 3. All advertising materials mentioning features or use of this software
2289099Sfjoe *    must display the following acknowledgement:
2389099Sfjoe *        This product includes software developed by the NetBSD
2489099Sfjoe *        Foundation, Inc. and its contributors.
2589099Sfjoe * 4. Neither the name of The NetBSD Foundation nor the names of its
2689099Sfjoe *    contributors may be used to endorse or promote products derived
2789099Sfjoe *    from this software without specific prior written permission.
2889099Sfjoe *
2989099Sfjoe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
3089099Sfjoe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
3189099Sfjoe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3289099Sfjoe * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3389099Sfjoe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3489099Sfjoe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3589099Sfjoe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3689099Sfjoe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3789099Sfjoe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3889099Sfjoe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3989099Sfjoe * POSSIBILITY OF SUCH DAMAGE.
4089099Sfjoe */
4189099Sfjoe
4289099Sfjoe#include <sys/param.h>
4389099Sfjoe#include <sys/systm.h>
4489099Sfjoe#include <sys/socket.h>
4589099Sfjoe#include <sys/kernel.h>
4689099Sfjoe
4789099Sfjoe#include <sys/module.h>
4889099Sfjoe#include <sys/bus.h>
4989099Sfjoe
5089099Sfjoe#include <machine/bus.h>
5189099Sfjoe
5289099Sfjoe#include <net/if.h>
5389099Sfjoe#include <net/if_arc.h>
5489099Sfjoe
5589099Sfjoe#include <dev/cm/smc90cx6var.h>
5689099Sfjoe
5792739Salfredstatic int cm_isa_probe		(device_t);
5892739Salfredstatic int cm_isa_attach	(device_t);
5989099Sfjoe
6089099Sfjoestatic int
6189099Sfjoecm_isa_probe(dev)
6289099Sfjoe	device_t dev;
6389099Sfjoe{
6489099Sfjoe	struct cm_softc *sc = device_get_softc(dev);
6589099Sfjoe	int error;
6689099Sfjoe
6789099Sfjoe	bzero(sc, sizeof(struct cm_softc));
6889099Sfjoe
6989099Sfjoe	error = cm_probe(dev);
7089099Sfjoe	if (error == 0)
7189099Sfjoe		goto end;
7289099Sfjoe
7389099Sfjoeend:
7489099Sfjoe	if (error == 0)
7589099Sfjoe		error = cm_alloc_irq(dev, 0);
7689099Sfjoe
7789099Sfjoe	cm_release_resources(dev);
7889099Sfjoe	return (error);
7989099Sfjoe}
8089099Sfjoe
8189099Sfjoestatic int
8289099Sfjoecm_isa_attach(dev)
8389099Sfjoe	device_t dev;
8489099Sfjoe{
8589099Sfjoe	struct cm_softc *sc = device_get_softc(dev);
8689099Sfjoe	int error;
8789099Sfjoe
8889099Sfjoe	cm_alloc_port(dev, sc->port_rid, sc->port_used);
8989099Sfjoe	cm_alloc_memory(dev, sc->mem_rid, sc->mem_used);
9089099Sfjoe	cm_alloc_irq(dev, sc->irq_rid);
9189099Sfjoe
9289099Sfjoe	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
9389099Sfjoe			       cmintr, sc, &sc->irq_handle);
9489099Sfjoe	if (error) {
9589099Sfjoe		cm_release_resources(dev);
9689099Sfjoe		return (error);
9789099Sfjoe	}
9889099Sfjoe
99121816Sbrooks	return cm_attach(dev);
10089099Sfjoe}
10189099Sfjoe
10289099Sfjoestatic int
10389099Sfjoecm_isa_detach(device_t dev)
10489099Sfjoe{
10589099Sfjoe	struct cm_softc *sc = device_get_softc(dev);
106147256Sbrooks	struct ifnet *ifp = sc->sc_ifp;
10789099Sfjoe	int s;
10889099Sfjoe
10989099Sfjoe	cm_stop(sc);
11089099Sfjoe	ifp->if_flags &= ~IFF_RUNNING;
11189099Sfjoe
11289099Sfjoe	s = splimp();
113147256Sbrooks	arc_ifdetach(ifp);
114147256Sbrooks	if_free(ifp);
11589099Sfjoe	splx(s);
11689099Sfjoe
11789099Sfjoe	bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
11889099Sfjoe	cm_release_resources(dev);
11989099Sfjoe
12089099Sfjoe	return (0);
12189099Sfjoe}
12289099Sfjoe
12389099Sfjoestatic device_method_t cm_isa_methods[] = {
12489099Sfjoe	/* Device interface */
12589099Sfjoe	DEVMETHOD(device_probe,		cm_isa_probe),
12689099Sfjoe	DEVMETHOD(device_attach,	cm_isa_attach),
12789099Sfjoe	DEVMETHOD(device_detach,	cm_isa_detach),
12889099Sfjoe
12989099Sfjoe	{ 0, 0 }
13089099Sfjoe};
13189099Sfjoe
13289099Sfjoestatic driver_t cm_isa_driver = {
13389099Sfjoe	"cm",
13489099Sfjoe	cm_isa_methods,
13589099Sfjoe	sizeof(struct cm_softc)
13689099Sfjoe};
13789099Sfjoe
138113506SmdoddDRIVER_MODULE(cm, isa, cm_isa_driver, cm_devclass, 0, 0);
139113506SmdoddMODULE_DEPEND(cm, isa, 1, 1, 1);
140