xref: /netbsd-src/sys/arch/alpha/sableio/lpt_sableio.c (revision b7b2b8a3d89bfee25ca9324638c59a92666e2e4e)
1*b7b2b8a3Sthorpej /* $NetBSD: lpt_sableio.c,v 1.12 2021/05/07 16:58:34 thorpej Exp $ */
2f363b73fSthorpej 
3f363b73fSthorpej /*-
4f363b73fSthorpej  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5f363b73fSthorpej  * All rights reserved.
6f363b73fSthorpej  *
7f363b73fSthorpej  * This code is derived from software contributed to The NetBSD Foundation
8f363b73fSthorpej  * by Jason R. Thorpe.
9f363b73fSthorpej  *
10f363b73fSthorpej  * Redistribution and use in source and binary forms, with or without
11f363b73fSthorpej  * modification, are permitted provided that the following conditions
12f363b73fSthorpej  * are met:
13f363b73fSthorpej  * 1. Redistributions of source code must retain the above copyright
14f363b73fSthorpej  *    notice, this list of conditions and the following disclaimer.
15f363b73fSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16f363b73fSthorpej  *    notice, this list of conditions and the following disclaimer in the
17f363b73fSthorpej  *    documentation and/or other materials provided with the distribution.
18f363b73fSthorpej  *
19f363b73fSthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f363b73fSthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f363b73fSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f363b73fSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f363b73fSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f363b73fSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f363b73fSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f363b73fSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f363b73fSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f363b73fSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f363b73fSthorpej  * POSSIBILITY OF SUCH DAMAGE.
30f363b73fSthorpej  */
31f363b73fSthorpej 
32f363b73fSthorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
33f363b73fSthorpej 
34*b7b2b8a3Sthorpej __KERNEL_RCSID(0, "$NetBSD: lpt_sableio.c,v 1.12 2021/05/07 16:58:34 thorpej Exp $");
35f363b73fSthorpej 
36f363b73fSthorpej #include <sys/param.h>
37f363b73fSthorpej #include <sys/systm.h>
38f363b73fSthorpej #include <sys/ioctl.h>
39f363b73fSthorpej #include <sys/select.h>
40f363b73fSthorpej #include <sys/tty.h>
41f363b73fSthorpej #include <sys/proc.h>
42f363b73fSthorpej #include <sys/conf.h>
43f363b73fSthorpej #include <sys/file.h>
44f363b73fSthorpej #include <sys/uio.h>
45f363b73fSthorpej #include <sys/kernel.h>
46f363b73fSthorpej #include <sys/syslog.h>
47f363b73fSthorpej #include <sys/types.h>
48f363b73fSthorpej #include <sys/device.h>
49f363b73fSthorpej 
50f363b73fSthorpej #include <machine/intr.h>
51cf10107dSdyoung #include <sys/bus.h>
52f363b73fSthorpej 
53f363b73fSthorpej #include <dev/ic/lptreg.h>
54f363b73fSthorpej #include <dev/ic/lptvar.h>
55f363b73fSthorpej 
56f363b73fSthorpej #include <dev/pci/pcivar.h>
57f363b73fSthorpej #include <dev/isa/isavar.h>
58f363b73fSthorpej 
59f363b73fSthorpej #include <alpha/sableio/sableiovar.h>
60f363b73fSthorpej 
61f363b73fSthorpej struct lpt_sableio_softc {
62f363b73fSthorpej 	struct lpt_softc sc_lpt;	/* real "lpt" softc */
63f363b73fSthorpej 
64f363b73fSthorpej 	/* STDIO-specific goo. */
65f363b73fSthorpej 	void	*sc_ih;			/* interrupt handler */
66f363b73fSthorpej };
67f363b73fSthorpej 
68*b7b2b8a3Sthorpej static int	lpt_sableio_match(device_t, cfdata_t , void *);
69*b7b2b8a3Sthorpej static void	lpt_sableio_attach(device_t, device_t, void *);
70f363b73fSthorpej 
718ecf8999Scube CFATTACH_DECL_NEW(lpt_sableio, sizeof(struct lpt_sableio_softc),
72b96bc0d7Sthorpej     lpt_sableio_match, lpt_sableio_attach, NULL, NULL);
73f363b73fSthorpej 
74*b7b2b8a3Sthorpej static int
lpt_sableio_match(device_t parent,cfdata_t match,void * aux)758ecf8999Scube lpt_sableio_match(device_t parent, cfdata_t match, void *aux)
76f363b73fSthorpej {
77f363b73fSthorpej 	struct sableio_attach_args *sa = aux;
78f363b73fSthorpej 
79f363b73fSthorpej 	/* Always present. */
80d1ad2ac4Sthorpej 	if (strcmp(sa->sa_name, match->cf_name) == 0)
81f363b73fSthorpej 		return (1);
82f363b73fSthorpej 
83f363b73fSthorpej 	return (0);
84f363b73fSthorpej }
85f363b73fSthorpej 
86*b7b2b8a3Sthorpej static void
lpt_sableio_attach(device_t parent,device_t self,void * aux)878ecf8999Scube lpt_sableio_attach(device_t parent, device_t self, void *aux)
88f363b73fSthorpej {
898ecf8999Scube 	struct lpt_sableio_softc *ssc = device_private(self);
90f363b73fSthorpej 	struct lpt_softc *sc = &ssc->sc_lpt;
91f363b73fSthorpej 	struct sableio_attach_args *sa = aux;
92f363b73fSthorpej 	const char *intrstr;
93e58a356cSchristos 	char buf[PCI_INTRSTR_LEN];
941099504eSthorpej 	pci_intr_handle_t ih;
95f363b73fSthorpej 
968ecf8999Scube 	sc->sc_dev = self;
97f363b73fSthorpej 	sc->sc_iot = sa->sa_iot;
98f363b73fSthorpej 
99f363b73fSthorpej 	if (bus_space_map(sc->sc_iot, sa->sa_ioaddr, LPT_NPORTS, 0,
100f363b73fSthorpej 	    &sc->sc_ioh) != 0) {
1018ecf8999Scube 		aprint_error(": can't map i/o space\n");
102f363b73fSthorpej 		return;
103f363b73fSthorpej 	}
104f363b73fSthorpej 
1058ecf8999Scube 	aprint_normal("\n");
1068ecf8999Scube 	aprint_naive("\n");
107f363b73fSthorpej 
108f363b73fSthorpej 	lpt_attach_subr(sc);
109f363b73fSthorpej 
1101099504eSthorpej 	alpha_pci_intr_handle_init(&ih, sa->sa_sableirq[0], 0);
1111099504eSthorpej 
1121099504eSthorpej 	intrstr = pci_intr_string(sa->sa_pc, ih, buf, sizeof(buf));
1131099504eSthorpej 	ssc->sc_ih = pci_intr_establish(sa->sa_pc, ih, IPL_TTY, lptintr, sc);
114f363b73fSthorpej 	if (ssc->sc_ih == NULL) {
1158ecf8999Scube 		aprint_error_dev(self, "unable to establish interrupt");
116f363b73fSthorpej 		if (intrstr != NULL)
1178ecf8999Scube 			aprint_error(" at %s", intrstr);
1188ecf8999Scube 		aprint_error("\n");
119f363b73fSthorpej 		return;
120f363b73fSthorpej 	}
1218ecf8999Scube 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
122f363b73fSthorpej }
123