xref: /openbsd-src/sys/dev/puc/com_puc.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: com_puc.c,v 1.22 2014/09/14 14:17:25 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/file.h>
38 #include <sys/uio.h>
39 #include <sys/kernel.h>
40 #include <sys/syslog.h>
41 #include <sys/device.h>
42 
43 #include <machine/intr.h>
44 #include <machine/bus.h>
45 
46 #include <dev/pci/pucvar.h>
47 
48 #include "com.h"
49 
50 #include <dev/ic/comreg.h>
51 #include <dev/ic/comvar.h>
52 #include <dev/ic/ns16550reg.h>
53 
54 #define	com_lcr		com_cfcr
55 
56 int	com_puc_match(struct device *, void *, void *);
57 void	com_puc_attach(struct device *, struct device *, void *);
58 int	com_puc_detach(struct device *, int);
59 
60 struct cfattach com_puc_ca = {
61 	sizeof(struct com_softc), com_puc_match,
62 	com_puc_attach, com_puc_detach, com_activate
63 };
64 
65 int
66 com_puc_match(parent, match, aux)
67 	struct device *parent;
68 	void *match, *aux;
69 {
70 	struct puc_attach_args *pa = aux;
71 
72 	if (PUC_IS_COM(pa->type))
73 		return(1);
74 
75 	return(0);
76 }
77 
78 void
79 com_puc_attach(parent, self, aux)
80 	struct device *parent, *self;
81 	void *aux;
82 {
83 	struct com_softc *sc = (void *)self;
84 	struct puc_attach_args *pa = aux;
85 	const char *intrstr;
86 
87 	/* Grab a PCI interrupt. */
88 	intrstr = pa->intr_string(pa);
89 	sc->sc_ih = pa->intr_establish(pa, IPL_TTY, comintr, sc,
90 	    sc->sc_dev.dv_xname);
91 	if (sc->sc_ih == NULL) {
92 		printf(": couldn't establish interrupt");
93 		if (intrstr != NULL)
94 			printf(" at %s", intrstr);
95 		printf("\n");
96 		return;
97 	}
98 	printf(" %s", intrstr);
99 
100 	sc->sc_iot = pa->t;
101 	sc->sc_ioh = pa->h;
102 	sc->sc_iobase = pa->a;
103 	if (PUC_IS_COM_MUL(pa->type))
104 		sc->sc_frequency = COM_FREQ * PUC_COM_GET_MUL(pa->type);
105 	else
106 		sc->sc_frequency = COM_FREQ * (1 << PUC_COM_GET_POW2(pa->type));
107 
108 	com_attach_subr(sc);
109 }
110 
111 int
112 com_puc_detach(struct device *self, int flags)
113 {
114 	return com_detach(self, flags);
115 }
116