1/*- 2 * Copyright (c) 1998 - 2003 S�ren Schmidt <sos@FreeBSD.org> 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 the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 *
| 1/*- 2 * Copyright (c) 1998 - 2003 S�ren Schmidt <sos@FreeBSD.org> 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 the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 *
|
53 PCMCIA_CARD(PANASONIC, KXLC005, 0), 54 PCMCIA_CARD(TEAC, IDECARDII, 0), 55 {NULL} 56}; 57 58static int 59ata_pccard_match(device_t dev) 60{ 61 const struct pccard_product *pp; 62 u_int32_t fcn = PCCARD_FUNCTION_UNSPEC; 63 int error = 0; 64 65 error = pccard_get_function(dev, &fcn); 66 if (error != 0) 67 return (error); 68 69 /* if it says its a disk we should register it */ 70 if (fcn == PCCARD_FUNCTION_DISK) 71 return (0); 72 73 /* Match other devices here, primarily cdrom/dvd rom */ 74 if ((pp = pccard_product_lookup(dev, ata_pccard_products, 75 sizeof(ata_pccard_products[0]), NULL)) != NULL) { 76 if (pp->pp_name) 77 device_set_desc(dev, pp->pp_name); 78 return (0); 79 } 80 return(ENXIO); 81} 82 83static void 84ata_pccard_locknoop(struct ata_channel *ch, int type) 85{ 86} 87 88static void 89ata_pccard_setmode(struct ata_device *atadev, int mode) 90{ 91 atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); 92} 93 94static int 95ata_pccard_probe(device_t dev) 96{ 97 struct ata_channel *ch = device_get_softc(dev); 98 struct resource *io, *altio; 99 int i, rid, len, start, end; 100 u_long tmp; 101 102 /* allocate the io range to get start and length */ 103 rid = ATA_IOADDR_RID; 104 len = bus_get_resource_count(dev, SYS_RES_IOPORT, rid); 105 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 106 ATA_IOSIZE, RF_ACTIVE); 107 if (!io) 108 return ENXIO; 109 110 /* reallocate the io address to only cover the io ports */ 111 start = rman_get_start(io); 112 end = start + ATA_IOSIZE - 1; 113 bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 114 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 115 start, end, ATA_IOSIZE, RF_ACTIVE); 116 117 /* 118 * if we got more than the default ATA_IOSIZE ports, this is likely 119 * a pccard system where the altio ports are located at offset 14 120 * otherwise its the normal altio offset 121 */ 122 if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) { 123 if (len > ATA_IOSIZE) { 124 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 125 start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE); 126 } 127 else { 128 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 129 start + ATA_ALTOFFSET, ATA_ALTIOSIZE); 130 } 131 } 132 else { 133 bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 134 return ENXIO; 135 } 136 137 /* allocate the altport range */ 138 rid = ATA_ALTADDR_RID; 139 altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 140 ATA_ALTIOSIZE, RF_ACTIVE); 141 if (!altio) { 142 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); 143 return ENXIO; 144 } 145 146 /* setup the resource vectors */ 147 for (i = ATA_DATA; i <= ATA_STATUS; i++) { 148 ch->r_io[i].res = io; 149 ch->r_io[i].offset = i; 150 } 151 ch->r_io[ATA_ALTSTAT].res = altio; 152 ch->r_io[ATA_ALTSTAT].offset = 0; 153 154 /* initialize softc for this channel */ 155 ch->unit = 0; 156 ch->flags |= (ATA_USE_16BIT | ATA_NO_SLAVE); 157 ch->locking = ata_pccard_locknoop; 158 ch->device[MASTER].setmode = ata_pccard_setmode; 159 ch->device[SLAVE].setmode = ata_pccard_setmode; 160 return ata_probe(dev); 161} 162 163static int 164ata_pccard_detach(device_t dev) 165{ 166 struct ata_channel *ch = device_get_softc(dev); 167 int i; 168 169 ata_detach(dev); 170 bus_release_resource(dev, SYS_RES_IOPORT, 171 ATA_ALTADDR_RID, ch->r_io[ATA_ALTSTAT].res); 172 bus_release_resource(dev, SYS_RES_IOPORT, 173 ATA_IOADDR_RID, ch->r_io[ATA_DATA].res); 174 for (i = ATA_DATA; i < ATA_MAX_RES; i++) 175 ch->r_io[i].res = NULL; 176 return 0; 177} 178 179static device_method_t ata_pccard_methods[] = { 180 /* device interface */ 181 DEVMETHOD(device_probe, pccard_compat_probe), 182 DEVMETHOD(device_attach, pccard_compat_attach), 183 DEVMETHOD(device_detach, ata_pccard_detach), 184 185 /* Card interface */ 186 DEVMETHOD(card_compat_match, ata_pccard_match), 187 DEVMETHOD(card_compat_probe, ata_pccard_probe), 188 DEVMETHOD(card_compat_attach, ata_attach), 189 { 0, 0 } 190}; 191 192static driver_t ata_pccard_driver = { 193 "ata", 194 ata_pccard_methods, 195 sizeof(struct ata_channel), 196}; 197 198DRIVER_MODULE(ata, pccard, ata_pccard_driver, ata_devclass, 0, 0);
| 54 PCMCIA_CARD(PANASONIC, KXLC005, 0), 55 PCMCIA_CARD(TEAC, IDECARDII, 0), 56 {NULL} 57}; 58 59static int 60ata_pccard_match(device_t dev) 61{ 62 const struct pccard_product *pp; 63 u_int32_t fcn = PCCARD_FUNCTION_UNSPEC; 64 int error = 0; 65 66 error = pccard_get_function(dev, &fcn); 67 if (error != 0) 68 return (error); 69 70 /* if it says its a disk we should register it */ 71 if (fcn == PCCARD_FUNCTION_DISK) 72 return (0); 73 74 /* Match other devices here, primarily cdrom/dvd rom */ 75 if ((pp = pccard_product_lookup(dev, ata_pccard_products, 76 sizeof(ata_pccard_products[0]), NULL)) != NULL) { 77 if (pp->pp_name) 78 device_set_desc(dev, pp->pp_name); 79 return (0); 80 } 81 return(ENXIO); 82} 83 84static void 85ata_pccard_locknoop(struct ata_channel *ch, int type) 86{ 87} 88 89static void 90ata_pccard_setmode(struct ata_device *atadev, int mode) 91{ 92 atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); 93} 94 95static int 96ata_pccard_probe(device_t dev) 97{ 98 struct ata_channel *ch = device_get_softc(dev); 99 struct resource *io, *altio; 100 int i, rid, len, start, end; 101 u_long tmp; 102 103 /* allocate the io range to get start and length */ 104 rid = ATA_IOADDR_RID; 105 len = bus_get_resource_count(dev, SYS_RES_IOPORT, rid); 106 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 107 ATA_IOSIZE, RF_ACTIVE); 108 if (!io) 109 return ENXIO; 110 111 /* reallocate the io address to only cover the io ports */ 112 start = rman_get_start(io); 113 end = start + ATA_IOSIZE - 1; 114 bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 115 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 116 start, end, ATA_IOSIZE, RF_ACTIVE); 117 118 /* 119 * if we got more than the default ATA_IOSIZE ports, this is likely 120 * a pccard system where the altio ports are located at offset 14 121 * otherwise its the normal altio offset 122 */ 123 if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) { 124 if (len > ATA_IOSIZE) { 125 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 126 start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE); 127 } 128 else { 129 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, 130 start + ATA_ALTOFFSET, ATA_ALTIOSIZE); 131 } 132 } 133 else { 134 bus_release_resource(dev, SYS_RES_IOPORT, rid, io); 135 return ENXIO; 136 } 137 138 /* allocate the altport range */ 139 rid = ATA_ALTADDR_RID; 140 altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 141 ATA_ALTIOSIZE, RF_ACTIVE); 142 if (!altio) { 143 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); 144 return ENXIO; 145 } 146 147 /* setup the resource vectors */ 148 for (i = ATA_DATA; i <= ATA_STATUS; i++) { 149 ch->r_io[i].res = io; 150 ch->r_io[i].offset = i; 151 } 152 ch->r_io[ATA_ALTSTAT].res = altio; 153 ch->r_io[ATA_ALTSTAT].offset = 0; 154 155 /* initialize softc for this channel */ 156 ch->unit = 0; 157 ch->flags |= (ATA_USE_16BIT | ATA_NO_SLAVE); 158 ch->locking = ata_pccard_locknoop; 159 ch->device[MASTER].setmode = ata_pccard_setmode; 160 ch->device[SLAVE].setmode = ata_pccard_setmode; 161 return ata_probe(dev); 162} 163 164static int 165ata_pccard_detach(device_t dev) 166{ 167 struct ata_channel *ch = device_get_softc(dev); 168 int i; 169 170 ata_detach(dev); 171 bus_release_resource(dev, SYS_RES_IOPORT, 172 ATA_ALTADDR_RID, ch->r_io[ATA_ALTSTAT].res); 173 bus_release_resource(dev, SYS_RES_IOPORT, 174 ATA_IOADDR_RID, ch->r_io[ATA_DATA].res); 175 for (i = ATA_DATA; i < ATA_MAX_RES; i++) 176 ch->r_io[i].res = NULL; 177 return 0; 178} 179 180static device_method_t ata_pccard_methods[] = { 181 /* device interface */ 182 DEVMETHOD(device_probe, pccard_compat_probe), 183 DEVMETHOD(device_attach, pccard_compat_attach), 184 DEVMETHOD(device_detach, ata_pccard_detach), 185 186 /* Card interface */ 187 DEVMETHOD(card_compat_match, ata_pccard_match), 188 DEVMETHOD(card_compat_probe, ata_pccard_probe), 189 DEVMETHOD(card_compat_attach, ata_attach), 190 { 0, 0 } 191}; 192 193static driver_t ata_pccard_driver = { 194 "ata", 195 ata_pccard_methods, 196 sizeof(struct ata_channel), 197}; 198 199DRIVER_MODULE(ata, pccard, ata_pccard_driver, ata_devclass, 0, 0);
|