xref: /freebsd-12.1/sys/dev/fdc/fdc_pccard.c (revision 7d0fc2f4)
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 <dev/fdc/fdcvar.h>
41 #include <dev/fdc/fdcreg.h>
42 
43 static void fdctl_wr_pcmcia(fdc_p, u_int8_t);
44 static int fdc_pccard_probe(device_t);
45 
46 static void
47 fdctl_wr_pcmcia(fdc_p fdc, u_int8_t v)
48 {
49 	bus_space_write_1(fdc->portt, fdc->porth, FDCTL+fdc->port_off, v);
50 }
51 
52 /* XXX this is really an attach routine */
53 static int
54 fdc_pccard_probe(device_t dev)
55 {
56 	int	error;
57 	struct	fdc_data *fdc;
58 
59 	fdc = device_get_softc(dev);
60 	bzero(fdc, sizeof *fdc);
61 	fdc->fdc_dev = dev;
62 	fdc->fdctl_wr = fdctl_wr_pcmcia;
63 
64 	fdc->flags |= FDC_ISPCMCIA | FDC_NODMA;
65 
66 	/* Attempt to allocate our resources for the duration of the probe */
67 	error = fdc_alloc_resources(fdc);
68 	if (error)
69 		goto out;
70 
71 	/* First - lets reset the floppy controller */
72 	fdout_wr(fdc, 0);
73 	DELAY(100);
74 	fdout_wr(fdc, FDO_FRST);
75 
76 	/* see if it can handle a command */
77 	if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
78 		   NE7_SPEC_2(2, 0), 0)) {
79 		error = ENXIO;
80 		goto out;
81 	}
82 
83 	device_set_desc(dev, "Y-E Data PCMCIA floppy");
84 	fdc->fdct = FDC_NE765;
85 
86 out:
87 	fdc_release_resources(fdc);
88 	return (error);
89 }
90 
91 static device_method_t fdc_pccard_methods[] = {
92 	/* Device interface */
93 	DEVMETHOD(device_probe,		fdc_pccard_probe),
94 	DEVMETHOD(device_attach,	fdc_attach),
95 	DEVMETHOD(device_detach,	fdc_detach),
96 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
97 	DEVMETHOD(device_suspend,	bus_generic_suspend),
98 	DEVMETHOD(device_resume,	bus_generic_resume),
99 
100 	/* Bus interface */
101 	DEVMETHOD(bus_print_child,	fdc_print_child),
102 	DEVMETHOD(bus_read_ivar,	fdc_read_ivar),
103 	/* Our children never use any other bus interface methods. */
104 
105 	{ 0, 0 }
106 };
107 
108 static driver_t fdc_pccard_driver = {
109 	"fdc",
110 	fdc_pccard_methods,
111 	sizeof(struct fdc_data)
112 };
113 
114 DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
115