2004-07-14 22:09:32 +00:00
|
|
|
/*-
|
2005-01-19 07:46:38 +00:00
|
|
|
* Copyright (c) 2004-2005 M. Warner Losh.
|
2004-07-07 22:35:27 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2005-01-11 06:24:40 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2004-07-07 22:35:27 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2005-01-11 06:24:40 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-07-07 22:35:27 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2005-01-11 06:24:40 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
2004-07-07 22:35:27 +00:00
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-08-20 15:14:25 +00:00
|
|
|
#include <sys/lock.h>
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <sys/module.h>
|
2004-08-20 15:14:25 +00:00
|
|
|
#include <sys/mutex.h>
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/systm.h>
|
2004-07-14 06:59:58 +00:00
|
|
|
#include <machine/bus.h>
|
2004-07-07 22:35:27 +00:00
|
|
|
|
2004-07-13 02:42:23 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
#include <dev/fdc/fdcvar.h>
|
2004-07-14 06:59:58 +00:00
|
|
|
#include <dev/pccard/pccardvar.h>
|
|
|
|
#include "pccarddevs.h"
|
2004-07-07 22:35:27 +00:00
|
|
|
|
|
|
|
static int fdc_pccard_probe(device_t);
|
2004-07-14 06:59:58 +00:00
|
|
|
static int fdc_pccard_attach(device_t);
|
2004-07-07 22:35:27 +00:00
|
|
|
|
2004-07-14 06:59:58 +00:00
|
|
|
static const struct pccard_product fdc_pccard_products[] = {
|
2005-06-24 14:36:54 +00:00
|
|
|
PCMCIA_CARD(YEDATA, EXTERNAL_FDD),
|
2004-07-14 06:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdc_pccard_alloc_resources(device_t dev, struct fdc_data *fdc)
|
|
|
|
{
|
2005-01-19 07:46:38 +00:00
|
|
|
struct resource *res;
|
|
|
|
int rid, i;
|
|
|
|
|
|
|
|
rid = 0;
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (res == NULL) {
|
2004-07-14 06:59:58 +00:00
|
|
|
device_printf(dev, "cannot alloc I/O port range\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2005-01-19 07:46:38 +00:00
|
|
|
for (i = 0; i < FDC_MAXREG; i++) {
|
|
|
|
fdc->resio[i] = res;
|
|
|
|
fdc->ridio[i] = rid;
|
|
|
|
fdc->ioff[i] = i;
|
|
|
|
fdc->ioh[i] = rman_get_bushandle(res);
|
|
|
|
}
|
|
|
|
fdc->iot = rman_get_bustag(res);
|
2004-07-14 06:59:58 +00:00
|
|
|
|
|
|
|
fdc->rid_irq = 0;
|
|
|
|
fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq,
|
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
|
|
|
if (fdc->res_irq == NULL) {
|
|
|
|
device_printf(dev, "cannot reserve interrupt line\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
static int
|
|
|
|
fdc_pccard_probe(device_t dev)
|
|
|
|
{
|
2008-11-23 23:04:28 +00:00
|
|
|
if (pccard_product_lookup(dev, fdc_pccard_products,
|
|
|
|
sizeof(fdc_pccard_products[0]), NULL) != NULL) {
|
2004-09-14 07:06:49 +00:00
|
|
|
device_set_desc(dev, "PC Card Floppy");
|
2004-07-14 06:59:58 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdc_pccard_attach(device_t dev)
|
|
|
|
{
|
2004-07-15 16:41:07 +00:00
|
|
|
int error;
|
2004-07-07 22:35:27 +00:00
|
|
|
struct fdc_data *fdc;
|
2004-09-14 07:06:49 +00:00
|
|
|
device_t child;
|
2004-07-11 16:01:25 +00:00
|
|
|
|
2004-07-07 22:35:27 +00:00
|
|
|
fdc = device_get_softc(dev);
|
2005-01-19 07:46:38 +00:00
|
|
|
fdc->flags = FDC_NODMA | FDC_NOFAST;
|
2004-07-07 22:35:27 +00:00
|
|
|
fdc->fdct = FDC_NE765;
|
2004-07-15 16:41:07 +00:00
|
|
|
error = fdc_pccard_alloc_resources(dev, fdc);
|
2004-08-20 15:14:25 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = fdc_attach(dev);
|
2004-09-14 07:06:49 +00:00
|
|
|
if (error == 0) {
|
|
|
|
child = fdc_add_child(dev, "fd", -1);
|
|
|
|
device_set_flags(child, 0x24);
|
|
|
|
error = bus_generic_attach(dev);
|
|
|
|
}
|
2004-07-15 16:41:07 +00:00
|
|
|
if (error)
|
|
|
|
fdc_release_resources(fdc);
|
|
|
|
return (error);
|
2004-07-07 22:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t fdc_pccard_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, fdc_pccard_probe),
|
2004-07-14 06:59:58 +00:00
|
|
|
DEVMETHOD(device_attach, fdc_pccard_attach),
|
2004-07-07 22:35:27 +00:00
|
|
|
DEVMETHOD(device_detach, fdc_detach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, fdc_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, fdc_read_ivar),
|
2004-07-12 20:49:26 +00:00
|
|
|
DEVMETHOD(bus_write_ivar, fdc_write_ivar),
|
2004-07-07 22:35:27 +00:00
|
|
|
/* Our children never use any other bus interface methods. */
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t fdc_pccard_driver = {
|
|
|
|
"fdc",
|
|
|
|
fdc_pccard_methods,
|
|
|
|
sizeof(struct fdc_data)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(fdc, pccard, fdc_pccard_driver, fdc_devclass, 0, 0);
|