1 /* $NetBSD: com_dio.c,v 1.7 2008/03/14 15:09:09 cube Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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.
33 * Copyright (c) 1991 The Regents of the University of California.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)com.c 7.5 (Berkeley) 5/16/91
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: com_dio.c,v 1.7 2008/03/14 15:09:09 cube Exp $");
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/device.h>
69 #include <sys/termios.h>
70 #include <sys/ttydefaults.h>
72 #include <machine/bus.h>
74 #include <dev/ic/comreg.h>
75 #include <dev/ic/comvar.h>
77 #include <hp300/dev/diovar.h>
78 #include <hp300/dev/diodevs.h>
79 #include <hp300/dev/com_dioreg.h>
80 #include <hp300/dev/com_diovar.h>
82 struct com_dio_softc
{
83 struct com_softc sc_com
; /* real "com" softc */
85 /* DIO-specific goo. */
86 struct bus_space_tag sc_tag
; /* device specific bus space tag */
87 void *sc_ih
; /* interrupt handler */
90 static int com_dio_match(device_t
, cfdata_t
, void *);
91 static void com_dio_attach(device_t
, device_t
, void *);
93 CFATTACH_DECL_NEW(com_dio
, sizeof(struct com_dio_softc
),
94 com_dio_match
, com_dio_attach
, NULL
, NULL
);
96 static int com_dio_speed
= TTYDEF_SPEED
;
97 static struct bus_space_tag comcntag
;
99 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
102 com_dio_match(device_t parent
, cfdata_t match
, void *aux
)
104 struct dio_attach_args
*da
= aux
;
107 case DIO_DEVICE_ID_DCA0
:
108 case DIO_DEVICE_ID_DCA0REM
:
109 case DIO_DEVICE_ID_DCA1
:
110 case DIO_DEVICE_ID_DCA1REM
:
118 com_dio_attach(device_t parent
, device_t self
, void *aux
)
120 struct com_dio_softc
*dsc
= device_private(self
);
121 struct com_softc
*sc
= &dsc
->sc_com
;
123 bus_space_handle_t iohdca
, iohcom
;
124 struct dio_attach_args
*da
= aux
;
128 isconsole
= com_is_console(&comcntag
, da
->da_addr
+ DCA_COM_OFFSET
,
133 bus_space_unmap(iot
, iohcom
, COM_NPORTS
);
136 memcpy(iot
, da
->da_bst
, sizeof(struct bus_space_tag
));
137 dio_set_bus_space_oddbyte(iot
);
140 if (bus_space_map(iot
, da
->da_addr
, DCA_SIZE
, 0, &iohdca
) ||
141 bus_space_subregion(iot
, iohdca
, DCA_COM_OFFSET
,
142 COM_NPORTS
<< 1, &iohcom
)) {
143 aprint_error(": can't map i/o space\n");
148 bus_space_write_1(iot
, iohdca
, DCA_RESET
, 0xff);
152 COM_INIT_REGS(sc
->sc_regs
, iot
, iohcom
,
153 da
->da_addr
+ DCA_COM_OFFSET
);
155 sc
->sc_frequency
= COM_DIO_FREQ
;
159 dsc
->sc_ih
= dio_intr_establish(comintr
, sc
, da
->da_ipl
, IPL_VM
);
161 /* Enable interrupts. */
162 bus_space_write_1(iot
, iohdca
, DCA_IC
, IC_IE
);
166 com_dio_cnattach(bus_space_tag_t bst
, bus_addr_t addr
, int scode
)
168 bus_space_tag_t iot
= &comcntag
;
169 bus_space_handle_t iohdca
;
172 memcpy(iot
, bst
, sizeof(struct bus_space_tag
));
173 dio_set_bus_space_oddbyte(iot
);
175 if (bus_space_map(iot
, addr
, DCA_SIZE
, 0, &iohdca
))
177 bus_space_write_1(iot
, iohdca
, DCA_RESET
, 0xff);
179 bus_space_write_1(iot
, iohdca
, DCA_IC
, IC_IE
);
181 id
= bus_space_read_1(iot
, iohdca
, DCA_ID
);
182 bus_space_unmap(iot
, iohdca
, DCA_SIZE
);
196 comcnattach(iot
, addr
+ DCA_COM_OFFSET
, com_dio_speed
, COM_DIO_FREQ
,
197 COM_TYPE_NORMAL
, CONMODE
);