xref: /netbsd-src/sys/arch/arm/imx/imx23_plcom.c (revision 55dba9eeb4e6dec59bbce92ab9e85e43f8d85022)
1 /* $Id: imx23_plcom.c,v 1.2 2018/10/23 09:15:35 jmcneill Exp $ */
2 
3 /*
4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Petri Laakso
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  *
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.
30  */
31 
32 /* Interface to plcom (PL011) serial driver. */
33 
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/bus.h>
37 #include <sys/device.h>
38 #include <sys/systm.h>
39 #include <sys/termios.h>
40 
41 #include <arm/pic/picvar.h>
42 
43 #include <arm/imx/imx23var.h>
44 #include <arm/imx/imx23_uartdbgreg.h>
45 
46 #include <evbarm/dev/plcomreg.h>
47 #include <evbarm/dev/plcomvar.h>
48 
49 static int imx23_plcom_match(device_t, cfdata_t, void *);
50 static void imx23_plcom_attach(device_t, device_t, void *);
51 
52 CFATTACH_DECL3_NEW(imx23plcom,
53 	sizeof(struct plcom_softc),
54 	imx23_plcom_match,
55 	imx23_plcom_attach,
56 	NULL,
57 	NULL,
58 	NULL,
59 	NULL,
60 	0);
61 
62 static int
imx23_plcom_match(device_t parent,cfdata_t cf,void * aux)63 imx23_plcom_match(device_t parent, cfdata_t cf, void *aux)
64 {
65 	struct apb_attach_args *aaa = aux;
66 
67 	if (aaa->aa_addr == HW_UARTDBG_BASE &&
68 	    aaa->aa_size == PL011COM_UART_SIZE) {
69 		return 1;
70 	}
71 
72 	return 0;
73 }
74 
75 static void
imx23_plcom_attach(device_t parent,device_t self,void * aux)76 imx23_plcom_attach(device_t parent, device_t self, void *aux)
77 {
78 	static int plcom_attached = 0;
79 	struct plcom_softc *sc = device_private(self);
80 	struct apb_attach_args *aaa = aux;
81 	void *ih;
82 
83 	if (plcom_attached)
84 		return;
85 
86 	aprint_naive("\n");
87 	aprint_normal("\n");
88 
89 	sc->sc_dev = self;
90 	sc->sc_frequency = IMX23_UART_CLK;
91 	sc->sc_hwflags = PLCOM_HW_TXFIFO_DISABLE;
92 	sc->sc_swflags = 0;
93 	sc->sc_set_mcr = NULL;
94 	sc->sc_set_mcr_arg = NULL;
95 
96 	sc->sc_pi.pi_type = PLCOM_TYPE_PL011;
97 	sc->sc_pi.pi_flags = PLC_FLAG_32BIT_ACCESS;
98 	sc->sc_pi.pi_iot = aaa->aa_iot;
99 	sc->sc_pi.pi_iobase = aaa->aa_addr;
100 
101 	if (bus_space_map(aaa->aa_iot, aaa->aa_addr, PL011COM_UART_SIZE, 0,
102 	    &sc->sc_pi.pi_ioh)) {
103 		aprint_error_dev(sc->sc_dev, "unable to map device\n");
104 		return;
105 	}
106 
107 	plcom_attach_subr(sc);
108 
109 	ih = intr_establish(aaa->aa_irq, IPL_SERIAL, IST_LEVEL,
110 		plcomintr, sc);
111 
112 	if (ih == NULL)
113 		panic("%s: cannot install interrupt handler",
114 		    device_xname(sc->sc_dev));
115 
116 	plcom_attached = 1;
117 
118 	return;
119 }
120