i82072.c revision 1.13
11.13Sdholland/* $NetBSD: i82072.c,v 1.13 2014/03/16 05:20:25 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.13Sdholland__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.13 2014/03/16 05:20:25 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.13Sdholland .d_flag = D_DISK 591.4Sgehenna}; 601.4Sgehenna 611.4Sgehennaconst struct cdevsw fd_cdevsw = { 621.13Sdholland .d_open = fdopen, 631.13Sdholland .d_close = nullclose, 641.13Sdholland .d_read = noread, 651.13Sdholland .d_write = nowrite, 661.13Sdholland .d_ioctl = noioctl, 671.13Sdholland .d_stop = nostop, 681.13Sdholland .d_tty = notty, 691.13Sdholland .d_poll = nopoll, 701.13Sdholland .d_mmap = nommap, 711.13Sdholland .d_kqfilter = nokqfilter, 721.13Sdholland .d_flag = D_DISK 731.4Sgehenna}; 741.3Smatt 751.1Swdk#define I82072_STATUS 0x000003 761.1Swdk#define I82072_DATA 0x000007 771.1Swdk#define I82072_TC 0x800003 781.1Swdk 791.1Swdkstruct fd_softc { 801.12Schs device_t dev; 811.1Swdk struct evcnt fd_intrcnt; 821.1Swdk bus_space_tag_t fd_bst; 831.1Swdk bus_space_handle_t fd_bsh; 841.1Swdk int unit; 851.1Swdk}; 861.1Swdk 871.12Schsstatic int fd_match (device_t, cfdata_t, void *); 881.12Schsstatic void fd_attach (device_t, device_t, void *); 891.3Smattstatic void fd_reset (struct fd_softc *); 901.1Swdk 911.12SchsCFATTACH_DECL_NEW(fd, sizeof(struct fd_softc), 921.6Sthorpej fd_match, fd_attach, NULL, NULL); 931.1Swdk 941.3Smattstatic int fd_intr (void *); 951.2Swdk 961.1Swdkint 971.12Schsfd_match(device_t parent, cfdata_t cf, void *aux) 981.1Swdk{ 991.1Swdk return 1; 1001.1Swdk} 1011.1Swdk 1021.1Swdkvoid 1031.12Schsfd_attach(device_t parent, device_t self, void *aux) 1041.1Swdk{ 1051.12Schs struct fd_softc *sc = device_private(self); 1061.1Swdk struct confargs *ca = aux; 1071.1Swdk 1081.1Swdk sc->fd_bst = ca->ca_bustag; 1091.1Swdk if (bus_space_map(ca->ca_bustag, ca->ca_addr, 1101.1Swdk 0x1000000, 1111.1Swdk BUS_SPACE_MAP_LINEAR, 1121.1Swdk &sc->fd_bsh) != 0) { 1131.12Schs printf("%s: cannot map registers\n", device_xname(self)); 1141.1Swdk return; 1151.1Swdk } 1161.1Swdk evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL, 1171.12Schs device_xname(self), "intr"); 1181.1Swdk 1191.2Swdk bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc); 1201.2Swdk 1211.1Swdk fd_reset(sc); 1221.1Swdk printf(": not fully implemented\n"); 1231.1Swdk} 1241.1Swdk 1251.1Swdkvoid 1261.3Smattfd_reset(struct fd_softc *sc) 1271.1Swdk{ 1281.1Swdk /* This clears any pending interrupts from the i82072 FDC */ 1291.1Swdk bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80); 1301.1Swdk DELAY(1000); 1311.1Swdk bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01); 1321.1Swdk DELAY(1000); 1331.1Swdk} 1341.1Swdk 1351.3Smattint 1361.9Schristosfdopen(dev_t dev, int flags, int mode, struct lwp *l) 1371.3Smatt{ 1381.3Smatt return (EBADF); 1391.3Smatt} 1401.1Swdk 1411.1Swdkvoid 1421.3Smattfdstrategy(struct buf *bp) 1431.3Smatt{ 1441.3Smatt panic("fdstrategy"); 1451.3Smatt} 1461.1Swdk 1471.2Swdkstatic int 1481.11Sdslfd_intr(void *arg) 1491.1Swdk{ 1501.2Swdk struct fd_softc *sc = arg; 1511.1Swdk 1521.2Swdk sc->fd_intrcnt.ev_count++; 1531.2Swdk fd_reset(sc); 1541.2Swdk return 0; 1551.1Swdk} 156