fdc_pccard.c revision 132137
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: head/sys/dev/fdc/fdc_pccard.c 132137 2004-07-14 06:59:58Z imp $");
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#include <machine/bus.h>
40
41#include <machine/bus.h>
42
43#include <dev/fdc/fdcvar.h>
44#include <dev/fdc/fdcreg.h>
45#include <dev/pccard/pccardvar.h>
46#include "pccarddevs.h"
47
48static void fdctl_wr_pcmcia(fdc_p, u_int8_t);
49static int fdc_pccard_probe(device_t);
50static int fdc_pccard_attach(device_t);
51
52static const struct pccard_product fdc_pccard_products[] = {
53	PCMCIA_CARD(YEDATA, EXTERNAL_FDD, 0),
54};
55
56static void
57fdctl_wr_pcmcia(fdc_p fdc, u_int8_t v)
58{
59	bus_space_write_1(fdc->portt, fdc->porth, FDCTL+fdc->port_off, v);
60}
61
62static int
63fdc_pccard_alloc_resources(device_t dev, struct fdc_data *fdc)
64{
65	fdc->rid_ioport = 0;
66	fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
67	    &fdc->rid_ioport, 0ul, ~0ul, 1, RF_ACTIVE);
68	if (fdc->res_ioport == NULL) {
69		device_printf(dev, "cannot alloc I/O port range\n");
70		return (ENXIO);
71	}
72	fdc->portt = rman_get_bustag(fdc->res_ioport);
73	fdc->porth = rman_get_bushandle(fdc->res_ioport);
74
75	fdc->rid_irq = 0;
76	fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
77	    RF_ACTIVE | RF_SHAREABLE);
78	if (fdc->res_irq == NULL) {
79		device_printf(dev, "cannot reserve interrupt line\n");
80		return (ENXIO);
81	}
82	return (0);
83}
84
85static int
86fdc_pccard_probe(device_t dev)
87{
88	const struct pccard_product *pp;
89
90	if ((pp = pccard_product_lookup(dev, fdc_pccard_products,
91	    sizeof(fdc_pccard_products[0]), NULL)) != NULL) {
92		if (pp->pp_name != NULL)
93			device_set_desc(dev, pp->pp_name);
94		return (0);
95	}
96	return (ENXIO);
97}
98
99static int
100fdc_pccard_attach(device_t dev)
101{
102	struct	fdc_data *fdc;
103
104	return ENXIO;
105
106	fdc = device_get_softc(dev);
107	fdc->fdctl_wr = fdctl_wr_pcmcia;
108	fdc->flags = FDC_NODMA;
109	fdc->fdct = FDC_NE765;
110	fdc_pccard_alloc_resources(dev, fdc);
111	return (fdc_attach(dev));
112}
113
114static device_method_t fdc_pccard_methods[] = {
115	/* Device interface */
116	DEVMETHOD(device_probe,		fdc_pccard_probe),
117	DEVMETHOD(device_attach,	fdc_pccard_attach),
118	DEVMETHOD(device_detach,	fdc_detach),
119	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
120	DEVMETHOD(device_suspend,	bus_generic_suspend),
121	DEVMETHOD(device_resume,	bus_generic_resume),
122
123	/* Bus interface */
124	DEVMETHOD(bus_print_child,	fdc_print_child),
125	DEVMETHOD(bus_read_ivar,	fdc_read_ivar),
126	DEVMETHOD(bus_write_ivar,       fdc_write_ivar),
127	/* Our children never use any other bus interface methods. */
128
129	{ 0, 0 }
130};
131
132static driver_t fdc_pccard_driver = {
133	"fdc",
134	fdc_pccard_methods,
135	sizeof(struct fdc_data)
136};
137
138DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
139