i82072.c revision 1.3
1/*	$NetBSD: i82072.c,v 1.3 2000/12/03 04:51:05 matt Exp $	*/
2/*-
3 * Copyright (c) 2000 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Wayne Knowles
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *        This product includes software developed by the NetBSD
20 *        Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 *    contributors may be used to endorse or promote products derived
23 *    from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/mbuf.h>
41#include <sys/syslog.h>
42#include <sys/socket.h>
43#include <sys/device.h>
44#include <sys/conf.h>
45
46#include <machine/cpu.h>
47#include <machine/autoconf.h>
48#include <machine/mainboard.h>
49#include <machine/bus.h>
50
51dev_type_open(fdopen);
52dev_type_close(fdclose);
53dev_type_ioctl(fdioctl);
54dev_type_size(fdsize);
55dev_type_dump(fddump);
56dev_type_strategy(fdstrategy);
57
58
59#define	I82072_STATUS	0x000003
60#define	I82072_DATA	0x000007
61#define	I82072_TC	0x800003
62
63struct	fd_softc {
64        struct  device dev;
65        struct  evcnt  fd_intrcnt;
66	bus_space_tag_t	fd_bst;
67	bus_space_handle_t fd_bsh;
68        int     unit;
69};
70
71static int	fd_match (struct device *, struct cfdata *, void *);
72static void	fd_attach (struct device *, struct device *, void *);
73static void     fd_reset (struct fd_softc *);
74
75struct cfattach fd_ca = {
76	sizeof(struct fd_softc), fd_match, fd_attach
77};
78
79static int	fd_intr (void *);
80
81int
82fd_match(struct device *parent, struct cfdata *cf, void *aux)
83{
84	return 1;
85}
86
87void
88fd_attach(struct device *parent, struct device *self, void *aux)
89{
90        struct fd_softc *sc = (void *)self;
91	struct confargs *ca = aux;
92
93	sc->fd_bst = ca->ca_bustag;
94	if (bus_space_map(ca->ca_bustag, ca->ca_addr,
95			  0x1000000,
96			  BUS_SPACE_MAP_LINEAR,
97			  &sc->fd_bsh) != 0) {
98		printf("%s: cannot map registers\n", self->dv_xname);
99		return;
100	}
101	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
102			     self->dv_xname, "intr");
103
104	bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
105
106	fd_reset(sc);
107	printf(": not fully implemented\n");
108}
109
110void
111fd_reset(struct fd_softc *sc)
112{
113	/* This clears any pending interrupts from the i82072 FDC */
114	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
115	DELAY(1000);
116	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
117	DELAY(1000);
118}
119
120int
121fdopen(dev_t dev, int flags, int mode, struct proc *p)
122{
123	return (EBADF);
124}
125
126int
127fdclose(dev_t dev, int flags, int mode, struct proc *p)
128{
129	return 0;
130}
131
132void
133fdstrategy(struct buf *bp)
134{
135	panic("fdstrategy");
136}
137
138int
139fdioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
140{
141	return (EINVAL);
142}
143
144int
145fddump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
146{
147	return (ENODEV);
148}
149
150int
151fdsize(dev_t dev)
152{
153	return (0);
154}
155
156static int
157fd_intr(arg)
158	void *arg;
159{
160	struct fd_softc *sc = arg;
161
162	sc->fd_intrcnt.ev_count++;
163	fd_reset(sc);
164	return 0;
165}
166