xref: /netbsd-src/sys/dev/isa/attimer_isa.c (revision 7fa608457b817eca6e0977b37f758ae064f3c99c)
1 /*	$NetBSD: attimer_isa.c,v 1.7 2007/10/19 12:00:15 ad Exp $	*/
2 
3 /*
4  *  Copyright (c) 2005 The NetBSD Foundation.
5  *  All rights reserved.
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *  1. Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *  2. Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution.
15  *  3. Neither the name of The NetBSD Foundation nor the names of its
16  *     contributors may be used to endorse or promote products derived
17  *     from this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1996 Carnegie-Mellon University.
34  * All rights reserved.
35  *
36  * Author: Chris G. Demetriou
37  *
38  * Permission to use, copy, modify and distribute this software and
39  * its documentation is hereby granted, provided that both the copyright
40  * notice and this permission notice appear in all copies of the
41  * software, derivative works or modified versions, and any portions
42  * thereof, and that both notices appear in supporting documentation.
43  *
44  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47  *
48  * Carnegie Mellon requests users of this software to return to
49  *
50  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
51  *  School of Computer Science
52  *  Carnegie Mellon University
53  *  Pittsburgh PA 15213-3890
54  *
55  * any improvements or extensions that they make and grant Carnegie the
56  * rights to redistribute these changes.
57  */
58 
59 /*
60  * ISA attachment for attimer(4)
61  */
62 
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: attimer_isa.c,v 1.7 2007/10/19 12:00:15 ad Exp $");
65 
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/errno.h>
69 #include <sys/ioctl.h>
70 #include <sys/device.h>
71 #include <sys/proc.h>
72 
73 #include <sys/bus.h>
74 
75 #include <dev/ic/attimervar.h>
76 
77 #include <dev/isa/isareg.h>
78 #include <dev/isa/isavar.h>
79 
80 static int	attimer_isa_match(struct device *, struct cfdata *, void *);
81 static void	attimer_isa_attach(struct device *, struct device *, void *);
82 
83 CFATTACH_DECL(attimer_isa, sizeof(struct attimer_softc),
84     attimer_isa_match, attimer_isa_attach, NULL, NULL);
85 
86 static int
87 attimer_isa_match(struct device *parent, struct cfdata *match,
88     void *aux)
89 {
90 	struct isa_attach_args *ia = aux;
91 	bus_space_handle_t att_ioh;
92 
93 	if (ISA_DIRECT_CONFIG(ia))
94 		return (0);
95 
96 	/* If values are hardwired to something that they can't be, punt. */
97 	if (ia->ia_nio < 1 ||
98 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
99 	    ia->ia_io[0].ir_addr != IO_TIMER1))
100 		return (0);
101 
102 	if (ia->ia_niomem > 0 &&
103 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
104 		return (0);
105 
106 	if (ia->ia_nirq > 0 &&
107 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
108 		return (0);
109 
110 	if (ia->ia_ndrq > 0 &&
111 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
112 		return (0);
113 
114 	if (bus_space_map(ia->ia_iot, IO_TIMER1, 4, 0, &att_ioh))
115 		return 0;
116 	bus_space_unmap(ia->ia_iot, att_ioh, 4);
117 
118 	ia->ia_io[0].ir_addr = IO_TIMER1;
119 	ia->ia_io[0].ir_size = 4;
120 	ia->ia_nio = 1;
121 
122 	ia->ia_niomem = 0;
123 	ia->ia_nirq = 0;
124 	ia->ia_ndrq = 0;
125 
126 	return 1;
127 }
128 
129 static void
130 attimer_isa_attach(struct device *parent, struct device *self,
131     void *aux)
132 {
133 	struct attimer_softc *sc = (struct attimer_softc *)self;
134 	struct isa_attach_args *ia = aux;
135 
136 	sc->sc_iot = ia->ia_iot;
137 
138 	aprint_naive(": AT Timer\n");
139 	aprint_normal(": AT Timer\n");
140 
141 	if (bus_space_map(sc->sc_iot, IO_TIMER1, 4, 0, &sc->sc_ioh) != 0)
142 		aprint_error("%s: could not map registers\n",
143 		    sc->sc_dev.dv_xname);
144 	else
145 		attimer_attach(sc);
146 }
147