1 /* $NetBSD: i82072.c,v 1.10 2008/04/28 20:23:28 martin Exp $ */
3 * Copyright (c) 2000 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.10 2008/04/28 20:23:28 martin Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/syslog.h>
38 #include <sys/socket.h>
39 #include <sys/device.h>
41 #include <sys/event.h>
43 #include <machine/cpu.h>
44 #include <machine/autoconf.h>
45 #include <machine/mainboard.h>
46 #include <machine/bus.h>
48 dev_type_open(fdopen
);
49 dev_type_strategy(fdstrategy
);
51 const struct bdevsw fd_bdevsw
= {
52 fdopen
, nullclose
, fdstrategy
, noioctl
, nodump
, nosize
, D_DISK
55 const struct cdevsw fd_cdevsw
= {
56 fdopen
, nullclose
, noread
, nowrite
, noioctl
,
57 nostop
, notty
, nopoll
, nommap
, nokqfilter
, D_DISK
60 #define I82072_STATUS 0x000003
61 #define I82072_DATA 0x000007
62 #define I82072_TC 0x800003
66 struct evcnt fd_intrcnt
;
67 bus_space_tag_t fd_bst
;
68 bus_space_handle_t fd_bsh
;
72 static int fd_match (struct device
*, struct cfdata
*, void *);
73 static void fd_attach (struct device
*, struct device
*, void *);
74 static void fd_reset (struct fd_softc
*);
76 CFATTACH_DECL(fd
, sizeof(struct fd_softc
),
77 fd_match
, fd_attach
, NULL
, NULL
);
79 static int fd_intr (void *);
82 fd_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
88 fd_attach(struct device
*parent
, struct device
*self
, void *aux
)
90 struct fd_softc
*sc
= (void *)self
;
91 struct confargs
*ca
= aux
;
93 sc
->fd_bst
= ca
->ca_bustag
;
94 if (bus_space_map(ca
->ca_bustag
, ca
->ca_addr
,
98 printf("%s: cannot map registers\n", self
->dv_xname
);
101 evcnt_attach_dynamic(&sc
->fd_intrcnt
, EVCNT_TYPE_INTR
, NULL
,
102 self
->dv_xname
, "intr");
104 bus_intr_establish(sc
->fd_bst
, SYS_INTR_FDC
, 0, 0, fd_intr
, sc
);
107 printf(": not fully implemented\n");
111 fd_reset(struct fd_softc
*sc
)
113 /* This clears any pending interrupts from the i82072 FDC */
114 bus_space_write_1(sc
->fd_bst
, sc
->fd_bsh
, I82072_STATUS
, 0x80);
116 bus_space_write_1(sc
->fd_bst
, sc
->fd_bsh
, I82072_TC
, 0x01);
121 fdopen(dev_t dev
, int flags
, int mode
, struct lwp
*l
)
127 fdstrategy(struct buf
*bp
)
135 struct fd_softc
*sc
= arg
;
137 sc
->fd_intrcnt
.ev_count
++;