1 /* $NetBSD: amps.c,v 1.16 2009/03/14 21:04:01 dsl Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mark Brinicombe of Causality Limited.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
31 * Card driver and probe and attach functions to use generic 16550 com
32 * driver for the Atomwide multiport serial podule
36 * Thanks to Martin Coulson, Atomwide, for providing the hardware
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: amps.c,v 1.16 2009/03/14 21:04:01 dsl Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/ioctl.h>
45 #include <sys/select.h>
51 #include <sys/kernel.h>
52 #include <sys/syslog.h>
53 #include <sys/types.h>
54 #include <sys/device.h>
56 #include <machine/intr.h>
57 #include <machine/io.h>
58 #include <machine/bus.h>
59 #include <acorn32/podulebus/podulebus.h>
60 #include <acorn32/podulebus/ampsreg.h>
61 #include <dev/ic/comreg.h>
62 #include <dev/ic/comvar.h>
63 #include <dev/podulebus/podules.h>
68 * Atomwide Mulit-port serial podule device.
70 * This probes and attaches the top level multi-port serial device to the
71 * podulebus. It then configures the child com devices.
75 * Atomwide Multi-port serial card softc structure.
77 * Contains the device node, podule information and global information
78 * required by the driver such as the card version and the interrupt mask.
82 struct device sc_dev
; /* device node */
83 podule_t
*sc_podule
; /* Our podule info */
84 int sc_podule_number
; /* Our podule number */
85 bus_space_tag_t sc_iot
; /* Bus tag */
88 int amps_probe(struct device
*, struct cfdata
*, void *);
89 void amps_attach(struct device
*, struct device
*, void *);
91 CFATTACH_DECL(amps
, sizeof(struct amps_softc
),
92 amps_probe
, amps_attach
, NULL
, NULL
);
94 int amps_print(void *, const char *);
95 void amps_shutdown(void *);
98 * Attach arguments for child devices.
99 * Pass the podule details, the parent softc and the channel
102 struct amps_attach_args
{
103 bus_space_tag_t aa_iot
; /* bus space tag */
104 unsigned int aa_base
; /* base address for port */
105 int aa_port
; /* serial port number */
106 podulebus_intr_handle_t aa_irq
; /* IRQ number */
110 * Define prototypes for custom bus space functions.
113 /* Print function used during child config */
116 amps_print(void *aux
, const char *name
)
118 struct amps_attach_args
*aa
= aux
;
121 aprint_normal(", port %d", aa
->aa_port
);
127 * Card probe function
129 * Just match the manufacturer and podule ID's
133 amps_probe(struct device
*parent
, struct cfdata
*cf
, void *aux
)
135 struct podule_attach_args
*pa
= (void *)aux
;
137 return (pa
->pa_product
== PODULE_ATOMWIDE_SERIAL
);
141 * Card attach function
143 * Identify the card version and configure any children.
144 * Install a shutdown handler to kill interrupts on shutdown
148 amps_attach(struct device
*parent
, struct device
*self
, void *aux
)
150 struct amps_softc
*sc
= (void *)self
;
151 struct podule_attach_args
*pa
= (void *)aux
;
152 struct amps_attach_args aa
;
154 /* Note the podule number and validate */
156 if (pa
->pa_podule_number
== -1)
157 panic("Podule has disappeared !");
159 sc
->sc_podule_number
= pa
->pa_podule_number
;
160 sc
->sc_podule
= pa
->pa_podule
;
161 podules
[sc
->sc_podule_number
].attached
= 1;
163 sc
->sc_iot
= pa
->pa_iot
;
165 /* Install a clean up handler to make sure IRQ's are disabled */
166 /* if (shutdownhook_establish(amps_shutdown, (void *)sc) == NULL)
167 panic("%s: Cannot install shutdown handler", self->dv_xname);*/
169 /* Set the interrupt info for this podule */
171 /* sc->sc_podule->irq_addr = pa->pa_podule->slow_base +;*/ /* XXX */
172 /* sc->sc_podule->irq_mask = ;*/
176 /* Configure the children */
178 aa
.aa_iot
= sc
->sc_iot
;
179 aa
.aa_base
= pa
->pa_podule
->slow_base
+ AMPS_BASE_OFFSET
;
180 aa
.aa_base
+= MAX_AMPS_PORTS
* AMPS_PORT_SPACING
;
181 aa
.aa_irq
= pa
->pa_podule
->interrupt
;
182 for (aa
.aa_port
= 0; aa
.aa_port
< MAX_AMPS_PORTS
; ++aa
.aa_port
) {
183 aa
.aa_base
-= AMPS_PORT_SPACING
;
184 config_found(self
, &aa
, amps_print
);
189 * Card shutdown function
191 * Called via do_shutdown_hooks() during kernel shutdown.
192 * Clear the cards's interrupt mask to stop any podule interrupts.
196 amps_shutdown(void *arg)
201 * Atomwide Multi-Port Serial probe and attach code for the com device.
203 * This provides a different pair of probe and attach functions
204 * for attaching the com device (dev/ic/com.c) to the Atomwide serial card.
207 struct com_amps_softc
{
208 struct com_softc sc_com
; /* real "com" softc */
209 void *sc_ih
; /* interrupt handler */
210 struct evcnt sc_intrcnt
; /* interrupt count */
213 /* Prototypes for functions */
215 static int com_amps_probe (device_t
, cfdata_t
, void *);
216 static void com_amps_attach (device_t
, device_t
, void *);
218 /* device attach structure */
220 CFATTACH_DECL_NEW(com_amps
, sizeof(struct com_amps_softc
),
221 com_amps_probe
, com_amps_attach
, NULL
, NULL
);
224 * Controller probe function
226 * Map all the required I/O space for this channel, make sure interrupts
227 * are disabled and probe the bus.
231 com_amps_probe(device_t parent
, cfdata_t cf
, void *aux
)
234 bus_space_handle_t ioh
;
237 struct amps_attach_args
*aa
= aux
;
240 iobase
= aa
->aa_base
;
242 /* if it's in use as console, it's there. */
243 if (!com_is_console(iot
, iobase
, 0)) {
244 if (bus_space_map(iot
, iobase
, COM_NPORTS
, 0, &ioh
)) {
248 * We don't use the generic comprobe1() function as it
249 * is not good enough to identify which ports are present.
251 * Instead test for the presence of the scratch register
254 bus_space_write_1(iot
, ioh
, com_scratch
, 0x55);
255 bus_space_write_1(iot
, ioh
, com_ier
, 0);
256 (void)bus_space_read_1(iot
, ioh
, com_data
);
257 if (bus_space_read_1(iot
, ioh
, com_scratch
) != 0x55)
259 bus_space_write_1(iot
, ioh
, com_scratch
, 0xaa);
260 bus_space_write_1(iot
, ioh
, com_ier
, 0);
261 (void)bus_space_read_1(iot
, ioh
, com_data
);
262 if (bus_space_read_1(iot
, ioh
, com_scratch
) != 0xaa)
265 bus_space_unmap(iot
, ioh
, COM_NPORTS
);
271 * Controller attach function
273 * Map all the required I/O space for this port and attach the driver
274 * The generic attach will probe and attach any device.
275 * Install an interrupt handler and we are ready to rock.
279 com_amps_attach(device_t parent
, device_t self
, void *aux
)
281 struct com_amps_softc
*asc
= device_private(self
);
282 struct com_softc
*sc
= &asc
->sc_com
;
285 bus_space_handle_t ioh
;
286 struct amps_attach_args
*aa
= aux
;
290 iobase
= aa
->aa_base
;
292 if (!com_is_console(iot
, iobase
, &ioh
)
293 && bus_space_map(iot
, iobase
, COM_NPORTS
, 0, &ioh
))
294 panic("comattach: io mapping failed");
295 COM_INIT_REGS(sc
->sc_regs
, iot
, ioh
, iobase
);
297 sc
->sc_frequency
= AMPS_FREQ
;
300 evcnt_attach_dynamic(&asc
->sc_intrcnt
, EVCNT_TYPE_INTR
, NULL
,
301 device_xname(self
), "intr");
302 asc
->sc_ih
= podulebus_irq_establish(aa
->aa_irq
, IPL_SERIAL
, comintr
,
303 sc
, &asc
->sc_intrcnt
);