i82072.c revision 1.14
11.14Sdholland/*	$NetBSD: i82072.c,v 1.14 2014/07/25 08:02:18 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.14Sdholland__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.14 2014/07/25 08:02:18 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.13Sdholland	.d_flag = D_DISK
741.4Sgehenna};
751.3Smatt
761.1Swdk#define	I82072_STATUS	0x000003
771.1Swdk#define	I82072_DATA	0x000007
781.1Swdk#define	I82072_TC	0x800003
791.1Swdk
801.1Swdkstruct	fd_softc {
811.12Schs        device_t dev;
821.1Swdk        struct  evcnt  fd_intrcnt;
831.1Swdk	bus_space_tag_t	fd_bst;
841.1Swdk	bus_space_handle_t fd_bsh;
851.1Swdk        int     unit;
861.1Swdk};
871.1Swdk
881.12Schsstatic int	fd_match (device_t, cfdata_t, void *);
891.12Schsstatic void	fd_attach (device_t, device_t, void *);
901.3Smattstatic void     fd_reset (struct fd_softc *);
911.1Swdk
921.12SchsCFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
931.6Sthorpej    fd_match, fd_attach, NULL, NULL);
941.1Swdk
951.3Smattstatic int	fd_intr (void *);
961.2Swdk
971.1Swdkint
981.12Schsfd_match(device_t parent, cfdata_t cf, void *aux)
991.1Swdk{
1001.1Swdk	return 1;
1011.1Swdk}
1021.1Swdk
1031.1Swdkvoid
1041.12Schsfd_attach(device_t parent, device_t self, void *aux)
1051.1Swdk{
1061.12Schs        struct fd_softc *sc = device_private(self);
1071.1Swdk	struct confargs *ca = aux;
1081.1Swdk
1091.1Swdk	sc->fd_bst = ca->ca_bustag;
1101.1Swdk	if (bus_space_map(ca->ca_bustag, ca->ca_addr,
1111.1Swdk			  0x1000000,
1121.1Swdk			  BUS_SPACE_MAP_LINEAR,
1131.1Swdk			  &sc->fd_bsh) != 0) {
1141.12Schs		printf("%s: cannot map registers\n", device_xname(self));
1151.1Swdk		return;
1161.1Swdk	}
1171.1Swdk	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
1181.12Schs			     device_xname(self), "intr");
1191.1Swdk
1201.2Swdk	bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
1211.2Swdk
1221.1Swdk	fd_reset(sc);
1231.1Swdk	printf(": not fully implemented\n");
1241.1Swdk}
1251.1Swdk
1261.1Swdkvoid
1271.3Smattfd_reset(struct fd_softc *sc)
1281.1Swdk{
1291.1Swdk	/* This clears any pending interrupts from the i82072 FDC */
1301.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
1311.1Swdk	DELAY(1000);
1321.1Swdk	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
1331.1Swdk	DELAY(1000);
1341.1Swdk}
1351.1Swdk
1361.3Smattint
1371.9Schristosfdopen(dev_t dev, int flags, int mode, struct lwp *l)
1381.3Smatt{
1391.3Smatt	return (EBADF);
1401.3Smatt}
1411.1Swdk
1421.1Swdkvoid
1431.3Smattfdstrategy(struct buf *bp)
1441.3Smatt{
1451.3Smatt	panic("fdstrategy");
1461.3Smatt}
1471.1Swdk
1481.2Swdkstatic int
1491.11Sdslfd_intr(void *arg)
1501.1Swdk{
1511.2Swdk	struct fd_softc *sc = arg;
1521.1Swdk
1531.2Swdk	sc->fd_intrcnt.ev_count++;
1541.2Swdk	fd_reset(sc);
1551.2Swdk	return 0;
1561.1Swdk}
157