1 /* $OpenBSD: com_dino.c,v 1.4 2007/07/15 19:25:49 kettenis Exp $ */
4 * Copyright (c) 2004 Michael Shalayeff
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
34 #include <machine/bus.h>
35 #include <machine/intr.h>
36 #include <machine/iomod.h>
37 #include <machine/autoconf.h>
39 #include <dev/ic/comreg.h>
40 #include <dev/ic/comvar.h>
42 #include <hp700/dev/cpudevs.h>
43 #include <hp700/hp700/machdep.h>
45 void *dino_intr_establish(void *sc
, int irq
, int pri
,
46 int (*handler
)(void *v
), void *arg
);
48 #define COM_DINO_FREQ 7272700
50 struct com_dino_softc
{
51 struct com_softc sc_com
; /* real "com" softc */
52 void *sc_ih
; /* interrupt handler */
55 struct com_dino_regs
{
59 #define COM_DINO_PAR_LOOP 0x01
60 #define COM_DINO_CLK_SEL 0x02
67 int com_dino_match(device_t
, cfdata_t
, void *);
68 void com_dino_attach(device_t
, device_t
, void *);
70 CFATTACH_DECL_NEW(com_dino
, sizeof(struct com_dino_softc
), com_dino_match
,
71 com_dino_attach
, NULL
, NULL
);
74 com_dino_match(device_t parent
, cfdata_t match
, void *aux
)
76 struct confargs
*ca
= aux
;
78 if (ca
->ca_type
.iodc_type
!= HPPA_TYPE_FIO
||
79 ca
->ca_type
.iodc_sv_model
!= HPPA_FIO_GRS232
)
83 /* HOZER comprobe1(ca->ca_iot, ca->ca_hpa + IOMOD_DEVOFFSET); */
87 com_dino_attach(device_t parent
, device_t self
, void *aux
)
89 void *sc_dino
= device_private(parent
);
90 struct com_dino_softc
*sc_comdino
= device_private(self
);
91 struct com_softc
*sc
= &sc_comdino
->sc_com
;
92 struct confargs
*ca
= aux
;
93 struct com_dino_regs
*regs
= (struct com_dino_regs
*)ca
->ca_hpa
;
97 bus_space_handle_t ioh
;
100 iobase
= (bus_addr_t
)ca
->ca_hpa
+ IOMOD_DEVOFFSET
;
101 sc
->sc_frequency
= COM_DINO_FREQ
;
103 /* Test if this is the console. Compare either HPA or device path. */
104 pagezero_cookie
= hp700_pagezero_map();
105 if (PAGE0
->mem_cons
.pz_class
== PCL_DUPLEX
&&
106 PAGE0
->mem_cons
.pz_hpa
== (struct iomod
*)ca
->ca_hpa
) {
109 * This port is the console. In this case we must call
110 * comcnattach() and later com_is_console() to initialize
111 * everything properly.
114 if (comcnattach(ca
->ca_iot
, iobase
, B9600
,
115 sc
->sc_frequency
, COM_TYPE_NORMAL
,
116 (TTYDEF_CFLAG
& ~(CSIZE
| PARENB
)) | CS8
) != 0) {
117 aprint_error(": can't comcnattach\n");
118 hp700_pagezero_unmap(pagezero_cookie
);
122 hp700_pagezero_unmap(pagezero_cookie
);
125 * Get the already initialized console ioh via com_is_console() if
126 * this is the console or map the I/O space if this isn't the console.
129 if (!com_is_console(ca
->ca_iot
, iobase
, &ioh
) &&
130 bus_space_map(ca
->ca_iot
, iobase
, COM_NPORTS
, 0, &ioh
) != 0) {
131 aprint_error(": can't map I/O space\n");
134 COM_INIT_REGS(sc
->sc_regs
, ca
->ca_iot
, ioh
, iobase
);
136 /* select clock freq */
137 regs
->test
= COM_DINO_CLK_SEL
;
143 sc_comdino
->sc_ih
= dino_intr_establish(sc_dino
, ca
->ca_irq
, IPL_TTY
,