i82072.c revision 1.3
11.3Smatt/*	$NetBSD: i82072.c,v 1.3 2000/12/03 04:51:05 matt Exp $	*/
21.1Swdk/*-
31.1Swdk * Copyright (c) 2000 The NetBSD Foundation, Inc.
41.1Swdk * All rights reserved.
51.1Swdk *
61.1Swdk * This code is derived from software contributed to The NetBSD Foundation
71.1Swdk * by Wayne Knowles
81.1Swdk *
91.1Swdk * Redistribution and use in source and binary forms, with or without
101.1Swdk * modification, are permitted provided that the following conditions
111.1Swdk * are met:
121.1Swdk * 1. Redistributions of source code must retain the above copyright
131.1Swdk *    notice, this list of conditions and the following disclaimer.
141.1Swdk * 2. Redistributions in binary form must reproduce the above copyright
151.1Swdk *    notice, this list of conditions and the following disclaimer in the
161.1Swdk *    documentation and/or other materials provided with the distribution.
171.1Swdk * 3. All advertising materials mentioning features or use of this software
181.1Swdk *    must display the following acknowledgement:
191.1Swdk *        This product includes software developed by the NetBSD
201.1Swdk *        Foundation, Inc. and its contributors.
211.1Swdk * 4. Neither the name of The NetBSD Foundation nor the names of its
221.1Swdk *    contributors may be used to endorse or promote products derived
231.1Swdk *    from this software without specific prior written permission.
241.1Swdk *
251.1Swdk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
261.1Swdk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Swdk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Swdk * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
291.1Swdk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Swdk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Swdk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Swdk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Swdk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Swdk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Swdk * POSSIBILITY OF SUCH DAMAGE.
361.1Swdk */
371.1Swdk
381.1Swdk#include <sys/param.h>
391.1Swdk#include <sys/systm.h>
401.1Swdk#include <sys/mbuf.h>
411.1Swdk#include <sys/syslog.h>
421.1Swdk#include <sys/socket.h>
431.1Swdk#include <sys/device.h>
441.3Smatt#include <sys/conf.h>
451.1Swdk
461.1Swdk#include <machine/cpu.h>
471.1Swdk#include <machine/autoconf.h>
481.1Swdk#include <machine/mainboard.h>
491.1Swdk#include <machine/bus.h>
501.1Swdk
511.3Smattdev_type_open(fdopen);
521.3Smattdev_type_close(fdclose);
531.3Smattdev_type_ioctl(fdioctl);
541.3Smattdev_type_size(fdsize);
551.3Smattdev_type_dump(fddump);
561.3Smattdev_type_strategy(fdstrategy);
571.3Smatt
581.3Smatt
591.1Swdk#define	I82072_STATUS	0x000003
601.1Swdk#define	I82072_DATA	0x000007
611.1Swdk#define	I82072_TC	0x800003
621.1Swdk
631.1Swdkstruct	fd_softc {
641.1Swdk        struct  device dev;
651.1Swdk        struct  evcnt  fd_intrcnt;
661.1Swdk	bus_space_tag_t	fd_bst;
671.1Swdk	bus_space_handle_t fd_bsh;
681.1Swdk        int     unit;
691.1Swdk};
701.1Swdk
711.3Smattstatic int	fd_match (struct device *, struct cfdata *, void *);
721.3Smattstatic void	fd_attach (struct device *, struct device *, void *);
731.3Smattstatic void     fd_reset (struct fd_softc *);
741.1Swdk
751.1Swdkstruct cfattach fd_ca = {
761.1Swdk	sizeof(struct fd_softc), fd_match, fd_attach
771.1Swdk};
781.1Swdk
791.3Smattstatic int	fd_intr (void *);
801.2Swdk
811.1Swdkint
821.3Smattfd_match(struct device *parent, struct cfdata *cf, void *aux)
831.1Swdk{
841.1Swdk	return 1;
851.1Swdk}
861.1Swdk
871.1Swdkvoid
881.3Smattfd_attach(struct device *parent, struct device *self, void *aux)
891.1Swdk{
901.1Swdk        struct fd_softc *sc = (void *)self;
911.1Swdk	struct confargs *ca = aux;
921.1Swdk
931.1Swdk	sc->fd_bst = ca->ca_bustag;
941.1Swdk	if (bus_space_map(ca->ca_bustag, ca->ca_addr,
951.1Swdk			  0x1000000,
961.1Swdk			  BUS_SPACE_MAP_LINEAR,
971.1Swdk			  &sc->fd_bsh) != 0) {
981.1Swdk		printf("%s: cannot map registers\n", self->dv_xname);
991.1Swdk		return;
1001.1Swdk	}
1011.1Swdk	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
1021.1Swdk			     self->dv_xname, "intr");
1031.1Swdk
1041.2Swdk	bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
1051.2Swdk
1061.1Swdk	fd_reset(sc);
1071.1Swdk	printf(": not fully implemented\n");
1081.1Swdk}
1091.1Swdk
1101.1Swdkvoid
1111.3Smattfd_reset(struct fd_softc *sc)
1121.1Swdk{
1131.1Swdk	/* This clears any pending interrupts from the i82072 FDC */
1141.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
1151.1Swdk	DELAY(1000);
1161.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
1171.1Swdk	DELAY(1000);
1181.1Swdk}
1191.1Swdk
1201.3Smattint
1211.3Smattfdopen(dev_t dev, int flags, int mode, struct proc *p)
1221.3Smatt{
1231.3Smatt	return (EBADF);
1241.3Smatt}
1251.1Swdk
1261.3Smattint
1271.3Smattfdclose(dev_t dev, int flags, int mode, struct proc *p)
1281.3Smatt{
1291.3Smatt	return 0;
1301.3Smatt}
1311.1Swdk
1321.1Swdkvoid
1331.3Smattfdstrategy(struct buf *bp)
1341.3Smatt{
1351.3Smatt	panic("fdstrategy");
1361.3Smatt}
1371.1Swdk
1381.3Smattint
1391.3Smattfdioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
1401.3Smatt{
1411.3Smatt	return (EINVAL);
1421.3Smatt}
1431.1Swdk
1441.3Smattint
1451.3Smattfddump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
1461.3Smatt{
1471.3Smatt	return (ENODEV);
1481.3Smatt}
1491.1Swdk
1501.3Smattint
1511.3Smattfdsize(dev_t dev)
1521.3Smatt{
1531.3Smatt	return (0);
1541.3Smatt}
1551.1Swdk
1561.2Swdkstatic int
1571.2Swdkfd_intr(arg)
1581.2Swdk	void *arg;
1591.1Swdk{
1601.2Swdk	struct fd_softc *sc = arg;
1611.1Swdk
1621.2Swdk	sc->fd_intrcnt.ev_count++;
1631.2Swdk	fd_reset(sc);
1641.2Swdk	return 0;
1651.1Swdk}
166