1*4ecd76e5Srin /* $NetBSD: if_bah_zbus.c,v 1.18 2020/02/24 12:20:29 rin Exp $ */
2a3ee69c8Sis
3dc068e0dSis /*-
42c7fa23cSis * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
5a3ee69c8Sis * All rights reserved.
6a3ee69c8Sis *
7dc068e0dSis * This code is derived from software contributed to The NetBSD Foundation
8dc068e0dSis * by Ignatios Souvatzis.
9dc068e0dSis *
10a3ee69c8Sis * Redistribution and use in source and binary forms, with or without
11a3ee69c8Sis * modification, are permitted provided that the following conditions
12a3ee69c8Sis * are met:
13a3ee69c8Sis * 1. Redistributions of source code must retain the above copyright
14a3ee69c8Sis * notice, this list of conditions and the following disclaimer.
15a3ee69c8Sis * 2. Redistributions in binary form must reproduce the above copyright
16a3ee69c8Sis * notice, this list of conditions and the following disclaimer in the
17a3ee69c8Sis * documentation and/or other materials provided with the distribution.
18a3ee69c8Sis *
19dc068e0dSis * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20dc068e0dSis * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21dc068e0dSis * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22dc068e0dSis * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23dc068e0dSis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24dc068e0dSis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25dc068e0dSis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26dc068e0dSis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27dc068e0dSis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28dc068e0dSis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29dc068e0dSis * POSSIBILITY OF SUCH DAMAGE.
30a3ee69c8Sis */
31a3ee69c8Sis
3223b820a8Sphx #ifdef __m68k__
33bd01b4a3Smrg #include "opt_m68k_arch.h"
3423b820a8Sphx #endif
35bd01b4a3Smrg
361ea4df81Saymeric #include <sys/cdefs.h>
37*4ecd76e5Srin __KERNEL_RCSID(0, "$NetBSD: if_bah_zbus.c,v 1.18 2020/02/24 12:20:29 rin Exp $");
381ea4df81Saymeric
39a3ee69c8Sis /*
40a3ee69c8Sis * Driver frontend for the Commodore Busines Machines and the
41a3ee69c8Sis * Ameristar ARCnet card.
42a3ee69c8Sis */
43a3ee69c8Sis
44a3ee69c8Sis #include <sys/types.h>
45a3ee69c8Sis #include <sys/param.h>
46a3ee69c8Sis
47a3ee69c8Sis #include <sys/conf.h>
48a3ee69c8Sis #include <sys/device.h>
49a3ee69c8Sis #include <sys/mbuf.h>
50a3ee69c8Sis #include <sys/socket.h>
51a3ee69c8Sis #include <sys/systm.h>
52a3ee69c8Sis #include <sys/kernel.h>
533a45360bSdyoung #include <sys/bus.h>
54a3ee69c8Sis
55a3ee69c8Sis #include <machine/cpu.h>
56a3ee69c8Sis #include <machine/intr.h>
57a3ee69c8Sis
58a3ee69c8Sis #include <net/if.h>
59a3ee69c8Sis #include <net/route.h>
60a3ee69c8Sis
61a3ee69c8Sis #include <net/if_arc.h>
62a3ee69c8Sis
63a3ee69c8Sis #include <amiga/amiga/device.h>
64a3ee69c8Sis #include <amiga/dev/zbusvar.h>
65a3ee69c8Sis
66a3ee69c8Sis #include <dev/ic/smc90cx6var.h>
67a3ee69c8Sis
68a3ee69c8Sis /*
69a3ee69c8Sis * A2060 software status per interface
70a3ee69c8Sis */
71a3ee69c8Sis struct bah_zbus_softc {
72a3ee69c8Sis struct bah_softc sc_bah;
73a3ee69c8Sis struct bus_space_tag sc_bst;
74a3ee69c8Sis struct isr sc_isr;
75a3ee69c8Sis };
76a3ee69c8Sis
77cbab9cadSchs int bah_zbus_match(device_t, cfdata_t, void *);
78cbab9cadSchs void bah_zbus_attach(device_t, device_t, void *);
799382c873Saymeric void bah_zbus_reset(struct bah_softc *, int);
80a3ee69c8Sis
81cbab9cadSchs CFATTACH_DECL_NEW(bah_zbus, sizeof(struct bah_zbus_softc),
82c5e91d44Sthorpej bah_zbus_match, bah_zbus_attach, NULL, NULL);
83a3ee69c8Sis
84a3ee69c8Sis int
bah_zbus_match(device_t parent,cfdata_t cf,void * aux)85cbab9cadSchs bah_zbus_match(device_t parent, cfdata_t cf, void *aux)
86a3ee69c8Sis {
87a3ee69c8Sis struct zbus_args *zap = aux;
88a3ee69c8Sis
89a3ee69c8Sis if ((zap->manid == 514 || zap->manid == 1053) && zap->prodid == 9)
90a3ee69c8Sis return (1);
91a3ee69c8Sis
92a3ee69c8Sis return (0);
93a3ee69c8Sis }
94a3ee69c8Sis
95a3ee69c8Sis void
bah_zbus_attach(device_t parent,device_t self,void * aux)96cbab9cadSchs bah_zbus_attach(device_t parent, device_t self, void *aux)
97a3ee69c8Sis {
98cbab9cadSchs struct bah_zbus_softc *bsc = device_private(self);
99a3ee69c8Sis struct bah_softc *sc = &bsc->sc_bah;
100a3ee69c8Sis struct zbus_args *zap = aux;
101eba490a0Smsaitoh int rv;
102a3ee69c8Sis
103cbab9cadSchs sc->sc_dev = self;
104a3ee69c8Sis #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2))
105*4ecd76e5Srin printf("\n%s: attach(%p, %p, %p)\n",
106cbab9cadSchs device_xname(self), parent, self, aux);
107a3ee69c8Sis #endif
108a3ee69c8Sis bsc->sc_bst.base = (bus_addr_t)zap->va;
109d7e70f70Saymeric bsc->sc_bst.absm = &amiga_bus_stride_2;
110a3ee69c8Sis
111a3ee69c8Sis sc->sc_bst_r = &bsc->sc_bst;
112a3ee69c8Sis sc->sc_regs = bsc->sc_bst.base + 0x4000;
113a3ee69c8Sis
114a3ee69c8Sis sc->sc_bst_m = &bsc->sc_bst;
115a3ee69c8Sis sc->sc_mem = bsc->sc_bst.base + 0x8000;
116a3ee69c8Sis
117a3ee69c8Sis sc->sc_reset = bah_zbus_reset;
118a3ee69c8Sis
119eba490a0Smsaitoh rv = bah_attach_subr(sc);
120eba490a0Smsaitoh if (rv != 0) {
121eba490a0Smsaitoh aprint_error_dev(self, "bah_attach_subr failed(%d)\n", rv);
122eba490a0Smsaitoh return;
123eba490a0Smsaitoh }
124a3ee69c8Sis
125a3ee69c8Sis bsc->sc_isr.isr_intr = bahintr;
126a3ee69c8Sis bsc->sc_isr.isr_arg = sc;
127a3ee69c8Sis bsc->sc_isr.isr_ipl = 2;
128a3ee69c8Sis add_isr(&bsc->sc_isr);
129a3ee69c8Sis }
130a3ee69c8Sis
131a3ee69c8Sis void
bah_zbus_reset(struct bah_softc * sc,int onoff)1329382c873Saymeric bah_zbus_reset(struct bah_softc *sc, int onoff)
133a3ee69c8Sis {
134a3ee69c8Sis struct bah_zbus_softc *bsc;
135a3ee69c8Sis volatile u_int8_t *p;
136a3ee69c8Sis
137a3ee69c8Sis bsc = (struct bah_zbus_softc *)sc;
138a3ee69c8Sis
139a3ee69c8Sis p = (volatile u_int8_t *)bsc->sc_bst.base;
140a3ee69c8Sis
141a3ee69c8Sis p[0x0000] = 0; /* A2060 reset flipflop */
142a3ee69c8Sis p[0xc000] = 0; /* A560 reset flipflop */
143a3ee69c8Sis
144a3ee69c8Sis if (!onoff)
145a3ee69c8Sis return;
146a3ee69c8Sis
147a99b5503Sis #ifdef M68060
148a99b5503Sis /* make sure we flush the store buffer before the delay */
149a99b5503Sis (void)p[0x8000];
150a99b5503Sis #endif
151a3ee69c8Sis DELAY(200);
152a3ee69c8Sis
153a3ee69c8Sis p[0x0000] = 0xff;
154a3ee69c8Sis p[0xc000] = 0xff;
155a3ee69c8Sis
156a3ee69c8Sis return;
157a3ee69c8Sis }
158