xref: /netbsd-src/sys/arch/amiga/dev/if_bah_zbus.c (revision 9fbd88883c38d0c0fbfcbe66d76fe6b0fab3f9de)
1 /*	$NetBSD: if_bah_zbus.c,v 1.8 2002/01/28 09:56:58 aymeric Exp $ */
2 
3 /*-
4  * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Ignatios Souvatzis.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: if_bah_zbus.c,v 1.8 2002/01/28 09:56:58 aymeric Exp $");
41 
42 /*
43  * Driver frontend for the Commodore Busines Machines and the
44  * Ameristar ARCnet card.
45  */
46 
47 #include <sys/types.h>
48 #include <sys/param.h>
49 
50 #include <sys/conf.h>
51 #include <sys/device.h>
52 #include <sys/mbuf.h>
53 #include <sys/socket.h>
54 #include <sys/systm.h>
55 #include <sys/kernel.h>
56 
57 #include <machine/bus.h>
58 #include <machine/cpu.h>
59 #include <machine/intr.h>
60 
61 #include <net/if.h>
62 #include <net/route.h>
63 
64 #include <net/if_arc.h>
65 
66 #include <amiga/amiga/device.h>
67 #include <amiga/dev/zbusvar.h>
68 
69 #include <dev/ic/smc90cx6var.h>
70 
71 /*
72  * A2060 software status per interface
73  */
74 struct bah_zbus_softc {
75 	struct	bah_softc	sc_bah;
76 	struct	bus_space_tag	sc_bst;
77 	struct	isr		sc_isr;
78 };
79 
80 int	bah_zbus_match(struct device *, struct cfdata *, void *);
81 void	bah_zbus_attach(struct device *, struct device *, void *);
82 void	bah_zbus_reset(struct bah_softc *, int);
83 
84 struct cfattach bah_zbus_ca = {
85 	sizeof(struct bah_zbus_softc), bah_zbus_match, bah_zbus_attach
86 };
87 
88 int
89 bah_zbus_match(struct device *parent, struct cfdata *cfp, void *aux)
90 {
91 	struct zbus_args *zap = aux;
92 
93 	if ((zap->manid == 514 || zap->manid == 1053) && zap->prodid == 9)
94 		return (1);
95 
96 	return (0);
97 }
98 
99 void
100 bah_zbus_attach(struct device *parent, struct device *self, void *aux)
101 {
102 	struct bah_zbus_softc *bsc = (void *)self;
103 	struct bah_softc *sc = &bsc->sc_bah;
104 	struct zbus_args *zap = aux;
105 
106 #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2))
107 	printf("\n%s: attach(0x%x, 0x%x, 0x%x)\n",
108 	    sc->sc_dev.dv_xname, parent, self, aux);
109 #endif
110 	bsc->sc_bst.base = (bus_addr_t)zap->va;
111 	bsc->sc_bst.absm = &amiga_bus_stride_2;
112 
113 	sc->sc_bst_r = &bsc->sc_bst;
114 	sc->sc_regs = bsc->sc_bst.base + 0x4000;
115 
116 	sc->sc_bst_m = &bsc->sc_bst;
117 	sc->sc_mem = bsc->sc_bst.base + 0x8000;
118 
119 	sc->sc_reset = bah_zbus_reset;
120 
121 	bah_attach_subr(sc);
122 
123 	bsc->sc_isr.isr_intr = bahintr;
124 	bsc->sc_isr.isr_arg = sc;
125 	bsc->sc_isr.isr_ipl = 2;
126 	add_isr(&bsc->sc_isr);
127 }
128 
129 void
130 bah_zbus_reset(struct bah_softc *sc, int onoff)
131 {
132 	struct bah_zbus_softc *bsc;
133 	volatile u_int8_t *p;
134 
135 	bsc = (struct bah_zbus_softc *)sc;
136 
137 	p = (volatile u_int8_t *)bsc->sc_bst.base;
138 
139 	p[0x0000] = 0;	/* A2060 reset flipflop */
140 	p[0xc000] = 0;	/* A560 reset flipflop */
141 
142 	if (!onoff)
143 		return;
144 
145 #ifdef M68060
146 	/* make sure we flush the store buffer before the delay */
147 	(void)p[0x8000];
148 #endif
149 	DELAY(200);
150 
151 	p[0x0000] = 0xff;
152 	p[0xc000] = 0xff;
153 
154 	return;
155 }
156