atppc_puc.c revision 1.1 1 1.1 jdolecek /* $NetBSD: atppc_puc.c,v 1.1 2004/01/25 11:50:51 jdolecek Exp $ */
2 1.1 jdolecek
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 1.1 jdolecek * All rights reserved.
6 1.1 jdolecek *
7 1.1 jdolecek * This code is derived from software contributed to The NetBSD Foundation
8 1.1 jdolecek * by Jaromir Dolecek.
9 1.1 jdolecek *
10 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
11 1.1 jdolecek * modification, are permitted provided that the following conditions
12 1.1 jdolecek * are met:
13 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
14 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
15 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
17 1.1 jdolecek * documentation and/or other materials provided with the distribution.
18 1.1 jdolecek * 3. All advertising materials mentioning features or use of this software
19 1.1 jdolecek * must display the following acknowledgement:
20 1.1 jdolecek * This product includes software developed by the NetBSD
21 1.1 jdolecek * Foundation, Inc. and its contributors.
22 1.1 jdolecek * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 jdolecek * contributors may be used to endorse or promote products derived
24 1.1 jdolecek * from this software without specific prior written permission.
25 1.1 jdolecek *
26 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 jdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 jdolecek * POSSIBILITY OF SUCH DAMAGE.
37 1.1 jdolecek */
38 1.1 jdolecek
39 1.1 jdolecek #include "opt_atppc.h"
40 1.1 jdolecek
41 1.1 jdolecek #include <sys/cdefs.h>
42 1.1 jdolecek __KERNEL_RCSID(0, "$NetBSD: atppc_puc.c,v 1.1 2004/01/25 11:50:51 jdolecek Exp $");
43 1.1 jdolecek
44 1.1 jdolecek #include <sys/param.h>
45 1.1 jdolecek #include <sys/systm.h>
46 1.1 jdolecek #include <sys/errno.h>
47 1.1 jdolecek #include <sys/ioctl.h>
48 1.1 jdolecek #include <sys/syslog.h>
49 1.1 jdolecek #include <sys/device.h>
50 1.1 jdolecek #include <sys/proc.h>
51 1.1 jdolecek #include <sys/termios.h>
52 1.1 jdolecek
53 1.1 jdolecek #include <machine/bus.h>
54 1.1 jdolecek
55 1.1 jdolecek #include <dev/pci/pcivar.h>
56 1.1 jdolecek #include <dev/pci/pucvar.h>
57 1.1 jdolecek
58 1.1 jdolecek #include <dev/ic/atppcvar.h>
59 1.1 jdolecek
60 1.1 jdolecek static int atppc_puc_match(struct device *, struct cfdata *, void *);
61 1.1 jdolecek static void atppc_puc_attach(struct device *, struct device *, void *);
62 1.1 jdolecek
63 1.1 jdolecek CFATTACH_DECL(atppc_puc, sizeof(struct atppc_softc), atppc_puc_match,
64 1.1 jdolecek atppc_puc_attach, NULL, NULL);
65 1.1 jdolecek
66 1.1 jdolecek static int atppc_puc_dma_start(struct atppc_softc *, void *, u_int,
67 1.1 jdolecek u_int8_t);
68 1.1 jdolecek static int atppc_puc_dma_finish(struct atppc_softc *);
69 1.1 jdolecek static int atppc_puc_dma_abort(struct atppc_softc *);
70 1.1 jdolecek static int atppc_puc_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
71 1.1 jdolecek bus_size_t);
72 1.1 jdolecek static void atppc_puc_dma_free(struct device *, caddr_t *, bus_addr_t *,
73 1.1 jdolecek bus_size_t);
74 1.1 jdolecek
75 1.1 jdolecek /*
76 1.1 jdolecek * atppc_acpi_match: autoconf(9) match routine
77 1.1 jdolecek */
78 1.1 jdolecek static int
79 1.1 jdolecek atppc_puc_match(struct device *parent, struct cfdata *match, void *aux)
80 1.1 jdolecek {
81 1.1 jdolecek struct puc_attach_args *aa = aux;
82 1.1 jdolecek
83 1.1 jdolecek /*
84 1.1 jdolecek * Locators already matched, just check the type.
85 1.1 jdolecek */
86 1.1 jdolecek if (aa->type != PUC_PORT_TYPE_LPT)
87 1.1 jdolecek return (0);
88 1.1 jdolecek
89 1.1 jdolecek return (1);
90 1.1 jdolecek }
91 1.1 jdolecek
92 1.1 jdolecek static void
93 1.1 jdolecek atppc_puc_attach(struct device *parent, struct device *self, void *aux)
94 1.1 jdolecek {
95 1.1 jdolecek struct atppc_softc *sc = (struct atppc_softc *) self;
96 1.1 jdolecek struct puc_attach_args *aa = aux;
97 1.1 jdolecek const char *intrstr;
98 1.1 jdolecek
99 1.1 jdolecek sc->sc_dev_ok = ATPPC_NOATTACH;
100 1.1 jdolecek
101 1.1 jdolecek printf(": AT Parallel Port\n");
102 1.1 jdolecek
103 1.1 jdolecek /* Attach */
104 1.1 jdolecek sc->sc_iot = aa->t;
105 1.1 jdolecek sc->sc_ioh = aa->h;
106 1.1 jdolecek sc->sc_dmat = aa->dmat;
107 1.1 jdolecek sc->sc_has = 0;
108 1.1 jdolecek
109 1.1 jdolecek intrstr = pci_intr_string(aa->pc, aa->intrhandle);
110 1.1 jdolecek sc->sc_ieh = pci_intr_establish(aa->pc, aa->intrhandle, IPL_TTY,
111 1.1 jdolecek atppcintr, sc);
112 1.1 jdolecek if (sc->sc_ieh == NULL) {
113 1.1 jdolecek printf("%s: couldn't establish interrupt",
114 1.1 jdolecek sc->sc_dev.dv_xname);
115 1.1 jdolecek if (intrstr != NULL)
116 1.1 jdolecek printf(" at %s", intrstr);
117 1.1 jdolecek printf("\n");
118 1.1 jdolecek return;
119 1.1 jdolecek }
120 1.1 jdolecek printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
121 1.1 jdolecek sc->sc_has |= ATPPC_HAS_INTR;
122 1.1 jdolecek
123 1.1 jdolecek /* setup DMA hooks */
124 1.1 jdolecek /* XXX setup dma maps */
125 1.1 jdolecek sc->sc_dma_start = atppc_puc_dma_start;
126 1.1 jdolecek sc->sc_dma_finish = atppc_puc_dma_finish;
127 1.1 jdolecek sc->sc_dma_abort = atppc_puc_dma_abort;
128 1.1 jdolecek sc->sc_dma_malloc = atppc_puc_dma_malloc;
129 1.1 jdolecek sc->sc_dma_free = atppc_puc_dma_free;
130 1.1 jdolecek //sc->sc_has |= ATPPC_HAS_DMA;
131 1.1 jdolecek
132 1.1 jdolecek /* Finished attach */
133 1.1 jdolecek sc->sc_dev_ok = ATPPC_ATTACHED;
134 1.1 jdolecek
135 1.1 jdolecek /* Run soft configuration attach */
136 1.1 jdolecek atppc_sc_attach(sc);
137 1.1 jdolecek }
138 1.1 jdolecek
139 1.1 jdolecek /* Start DMA operation over PCI bus */
140 1.1 jdolecek static int
141 1.1 jdolecek atppc_puc_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
142 1.1 jdolecek u_int8_t mode)
143 1.1 jdolecek {
144 1.1 jdolecek
145 1.1 jdolecek /* Nothing to do */
146 1.1 jdolecek return (0);
147 1.1 jdolecek }
148 1.1 jdolecek
149 1.1 jdolecek /* Stop DMA operation over PCI bus */
150 1.1 jdolecek static int
151 1.1 jdolecek atppc_puc_dma_finish(struct atppc_softc * lsc)
152 1.1 jdolecek {
153 1.1 jdolecek
154 1.1 jdolecek /* Nothing to do */
155 1.1 jdolecek return (0);
156 1.1 jdolecek }
157 1.1 jdolecek
158 1.1 jdolecek /* Abort DMA operation over PCI bus */
159 1.1 jdolecek int
160 1.1 jdolecek atppc_puc_dma_abort(struct atppc_softc * lsc)
161 1.1 jdolecek {
162 1.1 jdolecek
163 1.1 jdolecek /* Nothing to do */
164 1.1 jdolecek return (0);
165 1.1 jdolecek }
166 1.1 jdolecek
167 1.1 jdolecek /* Allocate memory for DMA over PCI bus */
168 1.1 jdolecek int
169 1.1 jdolecek atppc_puc_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
170 1.1 jdolecek bus_size_t size)
171 1.1 jdolecek {
172 1.1 jdolecek return 0;
173 1.1 jdolecek /*
174 1.1 jdolecek struct atppc_puc_softc * sc = (struct atppc_acpi_softc *) dev;
175 1.1 jdolecek
176 1.1 jdolecek return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
177 1.1 jdolecek */
178 1.1 jdolecek }
179 1.1 jdolecek
180 1.1 jdolecek /* Free memory allocated by atppc_isa_dma_malloc() */
181 1.1 jdolecek void
182 1.1 jdolecek atppc_puc_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
183 1.1 jdolecek bus_size_t size)
184 1.1 jdolecek {
185 1.1 jdolecek /*
186 1.1 jdolecek struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) dev;
187 1.1 jdolecek
188 1.1 jdolecek return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
189 1.1 jdolecek */
190 1.1 jdolecek }
191