3 /* $OpenBSD: com_ssio.c,v 1.2 2007/06/24 16:28:39 kettenis Exp $ */
6 * Copyright (c) 2007 Mark Kettenis
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/param.h>
22 #include <sys/systm.h>
23 #include <sys/device.h>
26 #include <machine/bus.h>
27 #include <machine/iomod.h>
29 #include <dev/ic/comreg.h>
30 #include <dev/ic/comvar.h>
32 #include <hp700/hp700/machdep.h>
33 #include <hp700/dev/ssiovar.h>
35 void *ssio_intr_establish(int, int, int (*)(void *), void *,
38 #define COM_SSIO_FREQ 1843200
40 struct com_ssio_softc
{
41 struct com_softc sc_com
; /* real "com" softc */
42 void *sc_ih
; /* interrupt handler */
45 int com_ssio_match(device_t
, cfdata_t
, void *);
46 void com_ssio_attach(device_t
, device_t
, void *);
48 CFATTACH_DECL_NEW(com_ssio
, sizeof(struct com_ssio_softc
), com_ssio_match
,
49 com_ssio_attach
, NULL
, NULL
);
52 com_ssio_match(device_t parent
, cfdata_t match
, void *aux
)
55 struct ssio_attach_args
*saa
= aux
;
57 if (strcmp(saa
->saa_name
, "com") != 0)
61 if (cf
->ssiocf_irq
!= SSIO_UNK_IRQ
&& cf
->ssiocf_irq
!= saa
->saa_irq
)
68 com_ssio_attach(device_t parent
, device_t self
, void *aux
)
70 struct com_ssio_softc
*sc_ssio
= device_private(self
);
71 struct com_softc
*sc
= &sc_ssio
->sc_com
;
72 struct ssio_attach_args
*saa
= aux
;
76 bus_space_handle_t ioh
;
80 iobase
= saa
->saa_iobase
;
82 if (bus_space_map(iot
, iobase
, COM_NPORTS
,
84 aprint_error(": can't map I/O space\n");
88 pagezero_cookie
= hp700_pagezero_map();
89 if (PAGE0
->mem_cons
.pz_class
== PCL_DUPLEX
&&
90 PAGE0
->mem_cons
.pz_hpa
== (struct iomod
*)iobase
) {
91 bus_space_unmap(iot
, ioh
, COM_NPORTS
);
92 if (comcnattach(iot
, iobase
, B9600
, COM_SSIO_FREQ
,
94 (TTYDEF_CFLAG
& ~(CSIZE
| PARENB
)) | CS8
) != 0) {
95 aprint_error(": can't comcnattach\n");
96 hp700_pagezero_unmap(pagezero_cookie
);
100 hp700_pagezero_unmap(pagezero_cookie
);
102 sc
->sc_frequency
= COM_SSIO_FREQ
;
103 COM_INIT_REGS(sc
->sc_regs
, iot
, ioh
, iobase
);
106 sc_ssio
->sc_ih
= ssio_intr_establish(IPL_TTY
, saa
->saa_irq
,
107 comintr
, sc
, device_xname(self
));