1/*	$NetBSD: if_tr_isapnp.c,v 1.19 2009/05/12 10:07:55 cegger Exp $	*/
2
3/*
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Onno van der Linden.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: if_tr_isapnp.c,v 1.19 2009/05/12 10:07:55 cegger Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/callout.h>
38#include <sys/mbuf.h>
39#include <sys/socket.h>
40#include <sys/ioctl.h>
41#include <sys/errno.h>
42#include <sys/syslog.h>
43#include <sys/select.h>
44#include <sys/device.h>
45
46#include <net/if.h>
47#include <net/if_dl.h>
48#include <net/if_ether.h>
49#include <net/if_media.h>
50
51#include <sys/cpu.h>
52#include <sys/bus.h>
53#include <sys/intr.h>
54
55#include <dev/ic/tropicreg.h>
56#include <dev/ic/tropicvar.h>
57
58#include <dev/isa/isavar.h>
59
60#include <dev/isapnp/isapnpreg.h>
61#include <dev/isapnp/isapnpvar.h>
62#include <dev/isapnp/isapnpdevs.h>
63
64int	tr_isapnp_match(device_t, cfdata_t, void *);
65void	tr_isapnp_attach(device_t, device_t, void *);
66
67CFATTACH_DECL(tr_isapnp, sizeof(struct tr_softc),
68    tr_isapnp_match, tr_isapnp_attach, NULL, NULL);
69
70int
71tr_isapnp_match(device_t parent, cfdata_t match, void *aux)
72{
73	int pri, variant;
74
75	pri =  isapnp_devmatch(aux, &isapnp_tr_devinfo, &variant);
76	if (pri && variant > 0)
77		pri = 0;
78	return pri;
79}
80
81
82void
83tr_isapnp_attach(device_t parent, device_t self, void *aux)
84{
85	struct tr_softc *sc = device_private(self);
86	struct isapnp_attach_args *ipa = aux;
87	int mmioidx, sramidx;
88
89	printf("\n");
90
91	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
92		aprint_error_dev(&sc->sc_dev, "error in region allocation\n");
93		return;
94	}
95
96	printf("%s: %s %s\n", device_xname(&sc->sc_dev), ipa->ipa_devident,
97	    ipa->ipa_devclass);
98
99	sc->sc_piot = ipa->ipa_iot;
100	sc->sc_pioh = ipa->ipa_io[0].h;
101
102	if (strcmp(ipa->ipa_devlogic, "TCM3190") == 0) {
103		mmioidx = 0;
104		sramidx = 1;
105	}
106	else {	/* Default */
107		mmioidx = 1;
108		sramidx = 0;
109	}
110	sc->sc_memt = ipa->ipa_memt;
111	sc->sc_mmioh = ipa->ipa_mem[mmioidx].h;
112	sc->sc_sramh = ipa->ipa_mem[sramidx].h;
113	sc->sc_memwinsz = ipa->ipa_mem[sramidx].length;
114	/*
115	 * Determine total RAM on adapter and decide how much to use.
116	 * XXX Since we don't use RAM paging, use sc_memwinsz for now.
117	 */
118	sc->sc_memsize = sc->sc_memwinsz;
119	sc->sc_memreserved = 0;
120
121	sc->sc_aca = TR_ACA_OFFSET;
122	sc->sc_maddr = ipa->ipa_mem[sramidx].base;
123	/*
124	 * Reset the card.
125	 */
126	if (tr_reset(sc))
127		return;
128
129	sc->sc_mediastatus = NULL;
130	sc->sc_mediachange = NULL;
131
132	if (tr_attach(sc))
133		return;
134
135	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
136		ipa->ipa_irq[0].type, IPL_NET, tr_intr, sc);
137}
138