]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/fdc/fdc_pccard.c
sysctl(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.git] / sys / dev / fdc / fdc_pccard.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004-2005 M. Warner Losh <imp@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/bio.h>
33 #include <sys/bus.h>
34 #include <sys/kernel.h>
35 #include <sys/lock.h>
36 #include <sys/module.h>
37 #include <sys/mutex.h>
38 #include <sys/rman.h>
39 #include <sys/systm.h>
40 #include <machine/bus.h>
41
42 #include <dev/fdc/fdcvar.h>
43 #include <dev/pccard/pccardvar.h>
44 #include "pccarddevs.h"
45
46 static int fdc_pccard_probe(device_t);
47 static int fdc_pccard_attach(device_t);
48
49 static const struct pccard_product fdc_pccard_products[] = {
50         PCMCIA_CARD(YEDATA, EXTERNAL_FDD),
51         { NULL }
52 };
53         
54 static int
55 fdc_pccard_alloc_resources(device_t dev, struct fdc_data *fdc)
56 {
57         struct resource *res;
58         int rid, i;
59
60         rid = 0;
61         res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
62         if (res == NULL) {
63                 device_printf(dev, "cannot alloc I/O port range\n");
64                 return (ENXIO);
65         }
66         for (i = 0; i < FDC_MAXREG; i++) {
67                 fdc->resio[i] = res;
68                 fdc->ridio[i] = rid;
69                 fdc->ioff[i] = i;
70                 fdc->ioh[i] = rman_get_bushandle(res);
71         }
72         fdc->iot = rman_get_bustag(res);
73
74         fdc->rid_irq = 0;
75         fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
76             RF_ACTIVE | RF_SHAREABLE);
77         if (fdc->res_irq == NULL) {
78                 device_printf(dev, "cannot reserve interrupt line\n");
79                 return (ENXIO);
80         }
81         return (0);
82 }
83
84 static int
85 fdc_pccard_probe(device_t dev)
86 {
87         if (pccard_product_lookup(dev, fdc_pccard_products,
88             sizeof(fdc_pccard_products[0]), NULL) != NULL) {
89                 device_set_desc(dev, "PC Card Floppy");
90                 return (0);
91         }
92         return (ENXIO);
93 }
94
95 static int
96 fdc_pccard_attach(device_t dev)
97 {
98         int error;
99         struct  fdc_data *fdc;
100         device_t child;
101
102         fdc = device_get_softc(dev);
103         fdc->flags = FDC_NODMA | FDC_NOFAST;
104         fdc->fdct = FDC_NE765;
105         error = fdc_pccard_alloc_resources(dev, fdc);
106         if (error == 0)
107                 error = fdc_attach(dev);
108         if (error == 0) {
109                 child = fdc_add_child(dev, "fd", -1);
110                 device_set_flags(child, 0x24);
111                 error = bus_generic_attach(dev);
112         }
113         if (error == 0) {
114                 gone_in_dev(dev, 13, "pccard removed");
115                 fdc_start_worker(dev);
116         } else
117                 fdc_release_resources(fdc);
118         return (error);
119 }
120
121 static device_method_t fdc_pccard_methods[] = {
122         /* Device interface */
123         DEVMETHOD(device_probe,         fdc_pccard_probe),
124         DEVMETHOD(device_attach,        fdc_pccard_attach),
125         DEVMETHOD(device_detach,        fdc_detach),
126         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
127         DEVMETHOD(device_suspend,       bus_generic_suspend),
128         DEVMETHOD(device_resume,        bus_generic_resume),
129
130         /* Bus interface */
131         DEVMETHOD(bus_print_child,      fdc_print_child),
132         DEVMETHOD(bus_read_ivar,        fdc_read_ivar),
133         DEVMETHOD(bus_write_ivar,       fdc_write_ivar),
134         /* Our children never use any other bus interface methods. */
135
136         { 0, 0 }
137 };
138
139 static driver_t fdc_pccard_driver = {
140         "fdc",
141         fdc_pccard_methods,
142         sizeof(struct fdc_data)
143 };
144
145 DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
146 PCCARD_PNP_INFO(fdc_pccard_products);