1 /* $NetBSD: com_gsc.c,v 1.13 2009/05/24 06:53:35 skrll Exp $ */
3 /* $OpenBSD: com_gsc.c,v 1.8 2000/03/13 14:39:59 mickey Exp $ */
6 * Copyright (c) 1998-2004 Michael Shalayeff
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: com_gsc.c,v 1.13 2009/05/24 06:53:35 skrll Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 #include <machine/iomod.h>
48 #include <machine/autoconf.h>
50 #include <dev/ic/comreg.h>
51 #include <dev/ic/comvar.h>
53 #include <hp700/dev/cpudevs.h>
54 #include <hp700/gsc/gscbusvar.h>
55 #include <hp700/hp700/machdep.h>
57 #define COMGSC_OFFSET 0x800
58 #define COMGSC_FREQUENCY (1843200 * 4) /* 16-bit baud rate divisor */
64 struct com_gsc_softc
{
65 struct com_softc sc_com
; /* real "com" softc */
67 /* GSC-specific goo. */
68 void *sc_ih
; /* interrupt handler */
71 int com_gsc_probe(device_t
, cfdata_t
, void *);
72 void com_gsc_attach(device_t
, device_t
, void *);
74 CFATTACH_DECL_NEW(com_gsc
, sizeof(struct com_gsc_softc
),
75 com_gsc_probe
, com_gsc_attach
, NULL
, NULL
);
78 com_gsc_probe(device_t parent
, cfdata_t match
, void *aux
)
80 struct gsc_attach_args
*ga
= aux
;
82 if (ga
->ga_type
.iodc_type
!= HPPA_TYPE_FIO
||
83 (ga
->ga_type
.iodc_sv_model
!= HPPA_FIO_GRS232
&&
84 ga
->ga_type
.iodc_sv_model
!= HPPA_FIO_RS232
))
91 com_gsc_attach(device_t parent
, device_t self
, void *aux
)
93 struct com_gsc_softc
*gsc
= device_private(self
);
94 struct com_softc
*sc
= &gsc
->sc_com
;
95 struct gsc_attach_args
*ga
= aux
;
98 bus_space_handle_t ioh
;
105 iobase
= (bus_addr_t
)ga
->ga_hpa
+ COMGSC_OFFSET
;
106 sc
->sc_frequency
= COMGSC_FREQUENCY
;
108 /* Test if this is the console. Compare either HPA or device path. */
109 pagezero_cookie
= hp700_pagezero_map();
110 if ((hppa_hpa_t
)PAGE0
->mem_cons
.pz_hpa
== ga
->ga_hpa
) {
113 * This port is the console. In this case we must call
114 * comcnattach() and later com_is_console() to initialize
115 * everything properly.
118 if (comcnattach(iot
, iobase
, B9600
,
119 sc
->sc_frequency
, COM_TYPE_NORMAL
,
120 (TTYDEF_CFLAG
& ~(CSIZE
| PARENB
)) | CS8
) != 0) {
121 aprint_error(": can't comcnattach\n");
122 hp700_pagezero_unmap(pagezero_cookie
);
126 hp700_pagezero_unmap(pagezero_cookie
);
129 * Get the already initialized console ioh via com_is_console() if
130 * this is the console or map the I/O space if this isn't the console.
133 if (!com_is_console(iot
, iobase
, &ioh
) &&
134 bus_space_map(iot
, iobase
, COM_NPORTS
, 0, &ioh
) != 0) {
135 aprint_error(": can't map I/O space\n");
138 COM_INIT_REGS(sc
->sc_regs
, iot
, ioh
, iobase
);
141 gsc
->sc_ih
= hp700_intr_establish(sc
->sc_dev
, IPL_TTY
,
142 comintr
, sc
, ga
->ga_int_reg
, ga
->ga_irq
);
146 int com_gsc_kgdb_attach(void);
148 com_gsc_kgdb_attach(void)
152 printf("kgdb: attaching com at 0x%x at %d baud...",
154 error
= com_kgdb_attach(&hppa_bustag
, KGDBADDR
+ COMGSC_OFFSET
,
155 KGDBRATE
, COMGSC_FREQUENCY
, COM_TYPE_NORMAL
,
156 ((TTYDEF_CFLAG
& ~(CSIZE
| CSTOPB
| PARENB
)) |
159 printf(" failed (%d)\n", error
);