1*f9228f42Sdholland /* $NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland Exp $ */
23f55a7b9Swdk /*-
33f55a7b9Swdk * Copyright (c) 2000 The NetBSD Foundation, Inc.
43f55a7b9Swdk * All rights reserved.
53f55a7b9Swdk *
63f55a7b9Swdk * This code is derived from software contributed to The NetBSD Foundation
73f55a7b9Swdk * by Wayne Knowles
83f55a7b9Swdk *
93f55a7b9Swdk * Redistribution and use in source and binary forms, with or without
103f55a7b9Swdk * modification, are permitted provided that the following conditions
113f55a7b9Swdk * are met:
123f55a7b9Swdk * 1. Redistributions of source code must retain the above copyright
133f55a7b9Swdk * notice, this list of conditions and the following disclaimer.
143f55a7b9Swdk * 2. Redistributions in binary form must reproduce the above copyright
153f55a7b9Swdk * notice, this list of conditions and the following disclaimer in the
163f55a7b9Swdk * documentation and/or other materials provided with the distribution.
173f55a7b9Swdk *
183f55a7b9Swdk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
193f55a7b9Swdk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
203f55a7b9Swdk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
213f55a7b9Swdk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
223f55a7b9Swdk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
233f55a7b9Swdk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
243f55a7b9Swdk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
253f55a7b9Swdk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
263f55a7b9Swdk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
273f55a7b9Swdk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
283f55a7b9Swdk * POSSIBILITY OF SUCH DAMAGE.
293f55a7b9Swdk */
303f55a7b9Swdk
314b2744bfSlukem #include <sys/cdefs.h>
32*f9228f42Sdholland __KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland Exp $");
334b2744bfSlukem
343f55a7b9Swdk #include <sys/param.h>
353f55a7b9Swdk #include <sys/systm.h>
363f55a7b9Swdk #include <sys/mbuf.h>
373f55a7b9Swdk #include <sys/syslog.h>
383f55a7b9Swdk #include <sys/socket.h>
393f55a7b9Swdk #include <sys/device.h>
40bd338a51Smatt #include <sys/conf.h>
41e0cc03a0Sjdolecek #include <sys/event.h>
423f55a7b9Swdk
433f55a7b9Swdk #include <machine/cpu.h>
443f55a7b9Swdk #include <machine/autoconf.h>
453f55a7b9Swdk #include <machine/mainboard.h>
463f55a7b9Swdk #include <machine/bus.h>
473f55a7b9Swdk
48bd338a51Smatt dev_type_open(fdopen);
49bd338a51Smatt dev_type_strategy(fdstrategy);
50bd338a51Smatt
5177a6b82bSgehenna const struct bdevsw fd_bdevsw = {
52a68f9396Sdholland .d_open = fdopen,
53a68f9396Sdholland .d_close = nullclose,
54a68f9396Sdholland .d_strategy = fdstrategy,
55a68f9396Sdholland .d_ioctl = noioctl,
56a68f9396Sdholland .d_dump = nodump,
57a68f9396Sdholland .d_psize = nosize,
588c70ef39Sdholland .d_discard = nodiscard,
59a68f9396Sdholland .d_flag = D_DISK
6077a6b82bSgehenna };
6177a6b82bSgehenna
6277a6b82bSgehenna const struct cdevsw fd_cdevsw = {
63a68f9396Sdholland .d_open = fdopen,
64a68f9396Sdholland .d_close = nullclose,
65a68f9396Sdholland .d_read = noread,
66a68f9396Sdholland .d_write = nowrite,
67a68f9396Sdholland .d_ioctl = noioctl,
68a68f9396Sdholland .d_stop = nostop,
69a68f9396Sdholland .d_tty = notty,
70a68f9396Sdholland .d_poll = nopoll,
71a68f9396Sdholland .d_mmap = nommap,
72a68f9396Sdholland .d_kqfilter = nokqfilter,
73*f9228f42Sdholland .d_discard = nodiscard,
74a68f9396Sdholland .d_flag = D_DISK
7577a6b82bSgehenna };
76bd338a51Smatt
773f55a7b9Swdk #define I82072_STATUS 0x000003
783f55a7b9Swdk #define I82072_DATA 0x000007
793f55a7b9Swdk #define I82072_TC 0x800003
803f55a7b9Swdk
813f55a7b9Swdk struct fd_softc {
82cbab9cadSchs device_t dev;
833f55a7b9Swdk struct evcnt fd_intrcnt;
843f55a7b9Swdk bus_space_tag_t fd_bst;
853f55a7b9Swdk bus_space_handle_t fd_bsh;
863f55a7b9Swdk int unit;
873f55a7b9Swdk };
883f55a7b9Swdk
89cbab9cadSchs static int fd_match (device_t, cfdata_t, void *);
90cbab9cadSchs static void fd_attach (device_t, device_t, void *);
91bd338a51Smatt static void fd_reset (struct fd_softc *);
923f55a7b9Swdk
93cbab9cadSchs CFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
94c5e91d44Sthorpej fd_match, fd_attach, NULL, NULL);
953f55a7b9Swdk
96bd338a51Smatt static int fd_intr (void *);
9733016f23Swdk
983f55a7b9Swdk int
fd_match(device_t parent,cfdata_t cf,void * aux)99cbab9cadSchs fd_match(device_t parent, cfdata_t cf, void *aux)
1003f55a7b9Swdk {
1013f55a7b9Swdk return 1;
1023f55a7b9Swdk }
1033f55a7b9Swdk
1043f55a7b9Swdk void
fd_attach(device_t parent,device_t self,void * aux)105cbab9cadSchs fd_attach(device_t parent, device_t self, void *aux)
1063f55a7b9Swdk {
107cbab9cadSchs struct fd_softc *sc = device_private(self);
1083f55a7b9Swdk struct confargs *ca = aux;
1093f55a7b9Swdk
1103f55a7b9Swdk sc->fd_bst = ca->ca_bustag;
1113f55a7b9Swdk if (bus_space_map(ca->ca_bustag, ca->ca_addr,
1123f55a7b9Swdk 0x1000000,
1133f55a7b9Swdk BUS_SPACE_MAP_LINEAR,
1143f55a7b9Swdk &sc->fd_bsh) != 0) {
115cbab9cadSchs printf("%s: cannot map registers\n", device_xname(self));
1163f55a7b9Swdk return;
1173f55a7b9Swdk }
1183f55a7b9Swdk evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
119cbab9cadSchs device_xname(self), "intr");
1203f55a7b9Swdk
12133016f23Swdk bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
12233016f23Swdk
1233f55a7b9Swdk fd_reset(sc);
1243f55a7b9Swdk printf(": not fully implemented\n");
1253f55a7b9Swdk }
1263f55a7b9Swdk
1273f55a7b9Swdk void
fd_reset(struct fd_softc * sc)128bd338a51Smatt fd_reset(struct fd_softc *sc)
1293f55a7b9Swdk {
1303f55a7b9Swdk /* This clears any pending interrupts from the i82072 FDC */
1313f55a7b9Swdk bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
1323f55a7b9Swdk DELAY(1000);
1333f55a7b9Swdk bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
1343f55a7b9Swdk DELAY(1000);
1353f55a7b9Swdk }
1363f55a7b9Swdk
137bd338a51Smatt int
fdopen(dev_t dev,int flags,int mode,struct lwp * l)13895e1ffb1Schristos fdopen(dev_t dev, int flags, int mode, struct lwp *l)
139bd338a51Smatt {
140bd338a51Smatt return (EBADF);
141bd338a51Smatt }
142bd338a51Smatt
1433f55a7b9Swdk void
fdstrategy(struct buf * bp)144bd338a51Smatt fdstrategy(struct buf *bp)
145bd338a51Smatt {
146bd338a51Smatt panic("fdstrategy");
147bd338a51Smatt }
1483f55a7b9Swdk
14933016f23Swdk static int
fd_intr(void * arg)150454af1c0Sdsl fd_intr(void *arg)
1513f55a7b9Swdk {
15233016f23Swdk struct fd_softc *sc = arg;
1533f55a7b9Swdk
1543f55a7b9Swdk sc->fd_intrcnt.ev_count++;
1553f55a7b9Swdk fd_reset(sc);
15633016f23Swdk return 0;
1573f55a7b9Swdk }
158