i82072.c revision 1.12
11.12Schs/*	$NetBSD: i82072.c,v 1.12 2012/10/27 17:18:03 chs 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 *
181.1Swdk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Swdk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Swdk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Swdk * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Swdk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Swdk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Swdk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Swdk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Swdk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Swdk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Swdk * POSSIBILITY OF SUCH DAMAGE.
291.1Swdk */
301.8Slukem
311.8Slukem#include <sys/cdefs.h>
321.12Schs__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.12 2012/10/27 17:18:03 chs Exp $");
331.1Swdk
341.1Swdk#include <sys/param.h>
351.1Swdk#include <sys/systm.h>
361.1Swdk#include <sys/mbuf.h>
371.1Swdk#include <sys/syslog.h>
381.1Swdk#include <sys/socket.h>
391.1Swdk#include <sys/device.h>
401.3Smatt#include <sys/conf.h>
411.7Sjdolecek#include <sys/event.h>
421.1Swdk
431.1Swdk#include <machine/cpu.h>
441.1Swdk#include <machine/autoconf.h>
451.1Swdk#include <machine/mainboard.h>
461.1Swdk#include <machine/bus.h>
471.1Swdk
481.3Smattdev_type_open(fdopen);
491.3Smattdev_type_strategy(fdstrategy);
501.3Smatt
511.4Sgehennaconst struct bdevsw fd_bdevsw = {
521.4Sgehenna	fdopen, nullclose, fdstrategy, noioctl, nodump, nosize, D_DISK
531.4Sgehenna};
541.4Sgehenna
551.4Sgehennaconst struct cdevsw fd_cdevsw = {
561.4Sgehenna	fdopen, nullclose, noread, nowrite, noioctl,
571.7Sjdolecek	nostop, notty, nopoll, nommap, nokqfilter, D_DISK
581.4Sgehenna};
591.3Smatt
601.1Swdk#define	I82072_STATUS	0x000003
611.1Swdk#define	I82072_DATA	0x000007
621.1Swdk#define	I82072_TC	0x800003
631.1Swdk
641.1Swdkstruct	fd_softc {
651.12Schs        device_t dev;
661.1Swdk        struct  evcnt  fd_intrcnt;
671.1Swdk	bus_space_tag_t	fd_bst;
681.1Swdk	bus_space_handle_t fd_bsh;
691.1Swdk        int     unit;
701.1Swdk};
711.1Swdk
721.12Schsstatic int	fd_match (device_t, cfdata_t, void *);
731.12Schsstatic void	fd_attach (device_t, device_t, void *);
741.3Smattstatic void     fd_reset (struct fd_softc *);
751.1Swdk
761.12SchsCFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
771.6Sthorpej    fd_match, fd_attach, NULL, NULL);
781.1Swdk
791.3Smattstatic int	fd_intr (void *);
801.2Swdk
811.1Swdkint
821.12Schsfd_match(device_t parent, cfdata_t cf, void *aux)
831.1Swdk{
841.1Swdk	return 1;
851.1Swdk}
861.1Swdk
871.1Swdkvoid
881.12Schsfd_attach(device_t parent, device_t self, void *aux)
891.1Swdk{
901.12Schs        struct fd_softc *sc = device_private(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.12Schs		printf("%s: cannot map registers\n", device_xname(self));
991.1Swdk		return;
1001.1Swdk	}
1011.1Swdk	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
1021.12Schs			     device_xname(self), "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.9Schristosfdopen(dev_t dev, int flags, int mode, struct lwp *l)
1221.3Smatt{
1231.3Smatt	return (EBADF);
1241.3Smatt}
1251.1Swdk
1261.1Swdkvoid
1271.3Smattfdstrategy(struct buf *bp)
1281.3Smatt{
1291.3Smatt	panic("fdstrategy");
1301.3Smatt}
1311.1Swdk
1321.2Swdkstatic int
1331.11Sdslfd_intr(void *arg)
1341.1Swdk{
1351.2Swdk	struct fd_softc *sc = arg;
1361.1Swdk
1371.2Swdk	sc->fd_intrcnt.ev_count++;
1381.2Swdk	fd_reset(sc);
1391.2Swdk	return 0;
1401.1Swdk}
141