1 /*-
2 * Copyright (c) 2004-2005 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 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: releng/11.2/sys/dev/fdc/fdc_pccard.c 331722 2018-03-29 02:50:57Z eadler $");
29
30 #include <sys/param.h>
31 #include <sys/bio.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/lock.h>
35 #include <sys/module.h>
36 #include <sys/mutex.h>
37 #include <sys/rman.h>
38 #include <sys/systm.h>
39 #include <machine/bus.h>
40
41 #include <dev/fdc/fdcvar.h>
42 #include <dev/pccard/pccardvar.h>
43 #include "pccarddevs.h"
44
45 static int fdc_pccard_probe(device_t);
46 static int fdc_pccard_attach(device_t);
47
48 static const struct pccard_product fdc_pccard_products[] = {
49 PCMCIA_CARD(YEDATA, EXTERNAL_FDD),
50 };
51
52 static int
53 fdc_pccard_alloc_resources(device_t dev, struct fdc_data *fdc)
54 {
55 struct resource *res;
56 int rid, i;
57
58 rid = 0;
59 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
60 if (res == NULL) {
61 device_printf(dev, "cannot alloc I/O port range\n");
62 return (ENXIO);
63 }
64 for (i = 0; i < FDC_MAXREG; i++) {
65 fdc->resio[i] = res;
66 fdc->ridio[i] = rid;
67 fdc->ioff[i] = i;
68 fdc->ioh[i] = rman_get_bushandle(res);
69 }
70 fdc->iot = rman_get_bustag(res);
71
72 fdc->rid_irq = 0;
73 fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
74 RF_ACTIVE | RF_SHAREABLE);
75 if (fdc->res_irq == NULL) {
76 device_printf(dev, "cannot reserve interrupt line\n");
77 return (ENXIO);
78 }
79 return (0);
80 }
81
82 static int
83 fdc_pccard_probe(device_t dev)
84 {
85 if (pccard_product_lookup(dev, fdc_pccard_products,
86 sizeof(fdc_pccard_products[0]), NULL) != NULL) {
87 device_set_desc(dev, "PC Card Floppy");
88 return (0);
89 }
90 return (ENXIO);
91 }
92
93 static int
94 fdc_pccard_attach(device_t dev)
95 {
96 int error;
97 struct fdc_data *fdc;
98 device_t child;
99
100 fdc = device_get_softc(dev);
101 fdc->flags = FDC_NODMA | FDC_NOFAST;
102 fdc->fdct = FDC_NE765;
103 error = fdc_pccard_alloc_resources(dev, fdc);
104 if (error == 0)
105 error = fdc_attach(dev);
106 if (error == 0) {
107 child = fdc_add_child(dev, "fd", -1);
108 device_set_flags(child, 0x24);
109 error = bus_generic_attach(dev);
110 }
111 if (error == 0)
112 fdc_start_worker(dev);
113 else
114 fdc_release_resources(fdc);
115 return (error);
116 }
117
118 static device_method_t fdc_pccard_methods[] = {
119 /* Device interface */
120 DEVMETHOD(device_probe, fdc_pccard_probe),
121 DEVMETHOD(device_attach, fdc_pccard_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_pccard_driver = {
137 "fdc",
138 fdc_pccard_methods,
139 sizeof(struct fdc_data)
140 };
141
142 DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
143 PCCARD_PNP_INFO(fdc_pccard_products);
Cache object: 9342dd4124cd6b61cf37ff1e5f6c7b6e
|