1272343Sngie/* $NetBSD: opms_isa.c,v 1.13 2023/08/30 09:17:46 andvar Exp $ */
2272343Sngie
3272343Sngie/*
4272343Sngie * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5272343Sngie * All rights reserved.
6272343Sngie *
7272343Sngie * Author: Chris G. Demetriou
8272343Sngie *
9272343Sngie * Permission to use, copy, modify and distribute this software and
10272343Sngie * its documentation is hereby granted, provided that both the copyright
11272343Sngie * notice and this permission notice appear in all copies of the
12272343Sngie * software, derivative works or modified versions, and any portions
13272343Sngie * thereof, and that both notices appear in supporting documentation.
14272343Sngie *
15272343Sngie * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16272343Sngie * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17272343Sngie * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18272343Sngie *
19272343Sngie * Carnegie Mellon requests users of this software to return to
20272343Sngie *
21272343Sngie *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22272343Sngie *  School of Computer Science
23272343Sngie *  Carnegie Mellon University
24272343Sngie *  Pittsburgh PA 15213-3890
25272343Sngie *
26272343Sngie * any improvements or extensions that they make and grant Carnegie the
27272343Sngie * rights to redistribute these changes.
28272343Sngie */
29272343Sngie
30272343Sngie#include <sys/cdefs.h>
31272343Sngie__KERNEL_RCSID(0, "$NetBSD: opms_isa.c,v 1.13 2023/08/30 09:17:46 andvar Exp $");
32272343Sngie
33272343Sngie#include <sys/param.h>
34272343Sngie#include <sys/systm.h>
35272343Sngie#include <sys/tty.h>
36272343Sngie#include <sys/device.h>
37272343Sngie
38272343Sngie#include <sys/bus.h>
39272343Sngie
40272343Sngie#include <dev/isa/isareg.h>
41272343Sngie#include <dev/isa/isavar.h>
42272343Sngie
43272343Sngie#include <arc/dev/pcconsvar.h>
44272343Sngie#include <arc/dev/opmsvar.h>
45272343Sngie#include <arc/isa/pccons_isavar.h>
46272343Sngie
47272343Sngiestatic int	opms_isa_match(device_t, cfdata_t, void *);
48272343Sngiestatic void	opms_isa_attach(device_t, device_t, void *);
49272343Sngie
50272343SngieCFATTACH_DECL_NEW(opms_isa, sizeof(struct opms_softc),
51272343Sngie    opms_isa_match, opms_isa_attach, NULL, NULL);
52272343Sngie
53272343Sngiestatic int
54272343Sngieopms_isa_match(device_t parent, cfdata_t cf, void *aux)
55272343Sngie{
56272343Sngie	struct isa_attach_args *ia = aux;
57272343Sngie	bus_addr_t iobase = IO_KBD;
58272343Sngie	bus_size_t iosize = IO_KBDSIZE;
59272343Sngie	int irq = 12;
60272343Sngie
61272343Sngie	if (ia->ia_nio < 1)
62272343Sngie		return 0;
63272343Sngie	if (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT)
64272343Sngie		iobase = ia->ia_io[0].ir_addr;
65272343Sngie#if 0	/* XXX isa.c */
66272343Sngie	if (ia->ia_iosize != 0)
67272343Sngie		iosize = ia->ia_iosize;
68272343Sngie#endif
69272343Sngie	if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ)
70272343Sngie		irq = ia->ia_irq[0].ir_irq;
71272343Sngie
72272343Sngie#if 0
73272343Sngie	/* If values are hardwired to something that they can't be, punt. */
74272343Sngie	if (iobase != IO_KBD || iosize != IO_KBDSIZE ||
75272343Sngie	    ia->ia_maddr != MADDRUNK || ia->ia_msize != 0 ||
76272343Sngie	    ia->ia_irq != 1 || ia->ia_drq != DRQUNK)
77272343Sngie		return 0;
78272343Sngie#endif
79272343Sngie
80272343Sngie	if (pccons_isa_conf == NULL)
81272343Sngie		return 0;
82272343Sngie
83272343Sngie	if (!opms_common_match(ia->ia_iot, pccons_isa_conf))
84272343Sngie		return 0;
85272343Sngie
86272343Sngie	ia->ia_nio = 1;
87272343Sngie	ia->ia_io[0].ir_addr = iobase;
88272343Sngie	ia->ia_io[0].ir_size = iosize;
89272343Sngie
90272343Sngie	ia->ia_nirq = 1;
91272343Sngie	ia->ia_irq[0].ir_irq = irq;
92272343Sngie
93272343Sngie	ia->ia_niomem = 0;
94272343Sngie	ia->ia_ndrq = 0;
95272343Sngie
96272343Sngie	return 1;
97272343Sngie}
98272343Sngie
99272343Sngiestatic void
100272343Sngieopms_isa_attach(device_t parent, device_t self, void *aux)
101272343Sngie{
102272343Sngie	struct opms_softc *sc = device_private(self);
103272343Sngie	struct isa_attach_args *ia = aux;
104272343Sngie
105272343Sngie	sc->sc_dev = self;
106272343Sngie
107272343Sngie	aprint_normal("\n");
108272343Sngie
109	isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE, IPL_TTY,
110	    pcintr, sc);
111	opms_common_attach(sc, ia->ia_iot, pccons_isa_conf);
112}
113