xref: /openbsd/sys/dev/puc/com_puc.c (revision ffccd32b)
1*ffccd32bSmvs /*	$OpenBSD: com_puc.c,v 1.28 2023/09/11 08:41:27 mvs Exp $	*/
25a7928a9Sdownsj 
35a7928a9Sdownsj /*
45a7928a9Sdownsj  * Copyright (c) 1997 - 1999, Jason Downs.  All rights reserved.
55a7928a9Sdownsj  *
65a7928a9Sdownsj  * Redistribution and use in source and binary forms, with or without
75a7928a9Sdownsj  * modification, are permitted provided that the following conditions
85a7928a9Sdownsj  * are met:
95a7928a9Sdownsj  * 1. Redistributions of source code must retain the above copyright
105a7928a9Sdownsj  *    notice, this list of conditions and the following disclaimer.
115a7928a9Sdownsj  * 2. Redistributions in binary form must reproduce the above copyright
125a7928a9Sdownsj  *    notice, this list of conditions and the following disclaimer in the
135a7928a9Sdownsj  *    documentation and/or other materials provided with the distribution.
145a7928a9Sdownsj  * 3. Neither the name(s) of the author(s) nor the name OpenBSD
155a7928a9Sdownsj  *    may be used to endorse or promote products derived from this software
165a7928a9Sdownsj  *    without specific prior written permission.
175a7928a9Sdownsj  *
185a7928a9Sdownsj  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
195a7928a9Sdownsj  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
205a7928a9Sdownsj  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
215a7928a9Sdownsj  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
225a7928a9Sdownsj  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
235a7928a9Sdownsj  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
245a7928a9Sdownsj  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
255a7928a9Sdownsj  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
265a7928a9Sdownsj  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
275a7928a9Sdownsj  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
285a7928a9Sdownsj  * SUCH DAMAGE.
295a7928a9Sdownsj  */
305a7928a9Sdownsj 
315a7928a9Sdownsj #include <sys/param.h>
325a7928a9Sdownsj #include <sys/systm.h>
335a7928a9Sdownsj #include <sys/ioctl.h>
345a7928a9Sdownsj #include <sys/tty.h>
355a7928a9Sdownsj #include <sys/conf.h>
365a7928a9Sdownsj #include <sys/uio.h>
375a7928a9Sdownsj #include <sys/kernel.h>
385a7928a9Sdownsj #include <sys/syslog.h>
395a7928a9Sdownsj #include <sys/device.h>
405a7928a9Sdownsj 
415a7928a9Sdownsj #include <machine/intr.h>
425a7928a9Sdownsj #include <machine/bus.h>
435a7928a9Sdownsj 
445a7928a9Sdownsj #include <dev/pci/pucvar.h>
455a7928a9Sdownsj 
465a7928a9Sdownsj #include "com.h"
475a7928a9Sdownsj 
485a7928a9Sdownsj #include <dev/ic/comreg.h>
495a7928a9Sdownsj #include <dev/ic/comvar.h>
505a7928a9Sdownsj #include <dev/ic/ns16550reg.h>
515a7928a9Sdownsj 
525a7928a9Sdownsj #define	com_lcr		com_cfcr
535a7928a9Sdownsj 
54c4071fd1Smillert int	com_puc_match(struct device *, void *, void *);
55c4071fd1Smillert void	com_puc_attach(struct device *, struct device *, void *);
56ad365a85Smickey int	com_puc_detach(struct device *, int);
575a7928a9Sdownsj 
58471aeecfSnaddy const struct cfattach com_puc_ca = {
59652996faSkettenis 	sizeof(struct com_softc), com_puc_match,
60e6229ee4Sderaadt 	com_puc_attach, com_puc_detach, com_activate
615a7928a9Sdownsj };
625a7928a9Sdownsj 
635a7928a9Sdownsj int
com_puc_match(struct device * parent,void * match,void * aux)6442b4ad6cSjsg com_puc_match(struct device *parent, void *match, void *aux)
655a7928a9Sdownsj {
665a7928a9Sdownsj 	struct puc_attach_args *pa = aux;
675a7928a9Sdownsj 
68ed84245fSderaadt 	if (PUC_IS_COM(pa->type))
695a7928a9Sdownsj 		return(1);
705a7928a9Sdownsj 
715a7928a9Sdownsj 	return(0);
725a7928a9Sdownsj }
735a7928a9Sdownsj 
745a7928a9Sdownsj void
com_puc_attach(struct device * parent,struct device * self,void * aux)7542b4ad6cSjsg com_puc_attach(struct device *parent, struct device *self, void *aux)
765a7928a9Sdownsj {
775a7928a9Sdownsj 	struct com_softc *sc = (void *)self;
785a7928a9Sdownsj 	struct puc_attach_args *pa = aux;
795a7928a9Sdownsj 	const char *intrstr;
80230ebe25Sjcs 	int i;
815a7928a9Sdownsj 
825a7928a9Sdownsj 	/* Grab a PCI interrupt. */
83ad365a85Smickey 	intrstr = pa->intr_string(pa);
84ad365a85Smickey 	sc->sc_ih = pa->intr_establish(pa, IPL_TTY, comintr, sc,
855a7928a9Sdownsj 	    sc->sc_dev.dv_xname);
865a7928a9Sdownsj 	if (sc->sc_ih == NULL) {
875a7928a9Sdownsj 		printf(": couldn't establish interrupt");
885a7928a9Sdownsj 		if (intrstr != NULL)
895a7928a9Sdownsj 			printf(" at %s", intrstr);
905a7928a9Sdownsj 		printf("\n");
915a7928a9Sdownsj 		return;
925a7928a9Sdownsj 	}
935a7928a9Sdownsj 	printf(" %s", intrstr);
945a7928a9Sdownsj 
955a7928a9Sdownsj 	sc->sc_iot = pa->t;
965a7928a9Sdownsj 	sc->sc_ioh = pa->h;
975a7928a9Sdownsj 	sc->sc_iobase = pa->a;
98230ebe25Sjcs 
99230ebe25Sjcs 	sc->sc_frequency = COM_FREQ;
100230ebe25Sjcs 
101230ebe25Sjcs 	for (i = 0; i < nitems(puc_port_types); i++)
102230ebe25Sjcs 		if (puc_port_types[i].type == pa->type) {
103230ebe25Sjcs 			sc->sc_frequency = puc_port_types[i].freq;
104230ebe25Sjcs 			break;
105230ebe25Sjcs 		}
10678a91e64Smickey 
107cbe056bcSjcs 	if (pa->type == PUC_PORT_COM_XR17V35X)
108cbe056bcSjcs 		sc->sc_uarttype = COM_UART_XR17V35X;
109cbe056bcSjcs 
1103da40b87Smiod 	com_attach_subr(sc);
1115a7928a9Sdownsj }
112ad365a85Smickey 
113ad365a85Smickey int
com_puc_detach(struct device * self,int flags)114ad365a85Smickey com_puc_detach(struct device *self, int flags)
115ad365a85Smickey {
116452fd331Skettenis 	return com_detach(self, flags);
117ad365a85Smickey }
118