11.15Sdholland/*	$NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland 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.15Sdholland__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.15 2014/07/25 08:10:34 dholland 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.13Sdholland	.d_open = fdopen,
531.13Sdholland	.d_close = nullclose,
541.13Sdholland	.d_strategy = fdstrategy,
551.13Sdholland	.d_ioctl = noioctl,
561.13Sdholland	.d_dump = nodump,
571.13Sdholland	.d_psize = nosize,
581.14Sdholland	.d_discard = nodiscard,
591.13Sdholland	.d_flag = D_DISK
601.4Sgehenna};
611.4Sgehenna
621.4Sgehennaconst struct cdevsw fd_cdevsw = {
631.13Sdholland	.d_open = fdopen,
641.13Sdholland	.d_close = nullclose,
651.13Sdholland	.d_read = noread,
661.13Sdholland	.d_write = nowrite,
671.13Sdholland	.d_ioctl = noioctl,
681.13Sdholland	.d_stop = nostop,
691.13Sdholland	.d_tty = notty,
701.13Sdholland	.d_poll = nopoll,
711.13Sdholland	.d_mmap = nommap,
721.13Sdholland	.d_kqfilter = nokqfilter,
731.15Sdholland	.d_discard = nodiscard,
741.13Sdholland	.d_flag = D_DISK
751.4Sgehenna};
761.3Smatt
771.1Swdk#define	I82072_STATUS	0x000003
781.1Swdk#define	I82072_DATA	0x000007
791.1Swdk#define	I82072_TC	0x800003
801.1Swdk
811.1Swdkstruct	fd_softc {
821.12Schs        device_t dev;
831.1Swdk        struct  evcnt  fd_intrcnt;
841.1Swdk	bus_space_tag_t	fd_bst;
851.1Swdk	bus_space_handle_t fd_bsh;
861.1Swdk        int     unit;
871.1Swdk};
881.1Swdk
891.12Schsstatic int	fd_match (device_t, cfdata_t, void *);
901.12Schsstatic void	fd_attach (device_t, device_t, void *);
911.3Smattstatic void     fd_reset (struct fd_softc *);
921.1Swdk
931.12SchsCFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
941.6Sthorpej    fd_match, fd_attach, NULL, NULL);
951.1Swdk
961.3Smattstatic int	fd_intr (void *);
971.2Swdk
981.1Swdkint
991.12Schsfd_match(device_t parent, cfdata_t cf, void *aux)
1001.1Swdk{
1011.1Swdk	return 1;
1021.1Swdk}
1031.1Swdk
1041.1Swdkvoid
1051.12Schsfd_attach(device_t parent, device_t self, void *aux)
1061.1Swdk{
1071.12Schs        struct fd_softc *sc = device_private(self);
1081.1Swdk	struct confargs *ca = aux;
1091.1Swdk
1101.1Swdk	sc->fd_bst = ca->ca_bustag;
1111.1Swdk	if (bus_space_map(ca->ca_bustag, ca->ca_addr,
1121.1Swdk			  0x1000000,
1131.1Swdk			  BUS_SPACE_MAP_LINEAR,
1141.1Swdk			  &sc->fd_bsh) != 0) {
1151.12Schs		printf("%s: cannot map registers\n", device_xname(self));
1161.1Swdk		return;
1171.1Swdk	}
1181.1Swdk	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
1191.12Schs			     device_xname(self), "intr");
1201.1Swdk
1211.2Swdk	bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
1221.2Swdk
1231.1Swdk	fd_reset(sc);
1241.1Swdk	printf(": not fully implemented\n");
1251.1Swdk}
1261.1Swdk
1271.1Swdkvoid
1281.3Smattfd_reset(struct fd_softc *sc)
1291.1Swdk{
1301.1Swdk	/* This clears any pending interrupts from the i82072 FDC */
1311.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
1321.1Swdk	DELAY(1000);
1331.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
1341.1Swdk	DELAY(1000);
1351.1Swdk}
1361.1Swdk
1371.3Smattint
1381.9Schristosfdopen(dev_t dev, int flags, int mode, struct lwp *l)
1391.3Smatt{
1401.3Smatt	return (EBADF);
1411.3Smatt}
1421.1Swdk
1431.1Swdkvoid
1441.3Smattfdstrategy(struct buf *bp)
1451.3Smatt{
1461.3Smatt	panic("fdstrategy");
1471.3Smatt}
1481.1Swdk
1491.2Swdkstatic int
1501.11Sdslfd_intr(void *arg)
1511.1Swdk{
1521.2Swdk	struct fd_softc *sc = arg;
1531.1Swdk
1541.2Swdk	sc->fd_intrcnt.ev_count++;
1551.2Swdk	fd_reset(sc);
1561.2Swdk	return 0;
1571.1Swdk}
158