1*594f789aSthorpej /* $NetBSD: com_frodo.c,v 1.11 2024/01/16 05:48:28 thorpej Exp $ */
263b14eb5Stsutsui
363b14eb5Stsutsui /*-
463b14eb5Stsutsui * Copyright (c) 1998 The NetBSD Foundation, Inc.
563b14eb5Stsutsui * All rights reserved.
663b14eb5Stsutsui *
763b14eb5Stsutsui * This code is derived from software contributed to The NetBSD Foundation
863b14eb5Stsutsui * by Charles M. Hannum.
963b14eb5Stsutsui *
1063b14eb5Stsutsui * Redistribution and use in source and binary forms, with or without
1163b14eb5Stsutsui * modification, are permitted provided that the following conditions
1263b14eb5Stsutsui * are met:
1363b14eb5Stsutsui * 1. Redistributions of source code must retain the above copyright
1463b14eb5Stsutsui * notice, this list of conditions and the following disclaimer.
1563b14eb5Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
1663b14eb5Stsutsui * notice, this list of conditions and the following disclaimer in the
1763b14eb5Stsutsui * documentation and/or other materials provided with the distribution.
1863b14eb5Stsutsui *
1963b14eb5Stsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2063b14eb5Stsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2163b14eb5Stsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2263b14eb5Stsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2363b14eb5Stsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2463b14eb5Stsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2563b14eb5Stsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2663b14eb5Stsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2763b14eb5Stsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2863b14eb5Stsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2963b14eb5Stsutsui * POSSIBILITY OF SUCH DAMAGE.
3063b14eb5Stsutsui */
3163b14eb5Stsutsui
3263b14eb5Stsutsui /*-
3363b14eb5Stsutsui * Copyright (c) 1991 The Regents of the University of California.
3463b14eb5Stsutsui * All rights reserved.
3563b14eb5Stsutsui *
3663b14eb5Stsutsui * Redistribution and use in source and binary forms, with or without
3763b14eb5Stsutsui * modification, are permitted provided that the following conditions
3863b14eb5Stsutsui * are met:
3963b14eb5Stsutsui * 1. Redistributions of source code must retain the above copyright
4063b14eb5Stsutsui * notice, this list of conditions and the following disclaimer.
4163b14eb5Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
4263b14eb5Stsutsui * notice, this list of conditions and the following disclaimer in the
4363b14eb5Stsutsui * documentation and/or other materials provided with the distribution.
4463b14eb5Stsutsui * 3. Neither the name of the University nor the names of its contributors
4563b14eb5Stsutsui * may be used to endorse or promote products derived from this software
4663b14eb5Stsutsui * without specific prior written permission.
4763b14eb5Stsutsui *
4863b14eb5Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4963b14eb5Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5063b14eb5Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5163b14eb5Stsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5263b14eb5Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5363b14eb5Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5463b14eb5Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5563b14eb5Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5663b14eb5Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5763b14eb5Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5863b14eb5Stsutsui * SUCH DAMAGE.
5963b14eb5Stsutsui *
6063b14eb5Stsutsui * @(#)com.c 7.5 (Berkeley) 5/16/91
6163b14eb5Stsutsui */
6263b14eb5Stsutsui
6363b14eb5Stsutsui #include <sys/cdefs.h>
64*594f789aSthorpej __KERNEL_RCSID(0, "$NetBSD: com_frodo.c,v 1.11 2024/01/16 05:48:28 thorpej Exp $");
6518155f04Stsutsui
6618155f04Stsutsui #include "sti_sgc.h"
6763b14eb5Stsutsui
6863b14eb5Stsutsui #include <sys/param.h>
6963b14eb5Stsutsui #include <sys/systm.h>
7063b14eb5Stsutsui #include <sys/device.h>
7163b14eb5Stsutsui #include <sys/termios.h>
7263b14eb5Stsutsui #include <sys/ttydefaults.h>
7363b14eb5Stsutsui
7463b14eb5Stsutsui #include <machine/bus.h>
7563b14eb5Stsutsui
7663b14eb5Stsutsui #include <dev/ic/comreg.h>
7763b14eb5Stsutsui #include <dev/ic/comvar.h>
7863b14eb5Stsutsui
7963b14eb5Stsutsui #include <hp300/dev/intiovar.h>
8063b14eb5Stsutsui #include <hp300/dev/frodoreg.h>
8163b14eb5Stsutsui #include <hp300/dev/frodovar.h>
8263b14eb5Stsutsui #include <hp300/dev/com_frodovar.h>
8363b14eb5Stsutsui
8463b14eb5Stsutsui #include "ioconf.h"
8563b14eb5Stsutsui
8663b14eb5Stsutsui struct com_frodo_softc {
8763b14eb5Stsutsui struct com_softc sc_com; /* real "com" softc */
8863b14eb5Stsutsui };
8963b14eb5Stsutsui
90607ead0eScube static int com_frodo_match(device_t, cfdata_t , void *);
91607ead0eScube static void com_frodo_attach(device_t, device_t, void *);
9263b14eb5Stsutsui
93607ead0eScube CFATTACH_DECL_NEW(com_frodo, sizeof(struct com_frodo_softc),
9463b14eb5Stsutsui com_frodo_match, com_frodo_attach, NULL, NULL);
9563b14eb5Stsutsui
9663b14eb5Stsutsui static int com_frodo_speed = TTYDEF_SPEED;
9763b14eb5Stsutsui static struct bus_space_tag comcntag;
9863b14eb5Stsutsui
9963b14eb5Stsutsui #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
10063b14eb5Stsutsui #define COM_FRODO_FREQ 8006400
10163b14eb5Stsutsui
1028ca927b4Sthorpej static int
com_frodo_match(device_t parent,cfdata_t match,void * aux)103607ead0eScube com_frodo_match(device_t parent, cfdata_t match, void *aux)
10463b14eb5Stsutsui {
10563b14eb5Stsutsui struct frodo_attach_args *fa = aux;
10663b14eb5Stsutsui
10763b14eb5Stsutsui if (strcmp(fa->fa_name, com_cd.cd_name) != 0)
10863b14eb5Stsutsui return 0;
10963b14eb5Stsutsui
11063b14eb5Stsutsui switch (fa->fa_offset) {
11163b14eb5Stsutsui case FRODO_APCI_OFFSET(1):
11263b14eb5Stsutsui case FRODO_APCI_OFFSET(2):
11363b14eb5Stsutsui case FRODO_APCI_OFFSET(3):
11463b14eb5Stsutsui return 1;
11563b14eb5Stsutsui }
11663b14eb5Stsutsui
11763b14eb5Stsutsui return 0;
11863b14eb5Stsutsui }
11963b14eb5Stsutsui
1208ca927b4Sthorpej static void
com_frodo_attach(device_t parent,device_t self,void * aux)121607ead0eScube com_frodo_attach(device_t parent, device_t self, void *aux)
12263b14eb5Stsutsui {
123607ead0eScube struct com_frodo_softc *fsc = device_private(self);
12463b14eb5Stsutsui struct com_softc *sc = &fsc->sc_com;
12563b14eb5Stsutsui struct frodo_attach_args *fa = aux;
12663b14eb5Stsutsui bus_space_tag_t iot;
12763b14eb5Stsutsui bus_space_handle_t ioh;
12863b14eb5Stsutsui int isconsole;
12963b14eb5Stsutsui
130607ead0eScube sc->sc_dev = self;
13163b14eb5Stsutsui isconsole = com_is_console(&comcntag, fa->fa_base + fa->fa_offset,
13263b14eb5Stsutsui &ioh);
13363b14eb5Stsutsui
13463b14eb5Stsutsui if (isconsole)
13563b14eb5Stsutsui iot = &comcntag;
13663b14eb5Stsutsui else
13763b14eb5Stsutsui iot = fa->fa_bst;
13863b14eb5Stsutsui
13963b14eb5Stsutsui if (!isconsole &&
14063b14eb5Stsutsui bus_space_map(iot, fa->fa_base + fa->fa_offset, COM_NPORTS << 2,
14163b14eb5Stsutsui 0, &ioh)) {
142607ead0eScube aprint_error(": can't map i/o space\n");
14363b14eb5Stsutsui return;
14463b14eb5Stsutsui }
1456d487047Sthorpej com_init_regs(&sc->sc_regs, iot, ioh, fa->fa_base + fa->fa_offset);
14663b14eb5Stsutsui
14763b14eb5Stsutsui sc->sc_frequency = COM_FRODO_FREQ;
14863b14eb5Stsutsui SET(sc->sc_hwflags, COM_HW_NOIEN);
14963b14eb5Stsutsui
15063b14eb5Stsutsui com_attach_subr(sc);
15163b14eb5Stsutsui
152*594f789aSthorpej frodo_intr_establish(parent, comintr, sc, fa->fa_line, ISRPRI_TTY);
15363b14eb5Stsutsui }
15463b14eb5Stsutsui
15563b14eb5Stsutsui int
com_frodo_cnattach(bus_space_tag_t bst,bus_addr_t addr,int scode)15663b14eb5Stsutsui com_frodo_cnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
15763b14eb5Stsutsui {
15863b14eb5Stsutsui bus_space_tag_t iot = &comcntag;
15963b14eb5Stsutsui bus_space_handle_t ioh;
16018155f04Stsutsui volatile uint8_t *frodoregs;
16163b14eb5Stsutsui
16263b14eb5Stsutsui if (machineid != HP_425 || mmuid != MMUID_425_E)
16363b14eb5Stsutsui return 1;
16463b14eb5Stsutsui
16518155f04Stsutsui /*
16618155f04Stsutsui * Check the service switch. On the 425e, this is a physical
16718155f04Stsutsui * switch, unlike other frodo-based machines, so we can use it
16818155f04Stsutsui * as a serial vs internal video selector, since the PROM can not
16918155f04Stsutsui * be configured for serial console.
17018155f04Stsutsui */
17118155f04Stsutsui frodoregs = (volatile uint8_t *)IIOV(INTIOBASE + FRODO_BASE);
17218155f04Stsutsui if (badaddr(__UNVOLATILE(frodoregs)) != 0) {
17318155f04Stsutsui /* 425e but no frodo chip found? */
17418155f04Stsutsui return 1;
17518155f04Stsutsui }
17618155f04Stsutsui
17718155f04Stsutsui /*
17818155f04Stsutsui * if sti(4) is not configured, we need serial console anyway
17918155f04Stsutsui * and no need to check the service switch.
18018155f04Stsutsui */
18118155f04Stsutsui #if NSTI_SGC > 0
18218155f04Stsutsui if (ISSET(frodoregs[FRODO_IISR], FRODO_IISR_SERVICE))
18318155f04Stsutsui return 1;
18418155f04Stsutsui #endif
18518155f04Stsutsui
18663b14eb5Stsutsui frodo_init_bus_space(iot);
18763b14eb5Stsutsui
18863b14eb5Stsutsui if (bus_space_map(iot, addr, INTIO_DEVSIZE, BUS_SPACE_MAP_LINEAR, &ioh))
18963b14eb5Stsutsui return 1;
19063b14eb5Stsutsui
19163b14eb5Stsutsui comcnattach(iot, addr, com_frodo_speed, COM_FRODO_FREQ,
19263b14eb5Stsutsui COM_TYPE_NORMAL, CONMODE);
19363b14eb5Stsutsui
19463b14eb5Stsutsui return 0;
19563b14eb5Stsutsui }
196