xref: /openbsd/sys/dev/puc/com_puc.c (revision 73471bf0)
1 /*	$OpenBSD: com_puc.c,v 1.26 2021/03/05 13:20:19 jsg Exp $	*/
2 
3 /*
4  * Copyright (c) 1997 - 1999, Jason Downs.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name(s) of the author(s) nor the name OpenBSD
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) 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 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/ioctl.h>
34 #include <sys/selinfo.h>
35 #include <sys/tty.h>
36 #include <sys/conf.h>
37 #include <sys/uio.h>
38 #include <sys/kernel.h>
39 #include <sys/syslog.h>
40 #include <sys/device.h>
41 
42 #include <machine/intr.h>
43 #include <machine/bus.h>
44 
45 #include <dev/pci/pucvar.h>
46 
47 #include "com.h"
48 
49 #include <dev/ic/comreg.h>
50 #include <dev/ic/comvar.h>
51 #include <dev/ic/ns16550reg.h>
52 
53 #define	com_lcr		com_cfcr
54 
55 int	com_puc_match(struct device *, void *, void *);
56 void	com_puc_attach(struct device *, struct device *, void *);
57 int	com_puc_detach(struct device *, int);
58 
59 struct cfattach com_puc_ca = {
60 	sizeof(struct com_softc), com_puc_match,
61 	com_puc_attach, com_puc_detach, com_activate
62 };
63 
64 int
65 com_puc_match(struct device *parent, void *match, void *aux)
66 {
67 	struct puc_attach_args *pa = aux;
68 
69 	if (PUC_IS_COM(pa->type))
70 		return(1);
71 
72 	return(0);
73 }
74 
75 void
76 com_puc_attach(struct device *parent, struct device *self, void *aux)
77 {
78 	struct com_softc *sc = (void *)self;
79 	struct puc_attach_args *pa = aux;
80 	const char *intrstr;
81 	int i;
82 
83 	/* Grab a PCI interrupt. */
84 	intrstr = pa->intr_string(pa);
85 	sc->sc_ih = pa->intr_establish(pa, IPL_TTY, comintr, sc,
86 	    sc->sc_dev.dv_xname);
87 	if (sc->sc_ih == NULL) {
88 		printf(": couldn't establish interrupt");
89 		if (intrstr != NULL)
90 			printf(" at %s", intrstr);
91 		printf("\n");
92 		return;
93 	}
94 	printf(" %s", intrstr);
95 
96 	sc->sc_iot = pa->t;
97 	sc->sc_ioh = pa->h;
98 	sc->sc_iobase = pa->a;
99 
100 	sc->sc_frequency = COM_FREQ;
101 
102 	for (i = 0; i < nitems(puc_port_types); i++)
103 		if (puc_port_types[i].type == pa->type) {
104 			sc->sc_frequency = puc_port_types[i].freq;
105 			break;
106 		}
107 
108 	if (pa->type == PUC_PORT_COM_XR17V35X)
109 		sc->sc_uarttype = COM_UART_XR17V35X;
110 
111 	com_attach_subr(sc);
112 }
113 
114 int
115 com_puc_detach(struct device *self, int flags)
116 {
117 	return com_detach(self, flags);
118 }
119