1 /* $NetBSD: com_vrip.c,v 1.20 2008/03/14 15:09:10 cube Exp $ */
4 * Copyright (c) 1999 SASAKI Takesi. All rights reserved.
5 * Copyright (c) 1999, 2002 PocketBSD Project. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the PocketBSD project
18 * and its contributors.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: com_vrip.c,v 1.20 2008/03/14 15:09:10 cube Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/reboot.h>
47 #include <sys/termios.h>
49 #include <machine/intr.h>
50 #include <machine/bus.h>
52 #include <machine/platid.h>
53 #include <machine/platid_mask.h>
54 #include <machine/config_hook.h>
56 #include <hpcmips/vr/vr.h>
57 #include <hpcmips/vr/vrcpudef.h>
58 #include <hpcmips/vr/vripif.h>
59 #include <hpcmips/vr/vripvar.h>
60 #include <hpcmips/vr/cmureg.h>
61 #include <hpcmips/vr/siureg.h>
63 #include <dev/ic/comvar.h>
64 #include <dev/ic/comreg.h>
66 #include "opt_vr41xx.h"
67 #include <hpcmips/vr/com_vripvar.h>
73 int com_vrip_debug
= 0;
74 #define DPRINTF(arg) if (com_vrip_debug) printf arg;
75 #define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
78 #define VPRINTF(arg) if (bootverbose) printf arg;
81 struct com_vrip_softc
{
82 struct com_softc sc_com
;
86 static int com_vrip_probe(device_t
, cfdata_t
, void *);
87 static void com_vrip_attach(device_t
, device_t
, void *);
88 static int com_vrip_common_probe(bus_space_tag_t
, int);
90 void vrcmu_init(void);
91 void vrcmu_supply(int);
94 CFATTACH_DECL_NEW(com_vrip
, sizeof(struct com_vrip_softc
),
95 com_vrip_probe
, com_vrip_attach
, NULL
, NULL
);
98 com_vrip_cndb_attach(bus_space_tag_t iot
, int iobase
, int rate
, int frequency
,
99 tcflag_t cflag
, int kgdb
)
102 if (!com_vrip_common_probe(iot
, iobase
))
103 return (EIO
); /* I can't find appropriate error number. */
106 return (com_kgdb_attach(iot
, iobase
, rate
, frequency
,
107 COM_TYPE_NORMAL
, cflag
));
110 return (comcnattach(iot
, iobase
, rate
, frequency
,
111 COM_TYPE_NORMAL
, cflag
));
115 com_vrip_common_probe(bus_space_tag_t iot
, int iobase
)
117 bus_space_handle_t ioh
;
120 if (bus_space_map(iot
, iobase
, 1, 0, &ioh
)) {
121 aprint_error(": can't map i/o space\n");
124 rv
= comprobe1(iot
, ioh
);
125 bus_space_unmap(iot
, ioh
, 1);
130 com_vrip_probe(device_t parent
, cfdata_t cf
, void *aux
)
132 struct vrip_attach_args
*va
= aux
;
133 bus_space_tag_t iot
= va
->va_iot
;
136 DPRINTF(("==com_vrip_probe"));
138 if (va
->va_addr
== VRIPIFCF_ADDR_DEFAULT
||
139 va
->va_unit
== VRIPIFCF_UNIT_DEFAULT
) {
140 aprint_error(": need addr and intr.\n");
144 vrip_power(va
->va_vc
, va
->va_unit
, 1);
146 if (com_is_console(iot
, va
->va_addr
, 0)) {
148 * We have alredy probed.
152 rv
= com_vrip_common_probe(iot
, va
->va_addr
);
155 DPRINTF((rv
? ": found COM ports\n" : ": can't probe COM device\n"));
158 va
->va_size
= COM_NPORTS
;
165 com_vrip_attach(device_t parent
, device_t self
, void *aux
)
167 struct com_vrip_softc
*vsc
= device_private(self
);
168 struct com_softc
*sc
= &vsc
->sc_com
;
169 struct vrip_attach_args
*va
= aux
;
171 bus_space_tag_t iot
= va
->va_iot
;
172 bus_space_handle_t ioh
;
175 vsc
->sc_pwctl
= device_cfdata(sc
->sc_dev
)->cf_loc
[VRIPIFCF_PWCTL
];
177 DPRINTF(("==com_vrip_attach"));
179 if (bus_space_map(iot
, va
->va_addr
, 1, 0, &ioh
)) {
180 aprint_error(": can't map bus space\n");
184 COM_INIT_REGS(sc
->sc_regs
, iot
, ioh
, va
->va_addr
);
186 sc
->enable
= NULL
; /* XXX: CMU control */
189 sc
->sc_frequency
= VRCOM_FREQ
;
190 /* Power management */
191 vrip_power(va
->va_vc
, va
->va_unit
, 1);
192 /* XXX, locale 'ID' must be need */
193 config_hook_call(CONFIG_HOOK_POWERCONTROL
, vsc
->sc_pwctl
, (void*)1);
195 DPRINTF(("Try to attach com.\n"));
198 DPRINTF(("Establish intr"));
199 if (!vrip_intr_establish(va
->va_vc
, va
->va_unit
, 0, IPL_TTY
,
201 aprint_error_dev(self
, "can't map interrupt line.\n");
204 DPRINTF((":return()"));
205 VPRINTF(("%s: pwctl %d\n", device_xname(self
), vsc
->sc_pwctl
));