drsupio.c revision 1.23 1 1.23 thorpej /* $NetBSD: drsupio.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $ */
2 1.1 is
3 1.5 is /*-
4 1.6 is * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 is * All rights reserved.
6 1.1 is *
7 1.5 is * This code is derived from software contributed to The NetBSD Foundation
8 1.5 is * by Ignatios Souvatzis.
9 1.5 is *
10 1.1 is * Redistribution and use in source and binary forms, with or without
11 1.1 is * modification, are permitted provided that the following conditions
12 1.1 is * are met:
13 1.1 is * 1. Redistributions of source code must retain the above copyright
14 1.1 is * notice, this list of conditions and the following disclaimer.
15 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 is * notice, this list of conditions and the following disclaimer in the
17 1.1 is * documentation and/or other materials provided with the distribution.
18 1.1 is *
19 1.5 is * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.5 is * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.5 is * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.5 is * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.5 is * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.5 is * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.5 is * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.5 is * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.5 is * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.5 is * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.5 is * POSSIBILITY OF SUCH DAMAGE.
30 1.1 is */
31 1.10 aymeric
32 1.10 aymeric #include <sys/cdefs.h>
33 1.23 thorpej __KERNEL_RCSID(0, "$NetBSD: drsupio.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $");
34 1.1 is
35 1.1 is /*
36 1.1 is * DraCo multi-io chip bus space stuff
37 1.1 is */
38 1.1 is
39 1.1 is #include <sys/types.h>
40 1.1 is
41 1.1 is #include <sys/conf.h>
42 1.1 is #include <sys/device.h>
43 1.1 is #include <sys/systm.h>
44 1.1 is #include <sys/param.h>
45 1.20 dyoung #include <sys/bus.h>
46 1.1 is
47 1.1 is #include <amiga/include/cpu.h>
48 1.1 is
49 1.1 is #include <amiga/amiga/device.h>
50 1.1 is #include <amiga/amiga/drcustom.h>
51 1.1 is
52 1.1 is #include <amiga/dev/supio.h>
53 1.1 is
54 1.1 is struct drsupio_softc {
55 1.1 is struct bus_space_tag sc_bst;
56 1.1 is };
57 1.1 is
58 1.21 chs int drsupiomatch(device_t, cfdata_t, void *);
59 1.21 chs void drsupioattach(device_t, device_t, void *);
60 1.21 chs int drsupprint(void *, const char *);
61 1.9 aymeric void drlptintack(void *);
62 1.1 is
63 1.21 chs CFATTACH_DECL_NEW(drsupio, sizeof(struct drsupio_softc),
64 1.13 thorpej drsupiomatch, drsupioattach, NULL, NULL);
65 1.1 is
66 1.1 is int
67 1.21 chs drsupiomatch(device_t parent, cfdata_t cf, void *aux)
68 1.1 is {
69 1.8 kleink static int drsupio_matched = 0;
70 1.1 is
71 1.1 is /* Exactly one of us lives on the DraCo */
72 1.21 chs if (!is_draco() || !matchname(aux, "drsupio") || drsupio_matched)
73 1.8 kleink return 0;
74 1.1 is
75 1.8 kleink drsupio_matched = 1;
76 1.8 kleink return 1;
77 1.1 is }
78 1.1 is
79 1.1 is struct drsupio_devs {
80 1.16 jmc const char *name;
81 1.1 is int off;
82 1.2 is int arg;
83 1.1 is } drsupiodevs[] = {
84 1.2 is { "com", 0x3f8, 115200 * 16 },
85 1.2 is { "com", 0x2f8, 115200 * 16 },
86 1.3 is { "lpt", 0x278, (int)drlptintack },
87 1.2 is { "fdc", 0x3f0, 0 },
88 1.1 is /* WD port? */
89 1.1 is { 0 }
90 1.1 is };
91 1.1 is
92 1.1 is void
93 1.21 chs drsupioattach(device_t parent, device_t self, void *aux)
94 1.1 is {
95 1.1 is struct drsupio_softc *drsc;
96 1.1 is struct drsupio_devs *drsd;
97 1.3 is struct drioct *ioct;
98 1.1 is struct supio_attach_args supa;
99 1.1 is
100 1.21 chs drsc = device_private(self);
101 1.1 is drsd = drsupiodevs;
102 1.1 is
103 1.1 is if (parent)
104 1.1 is printf("\n");
105 1.1 is
106 1.15 thorpej drsc->sc_bst.base = DRCCADDR + PAGE_SIZE * DRSUPIOPG + 1;
107 1.7 is drsc->sc_bst.absm = &amiga_bus_stride_4;
108 1.9 aymeric
109 1.1 is supa.supio_iot = &drsc->sc_bst;
110 1.2 is supa.supio_ipl = 5;
111 1.1 is
112 1.1 is while (drsd->name) {
113 1.1 is supa.supio_name = drsd->name;
114 1.1 is supa.supio_iobase = drsd->off;
115 1.2 is supa.supio_arg = drsd->arg;
116 1.23 thorpej config_found(self, &supa, drsupprint, CFARGS_NONE); /* XXX */
117 1.1 is ++drsd;
118 1.1 is }
119 1.3 is
120 1.3 is drlptintack(0);
121 1.15 thorpej ioct = (struct drioct *)(DRCCADDR + PAGE_SIZE * DRIOCTLPG);
122 1.3 is ioct->io_status2 |= DRSTAT2_PARIRQENA;
123 1.3 is }
124 1.3 is
125 1.3 is void
126 1.9 aymeric drlptintack(void *p)
127 1.3 is {
128 1.3 is struct drioct *ioct;
129 1.3 is
130 1.3 is (void)p;
131 1.15 thorpej ioct = (struct drioct *)(DRCCADDR + PAGE_SIZE * DRIOCTLPG);
132 1.3 is
133 1.3 is ioct->io_parrst = 0; /* any value works */
134 1.1 is }
135 1.1 is
136 1.1 is int
137 1.21 chs drsupprint(void *aux, const char *pnp)
138 1.1 is {
139 1.1 is struct supio_attach_args *supa;
140 1.21 chs
141 1.21 chs supa = aux;
142 1.1 is
143 1.1 is if (pnp == NULL)
144 1.1 is return(QUIET);
145 1.1 is
146 1.14 thorpej aprint_normal("%s at %s port 0x%02x",
147 1.1 is supa->supio_name, pnp, supa->supio_iobase);
148 1.1 is
149 1.1 is return(UNCONF);
150 1.1 is }
151