i82072.c revision 1.14
1/*	$NetBSD: i82072.c,v 1.14 2014/07/25 08:02:18 dholland 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 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: i82072.c,v 1.14 2014/07/25 08:02:18 dholland Exp $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/mbuf.h>
37#include <sys/syslog.h>
38#include <sys/socket.h>
39#include <sys/device.h>
40#include <sys/conf.h>
41#include <sys/event.h>
42
43#include <machine/cpu.h>
44#include <machine/autoconf.h>
45#include <machine/mainboard.h>
46#include <machine/bus.h>
47
48dev_type_open(fdopen);
49dev_type_strategy(fdstrategy);
50
51const struct bdevsw fd_bdevsw = {
52	.d_open = fdopen,
53	.d_close = nullclose,
54	.d_strategy = fdstrategy,
55	.d_ioctl = noioctl,
56	.d_dump = nodump,
57	.d_psize = nosize,
58	.d_discard = nodiscard,
59	.d_flag = D_DISK
60};
61
62const struct cdevsw fd_cdevsw = {
63	.d_open = fdopen,
64	.d_close = nullclose,
65	.d_read = noread,
66	.d_write = nowrite,
67	.d_ioctl = noioctl,
68	.d_stop = nostop,
69	.d_tty = notty,
70	.d_poll = nopoll,
71	.d_mmap = nommap,
72	.d_kqfilter = nokqfilter,
73	.d_flag = D_DISK
74};
75
76#define	I82072_STATUS	0x000003
77#define	I82072_DATA	0x000007
78#define	I82072_TC	0x800003
79
80struct	fd_softc {
81        device_t dev;
82        struct  evcnt  fd_intrcnt;
83	bus_space_tag_t	fd_bst;
84	bus_space_handle_t fd_bsh;
85        int     unit;
86};
87
88static int	fd_match (device_t, cfdata_t, void *);
89static void	fd_attach (device_t, device_t, void *);
90static void     fd_reset (struct fd_softc *);
91
92CFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
93    fd_match, fd_attach, NULL, NULL);
94
95static int	fd_intr (void *);
96
97int
98fd_match(device_t parent, cfdata_t cf, void *aux)
99{
100	return 1;
101}
102
103void
104fd_attach(device_t parent, device_t self, void *aux)
105{
106        struct fd_softc *sc = device_private(self);
107	struct confargs *ca = aux;
108
109	sc->fd_bst = ca->ca_bustag;
110	if (bus_space_map(ca->ca_bustag, ca->ca_addr,
111			  0x1000000,
112			  BUS_SPACE_MAP_LINEAR,
113			  &sc->fd_bsh) != 0) {
114		printf("%s: cannot map registers\n", device_xname(self));
115		return;
116	}
117	evcnt_attach_dynamic(&sc->fd_intrcnt, EVCNT_TYPE_INTR, NULL,
118			     device_xname(self), "intr");
119
120	bus_intr_establish(sc->fd_bst, SYS_INTR_FDC, 0, 0, fd_intr, sc);
121
122	fd_reset(sc);
123	printf(": not fully implemented\n");
124}
125
126void
127fd_reset(struct fd_softc *sc)
128{
129	/* This clears any pending interrupts from the i82072 FDC */
130	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_STATUS, 0x80);
131	DELAY(1000);
132	bus_space_write_1(sc->fd_bst, sc->fd_bsh, I82072_TC, 0x01);
133	DELAY(1000);
134}
135
136int
137fdopen(dev_t dev, int flags, int mode, struct lwp *l)
138{
139	return (EBADF);
140}
141
142void
143fdstrategy(struct buf *bp)
144{
145	panic("fdstrategy");
146}
147
148static int
149fd_intr(void *arg)
150{
151	struct fd_softc *sc = arg;
152
153	sc->fd_intrcnt.ev_count++;
154	fd_reset(sc);
155	return 0;
156}
157