ata-card.c revision 119418
173897Ssos/*- 2111188Ssos * Copyright (c) 1998 - 2003 S�ren Schmidt <sos@FreeBSD.org> 373897Ssos * All rights reserved. 473897Ssos * 573897Ssos * Redistribution and use in source and binary forms, with or without 673897Ssos * modification, are permitted provided that the following conditions 773897Ssos * are met: 873897Ssos * 1. Redistributions of source code must retain the above copyright 973897Ssos * notice, this list of conditions and the following disclaimer, 1073897Ssos * without modification, immediately at the beginning of the file. 1173897Ssos * 2. Redistributions in binary form must reproduce the above copyright 1273897Ssos * notice, this list of conditions and the following disclaimer in the 1373897Ssos * documentation and/or other materials provided with the distribution. 1473897Ssos * 3. The name of the author may not be used to endorse or promote products 1573897Ssos * derived from this software without specific prior written permission. 1673897Ssos * 1773897Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1873897Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1973897Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2073897Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2173897Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2273897Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2373897Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2473897Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2573897Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2673897Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2773897Ssos */ 2873897Ssos 29119418Sobrien#include <sys/cdefs.h> 30119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/ata/ata-card.c 119418 2003-08-24 17:55:58Z obrien $"); 31119418Sobrien 3273897Ssos#include <sys/param.h> 3373897Ssos#include <sys/systm.h> 34111809Ssos#include <sys/ata.h> 3573897Ssos#include <sys/kernel.h> 3673897Ssos#include <sys/module.h> 3773897Ssos#include <sys/bus.h> 3873897Ssos#include <sys/malloc.h> 39119404Ssos#include <sys/taskqueue.h> 4073897Ssos#include <machine/stdarg.h> 4173897Ssos#include <machine/resource.h> 4273897Ssos#include <machine/bus.h> 4373897Ssos#include <sys/rman.h> 4473897Ssos#include <dev/ata/ata-all.h> 4589915Ssos#include <dev/pccard/pccardreg.h> 4689915Ssos#include <dev/pccard/pccardvar.h> 4789915Ssos#include <dev/pccard/pccarddevs.h> 4873897Ssos 49114090Simpstatic const struct pccard_product ata_pccard_products[] = { 50116485Simp PCMCIA_CARD(FREECOM, PCCARDIDE, 0), 51114090Simp PCMCIA_CARD(EXP, EXPMULTIMEDIA, 0), 52114090Simp PCMCIA_CARD(IODATA, CBIDE2, 0), 53114090Simp PCMCIA_CARD(OEM2, CDROM1, 0), 54115756Simp PCMCIA_CARD(OEM2, IDE, 0), 55114090Simp PCMCIA_CARD(PANASONIC, KXLC005, 0), 56114090Simp PCMCIA_CARD(TEAC, IDECARDII, 0), 57114090Simp {NULL} 58114090Simp}; 59114090Simp 6073897Ssosstatic int 6189915Ssosata_pccard_match(device_t dev) 6289915Ssos{ 63114090Simp const struct pccard_product *pp; 6490215Ssos u_int32_t fcn = PCCARD_FUNCTION_UNSPEC; 6590215Ssos int error = 0; 6689915Ssos 6789915Ssos error = pccard_get_function(dev, &fcn); 6889915Ssos if (error != 0) 6989915Ssos return (error); 7089915Ssos 7189915Ssos /* if it says its a disk we should register it */ 7289915Ssos if (fcn == PCCARD_FUNCTION_DISK) 7389915Ssos return (0); 7489915Ssos 75119404Ssos /* match other devices here, primarily cdrom/dvd rom */ 76114090Simp if ((pp = pccard_product_lookup(dev, ata_pccard_products, 77114090Simp sizeof(ata_pccard_products[0]), NULL)) != NULL) { 78114090Simp if (pp->pp_name) 79114090Simp device_set_desc(dev, pp->pp_name); 80114090Simp return (0); 81114090Simp } 8289915Ssos return(ENXIO); 8389915Ssos} 8489915Ssos 85107660Ssosstatic void 86107660Ssosata_pccard_locknoop(struct ata_channel *ch, int type) 87107660Ssos{ 88107660Ssos} 89107660Ssos 90111809Ssosstatic void 91111809Ssosata_pccard_setmode(struct ata_device *atadev, int mode) 92111809Ssos{ 93111809Ssos atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); 94111809Ssos} 95111809Ssos 96107660Ssosstatic int 9773897Ssosata_pccard_probe(device_t dev) 9873897Ssos{ 9990215Ssos struct ata_channel *ch = device_get_softc(dev); 100112791Ssos struct resource *io, *altio; 101112791Ssos int i, rid, len, start, end; 10273897Ssos u_long tmp; 10373897Ssos 10473897Ssos /* allocate the io range to get start and length */ 10573897Ssos rid = ATA_IOADDR_RID; 10673897Ssos len = bus_get_resource_count(dev, SYS_RES_IOPORT, rid); 10773897Ssos io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 10873897Ssos ATA_IOSIZE, RF_ACTIVE); 10973897Ssos if (!io) 110112791Ssos return ENXIO; 11173897Ssos 11273897Ssos /* reallocate the io address to only cover the io ports */ 11373897Ssos start = rman_get_start(io); 11473897Ssos end = start + ATA_IOSIZE - 1; 11573897Ssos bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 11673897Ssos io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 11773897Ssos start, end, ATA_IOSIZE, RF_ACTIVE); 11873897Ssos 11973897Ssos /* 12073897Ssos * if we got more than the default ATA_IOSIZE ports, this is likely 12173897Ssos * a pccard system where the altio ports are located at offset 14 12273897Ssos * otherwise its the normal altio offset 12373897Ssos */ 12473897Ssos if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) { 12573897Ssos if (len > ATA_IOSIZE) { 12673897Ssos bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 12773897Ssos start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE); 12873897Ssos } 12973897Ssos else { 13073897Ssos bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 13173897Ssos start + ATA_ALTOFFSET, ATA_ALTIOSIZE); 13273897Ssos } 13373897Ssos } 13473897Ssos 135112791Ssos /* allocate the altport range */ 136112791Ssos rid = ATA_ALTADDR_RID; 137112791Ssos altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 138112791Ssos ATA_ALTIOSIZE, RF_ACTIVE); 139112791Ssos if (!altio) { 140112791Ssos bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); 141112791Ssos return ENXIO; 142112791Ssos } 143112791Ssos 144112791Ssos /* setup the resource vectors */ 145112791Ssos for (i = ATA_DATA; i <= ATA_STATUS; i++) { 146112791Ssos ch->r_io[i].res = io; 147112791Ssos ch->r_io[i].offset = i; 148112791Ssos } 149112791Ssos ch->r_io[ATA_ALTSTAT].res = altio; 150112791Ssos ch->r_io[ATA_ALTSTAT].offset = 0; 151112791Ssos 152112791Ssos /* initialize softc for this channel */ 15390215Ssos ch->unit = 0; 15490215Ssos ch->flags |= (ATA_USE_16BIT | ATA_NO_SLAVE); 155111188Ssos ch->locking = ata_pccard_locknoop; 156111809Ssos ch->device[MASTER].setmode = ata_pccard_setmode; 157111809Ssos ch->device[SLAVE].setmode = ata_pccard_setmode; 15873897Ssos return ata_probe(dev); 15973897Ssos} 16073897Ssos 161112791Ssosstatic int 162112791Ssosata_pccard_detach(device_t dev) 163112791Ssos{ 164112791Ssos struct ata_channel *ch = device_get_softc(dev); 165112791Ssos int i; 166112791Ssos 167112791Ssos ata_detach(dev); 168112791Ssos bus_release_resource(dev, SYS_RES_IOPORT, 169112791Ssos ATA_ALTADDR_RID, ch->r_io[ATA_ALTSTAT].res); 170112791Ssos bus_release_resource(dev, SYS_RES_IOPORT, 171112791Ssos ATA_IOADDR_RID, ch->r_io[ATA_DATA].res); 172114947Sphk for (i = ATA_DATA; i < ATA_MAX_RES; i++) 173112791Ssos ch->r_io[i].res = NULL; 174112791Ssos return 0; 175112791Ssos} 176112791Ssos 17773897Ssosstatic device_method_t ata_pccard_methods[] = { 17873897Ssos /* device interface */ 17989915Ssos DEVMETHOD(device_probe, pccard_compat_probe), 18089915Ssos DEVMETHOD(device_attach, pccard_compat_attach), 181112791Ssos DEVMETHOD(device_detach, ata_pccard_detach), 18289915Ssos 18389915Ssos /* Card interface */ 18489915Ssos DEVMETHOD(card_compat_match, ata_pccard_match), 18589915Ssos DEVMETHOD(card_compat_probe, ata_pccard_probe), 18689915Ssos DEVMETHOD(card_compat_attach, ata_attach), 18773897Ssos { 0, 0 } 18873897Ssos}; 18973897Ssos 19073897Ssosstatic driver_t ata_pccard_driver = { 19173897Ssos "ata", 19273897Ssos ata_pccard_methods, 19390215Ssos sizeof(struct ata_channel), 19473897Ssos}; 19573897Ssos 19673897SsosDRIVER_MODULE(ata, pccard, ata_pccard_driver, ata_devclass, 0, 0); 197