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