2014-07-25 12:10:31 +04:00
|
|
|
/* $NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland Exp $ */
|
2000-08-13 02:57:55 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Wayne Knowles
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:43:09 +04:00
|
|
|
#include <sys/cdefs.h>
|
2014-07-25 12:10:31 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland Exp $");
|
2003-07-15 06:43:09 +04:00
|
|
|
|
2000-08-13 02:57:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
2000-12-03 07:51:04 +03:00
|
|
|
#include <sys/conf.h>
|
2002-10-23 13:10:23 +04:00
|
|
|
#include <sys/event.h>
|
2000-08-13 02:57:55 +04:00
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/mainboard.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2000-12-03 07:51:04 +03:00
|
|
|
dev_type_open(fdopen);
|
|
|
|
dev_type_strategy(fdstrategy);
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
const struct bdevsw fd_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = fdopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_strategy = fdstrategy,
|
|
|
|
.d_ioctl = noioctl,
|
|
|
|
.d_dump = nodump,
|
|
|
|
.d_psize = nosize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw fd_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = fdopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_read = noread,
|
|
|
|
.d_write = nowrite,
|
|
|
|
.d_ioctl = noioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
2000-12-03 07:51:04 +03:00
|
|
|
|
2000-08-13 02:57:55 +04:00
|
|
|
#define I82072_STATUS 0x000003
|
|
|
|
#define I82072_DATA 0x000007
|
|
|
|
#define I82072_TC 0x800003
|
|
|
|
|
|
|
|
struct fd_softc {
|
2012-10-27 21:17:22 +04:00
|
|
|
device_t dev;
|
2000-08-13 02:57:55 +04:00
|
|
|
struct evcnt fd_intrcnt;
|
|
|
|
bus_space_tag_t fd_bst;
|
|
|
|
bus_space_handle_t fd_bsh;
|
|
|
|
int unit;
|
|
|
|
};
|
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
static int fd_match (device_t, cfdata_t, void *);
|
|
|
|
static void fd_attach (device_t, device_t, void *);
|
2000-12-03 07:51:04 +03:00
|
|
|
static void fd_reset (struct fd_softc *);
|
2000-08-13 02:57:55 +04:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
|
2002-10-02 08:55:47 +04:00
|
|
|
fd_match, fd_attach, NULL, NULL);
|
2000-08-13 02:57:55 +04:00
|
|
|
|
2000-12-03 07:51:04 +03:00
|
|
|
static int fd_intr (void *);
|
2000-08-15 08:56:45 +04:00
|
|
|
|
2000-08-13 02:57:55 +04:00
|
|
|
int
|
2012-10-27 21:17:22 +04:00
|
|
|
fd_match(device_t parent, cfdata_t cf, void *aux)
|
2000-08-13 02:57:55 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-27 21:17:22 +04:00
|
|
|
fd_attach(device_t parent, device_t self, void *aux)
|
2000-08-13 02:57:55 +04:00
|
|
|
{
|
2012-10-27 21:17:22 +04:00
|
|
|
struct fd_softc *sc = device_private(self);
|
2000-08-13 02:57:55 +04:00
|
|
|
struct confargs *ca = aux;
|
|
|
|
|
|
|
|
sc->fd_bst = ca->ca_bustag;
|
|
|
|
if (bus_space_map(ca->ca_bustag, ca->ca_addr,
|
|
|
|
0x1000000,
|
|
|
|
BUS_SPACE_MAP_LINEAR,
|
|
|
|
&sc->fd_bsh) != 0) {
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s: cannot map registers\n", device_xname(self));
|
2000-08-13 02:57:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
|
2012-10-27 21:17:22 +04:00
|
|
|
device_xname(self), "intr");
|
2000-08-13 02:57:55 +04:00
|
|
|
|
2000-08-15 08:56:45 +04:00
|
|
|
bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
|
|
|
|
|
2000-08-13 02:57:55 +04:00
|
|
|
fd_reset(sc);
|
|
|
|
printf(": not fully implemented\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-03 07:51:04 +03:00
|
|
|
fd_reset(struct fd_softc *sc)
|
2000-08-13 02:57:55 +04:00
|
|
|
{
|
|
|
|
/* This clears any pending interrupts from the i82072 FDC */
|
|
|
|
bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
|
|
|
|
DELAY(1000);
|
|
|
|
bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
|
|
|
|
DELAY(1000);
|
|
|
|
}
|
|
|
|
|
2000-12-03 07:51:04 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
fdopen(dev_t dev, int flags, int mode, struct lwp *l)
|
2000-12-03 07:51:04 +03:00
|
|
|
{
|
|
|
|
return (EBADF);
|
|
|
|
}
|
2000-08-13 02:57:55 +04:00
|
|
|
|
|
|
|
void
|
2000-12-03 07:51:04 +03:00
|
|
|
fdstrategy(struct buf *bp)
|
|
|
|
{
|
|
|
|
panic("fdstrategy");
|
|
|
|
}
|
2000-08-13 02:57:55 +04:00
|
|
|
|
2000-08-15 08:56:45 +04:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
fd_intr(void *arg)
|
2000-08-13 02:57:55 +04:00
|
|
|
{
|
2000-08-15 08:56:45 +04:00
|
|
|
struct fd_softc *sc = arg;
|
|
|
|
|
|
|
|
sc->fd_intrcnt.ev_count++;
|
|
|
|
fd_reset(sc);
|
|
|
|
return 0;
|
2000-08-13 02:57:55 +04:00
|
|
|
}
|