xref: /freebsd/sys/dev/fdc/fdc_isa.c (revision fbf96e52bbd90bbbb9c9e2ae6fbc101fa6ebd080)
1 /*
2  * Copyright (c) 2004 M. Warner Losh.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 #include <sys/bio.h>
34 #include <sys/bus.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/rman.h>
38 #include <sys/systm.h>
39 
40 #include <machine/bus.h>
41 
42 #include <dev/fdc/fdcvar.h>
43 #include <dev/fdc/fdcreg.h>
44 
45 #include <isa/isavar.h>
46 #include <isa/isareg.h>
47 
48 static int fdc_isa_probe(device_t);
49 static void fdctl_wr_isa(fdc_p, u_int8_t);
50 
51 static struct isa_pnp_id fdc_ids[] = {
52 	{0x0007d041, "PC standard floppy disk controller"}, /* PNP0700 */
53 	{0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */
54 	{0}
55 };
56 
57 static void
58 fdctl_wr_isa(fdc_p fdc, u_int8_t v)
59 {
60 	bus_space_write_1(fdc->ctlt, fdc->ctlh, 0, v);
61 }
62 
63 static int
64 fdc_isa_probe(device_t dev)
65 {
66 	int	error, ic_type;
67 	struct	fdc_data *fdc;
68 
69 	fdc = device_get_softc(dev);
70 	fdc->fdc_dev = dev;
71 	fdc->fdctl_wr = fdctl_wr_isa;
72 
73 	/* Check pnp ids */
74 	error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids);
75 	if (error == ENXIO)
76 		return ENXIO;
77 	if (error == 0)
78 		fdc->flags = FDC_ISPNP;
79 
80 	/* Attempt to allocate our resources for the duration of the probe */
81 	error = fdc_alloc_resources(fdc);
82 	if (error)
83 		goto out;
84 
85 	/* Check that the controller is working. */
86 	if ((fdc->flags & FDC_ISPNP) == 0) {
87 		error = fdc_initial_reset(fdc);
88 		if (error)
89 			goto out;
90 	}
91 
92 	/* Try to determine a more specific device type. */
93 	if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) {
94 		ic_type = (u_char)ic_type;
95 		switch (ic_type) {
96 		case 0x80:
97 			device_set_desc(dev, "NEC 765 or clone");
98 			fdc->fdct = FDC_NE765;
99 			break;
100 		case 0x81:	/* not mentioned in any hardware doc */
101 		case 0x90:
102 			device_set_desc(dev,
103 		"Enhanced floppy controller (i82077, NE72065 or clone)");
104 			fdc->fdct = FDC_ENHANCED;
105 			break;
106 		default:
107 			device_set_desc(dev, "Generic floppy controller");
108 			fdc->fdct = FDC_UNKNOWN;
109 			break;
110 		}
111 	}
112 
113 out:
114 	fdc_release_resources(fdc);
115 	return (error);
116 }
117 
118 static device_method_t fdc_methods[] = {
119 	/* Device interface */
120 	DEVMETHOD(device_probe,		fdc_isa_probe),
121 	DEVMETHOD(device_attach,	fdc_attach),
122 	DEVMETHOD(device_detach,	fdc_detach),
123 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
124 	DEVMETHOD(device_suspend,	bus_generic_suspend),
125 	DEVMETHOD(device_resume,	bus_generic_resume),
126 
127 	/* Bus interface */
128 	DEVMETHOD(bus_print_child,	fdc_print_child),
129 	DEVMETHOD(bus_read_ivar,	fdc_read_ivar),
130 	DEVMETHOD(bus_write_ivar,       fdc_write_ivar),
131 	/* Our children never use any other bus interface methods. */
132 
133 	{ 0, 0 }
134 };
135 
136 static driver_t fdc_driver = {
137 	"fdc",
138 	fdc_methods,
139 	sizeof(struct fdc_data)
140 };
141 
142 DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);
143 DRIVER_MODULE(fdc, acpi, fdc_driver, fdc_devclass, 0, 0);
144