xref: /netbsd-src/sys/arch/arm/gemini/gemini_com.c (revision 6d4870476f69938cdd065da8ea9ad989cef459f4)
1*6d487047Sthorpej /*	$NetBSD: gemini_com.c,v 1.4 2018/12/08 17:46:09 thorpej Exp $	*/
2f5d7ce3dSmatt 
3f5d7ce3dSmatt /* adapted from:
4f5d7ce3dSmatt  *	NetBSD: omap_com.c,v 1.2 2008/03/14 15:09:09 cube Exp
5f5d7ce3dSmatt  */
6f5d7ce3dSmatt 
7f5d7ce3dSmatt /*
8f5d7ce3dSmatt  * Based on arch/arm/xscale/pxa2x0_com.c
9f5d7ce3dSmatt  *
10f5d7ce3dSmatt  * Copyright 2003 Wasabi Systems, Inc.
11f5d7ce3dSmatt  * All rights reserved.
12f5d7ce3dSmatt  *
13f5d7ce3dSmatt  * Written by Steve C. Woodford for Wasabi Systems, Inc.
14f5d7ce3dSmatt  *
15f5d7ce3dSmatt  * Redistribution and use in source and binary forms, with or without
16f5d7ce3dSmatt  * modification, are permitted provided that the following conditions
17f5d7ce3dSmatt  * are met:
18f5d7ce3dSmatt  * 1. Redistributions of source code must retain the above copyright
19f5d7ce3dSmatt  *    notice, this list of conditions and the following disclaimer.
20f5d7ce3dSmatt  * 2. Redistributions in binary form must reproduce the above copyright
21f5d7ce3dSmatt  *    notice, this list of conditions and the following disclaimer in the
22f5d7ce3dSmatt  *    documentation and/or other materials provided with the distribution.
23f5d7ce3dSmatt  * 3. All advertising materials mentioning features or use of this software
24f5d7ce3dSmatt  *    must display the following acknowledgement:
25f5d7ce3dSmatt  *      This product includes software developed for the NetBSD Project by
26f5d7ce3dSmatt  *      Wasabi Systems, Inc.
27f5d7ce3dSmatt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
28f5d7ce3dSmatt  *    or promote products derived from this software without specific prior
29f5d7ce3dSmatt  *    written permission.
30f5d7ce3dSmatt  *
31f5d7ce3dSmatt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
32f5d7ce3dSmatt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33f5d7ce3dSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34f5d7ce3dSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
35f5d7ce3dSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36f5d7ce3dSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37f5d7ce3dSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38f5d7ce3dSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39f5d7ce3dSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40f5d7ce3dSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41f5d7ce3dSmatt  * POSSIBILITY OF SUCH DAMAGE.
42f5d7ce3dSmatt  */
43f5d7ce3dSmatt 
44f5d7ce3dSmatt #include <sys/cdefs.h>
45*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: gemini_com.c,v 1.4 2018/12/08 17:46:09 thorpej Exp $");
46f5d7ce3dSmatt 
47f5d7ce3dSmatt #include "opt_com.h"
48f5d7ce3dSmatt 
49f5d7ce3dSmatt #include <sys/param.h>
50f5d7ce3dSmatt #include <sys/systm.h>
51f5d7ce3dSmatt #include <sys/device.h>
52f5d7ce3dSmatt #include <sys/termios.h>
53f5d7ce3dSmatt 
54f5d7ce3dSmatt #include <machine/intr.h>
55cf10107dSdyoung #include <sys/bus.h>
56f5d7ce3dSmatt 
57f5d7ce3dSmatt #include <arm/pic/picvar.h>
58f5d7ce3dSmatt 
59f5d7ce3dSmatt #include <dev/ic/comreg.h>
60f5d7ce3dSmatt #include <dev/ic/comvar.h>
61f5d7ce3dSmatt 
62f5d7ce3dSmatt #include <arm/gemini/gemini_reg.h>
63f5d7ce3dSmatt #include <arm/gemini/gemini_obiovar.h>
64f5d7ce3dSmatt 
65f5d7ce3dSmatt #include <arm/gemini/gemini_com.h>
66f5d7ce3dSmatt 
67f5d7ce3dSmatt #include "locators.h"
68f5d7ce3dSmatt 
69f5d7ce3dSmatt static int	gemini_com_match(device_t, cfdata_t , void *);
70f5d7ce3dSmatt static void	gemini_com_attach(device_t, device_t, void *);
71f5d7ce3dSmatt 
72f5d7ce3dSmatt CFATTACH_DECL_NEW(gemini_com, sizeof(struct com_softc),
73f5d7ce3dSmatt     gemini_com_match, gemini_com_attach, NULL, NULL);
74f5d7ce3dSmatt 
75f5d7ce3dSmatt static int
gemini_com_match(device_t parent,cfdata_t cf,void * aux)76f5d7ce3dSmatt gemini_com_match(device_t parent, cfdata_t cf, void *aux)
77f5d7ce3dSmatt {
78f5d7ce3dSmatt 	struct obio_attach_args *obio = aux;
79f5d7ce3dSmatt 	bus_space_handle_t bh;
80f5d7ce3dSmatt 	int rv;
81f5d7ce3dSmatt 
82f5d7ce3dSmatt 	if (obio->obio_addr == -1 || obio->obio_intr == -1)
83f5d7ce3dSmatt 	    panic("gemini_com must have addr and intr specified in config.");
84f5d7ce3dSmatt 
85f5d7ce3dSmatt 	if (obio->obio_size == 0)
86f5d7ce3dSmatt 		obio->obio_size = GEMINI_UART_SIZE;
87f5d7ce3dSmatt 
88f5d7ce3dSmatt 	if (com_is_console(obio->obio_iot, obio->obio_addr, NULL))
89f5d7ce3dSmatt 		return (1);
90f5d7ce3dSmatt 
91f5d7ce3dSmatt 	if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size,
92f5d7ce3dSmatt 			  0, &bh))
93f5d7ce3dSmatt 		return (0);
94f5d7ce3dSmatt 
95f5d7ce3dSmatt 	rv = comprobe1(obio->obio_iot, bh);
96f5d7ce3dSmatt 
97f5d7ce3dSmatt 	bus_space_unmap(obio->obio_iot, bh, obio->obio_size);
98f5d7ce3dSmatt 
99f5d7ce3dSmatt 	return (rv);
100f5d7ce3dSmatt }
101f5d7ce3dSmatt 
102f5d7ce3dSmatt static void
gemini_com_attach(device_t parent,device_t self,void * aux)103f5d7ce3dSmatt gemini_com_attach(device_t parent, device_t self, void *aux)
104f5d7ce3dSmatt {
105f5d7ce3dSmatt 	struct com_softc *sc = device_private(self);
106f5d7ce3dSmatt 	struct obio_attach_args *obio = aux;
107f5d7ce3dSmatt 	bus_space_tag_t iot;
108f5d7ce3dSmatt 	bus_space_handle_t ioh;
109f5d7ce3dSmatt 	bus_addr_t iobase;
110f5d7ce3dSmatt 
111f5d7ce3dSmatt 	sc->sc_dev = self;
112f5d7ce3dSmatt 	iot = obio->obio_iot;
113f5d7ce3dSmatt 	iobase = obio->obio_addr;
114f5d7ce3dSmatt 	sc->sc_frequency = GEMINI_COM_FREQ;
11515bc29b7Scliff 	sc->sc_type = COM_TYPE_16550_NOERS;
116f5d7ce3dSmatt 
117f5d7ce3dSmatt 	if (com_is_console(iot, iobase, &ioh) == 0 &&
118f5d7ce3dSmatt 	    bus_space_map(iot, iobase, obio->obio_size, 0, &ioh)) {
119f5d7ce3dSmatt 		panic(": can't map registers\n");
120f5d7ce3dSmatt 		return;
121f5d7ce3dSmatt 	}
122*6d487047Sthorpej 	com_init_regs(&sc->sc_regs, iot, ioh, iobase);
123f5d7ce3dSmatt 
124f5d7ce3dSmatt 	com_attach_subr(sc);
125f5d7ce3dSmatt 	aprint_naive("\n");
126f5d7ce3dSmatt 
127f5d7ce3dSmatt 	intr_establish(obio->obio_intr, IPL_SERIAL, IST_LEVEL_HIGH,
128f5d7ce3dSmatt 		comintr, sc);
129f5d7ce3dSmatt }
130