2006-06-20 01:53:57 +04:00
|
|
|
/* $NetBSD: wdc_pcmcia.c,v 1.106 2006/06/19 21:53:57 christos Exp $ */
|
1998-01-19 22:49:03 +03:00
|
|
|
|
1998-08-15 14:10:47 +04:00
|
|
|
/*-
|
2004-08-10 10:10:38 +04:00
|
|
|
* Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
|
1998-08-15 14:10:47 +04:00
|
|
|
* All rights reserved.
|
1998-01-19 22:49:03 +03:00
|
|
|
*
|
1998-08-15 14:10:47 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
|
1998-01-19 22:49:03 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1998-08-15 14:10:47 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1998-01-19 22:49:03 +03:00
|
|
|
*
|
1998-08-15 14:10:47 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL 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.
|
1998-01-19 22:49:03 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 10:24:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-06-20 01:53:57 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wdc_pcmcia.c,v 1.106 2006/06/19 21:53:57 christos Exp $");
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1998-01-19 22:49:03 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
2005-06-19 22:19:19 +04:00
|
|
|
#include <sys/kernel.h>
|
2000-02-05 07:41:49 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
2005-06-19 22:19:19 +04:00
|
|
|
#include <sys/proc.h>
|
1998-01-19 22:49:03 +03:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2000-02-05 07:41:49 +03:00
|
|
|
#include <machine/intr.h>
|
1998-01-19 22:49:03 +03:00
|
|
|
|
1998-10-29 12:49:51 +03:00
|
|
|
#include <dev/pcmcia/pcmciareg.h>
|
1998-01-19 22:49:03 +03:00
|
|
|
#include <dev/pcmcia/pcmciavar.h>
|
1998-09-10 23:55:30 +04:00
|
|
|
#include <dev/pcmcia/pcmciadevs.h>
|
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
#include <dev/ic/wdcreg.h>
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <dev/ata/atavar.h>
|
1998-01-19 22:49:03 +03:00
|
|
|
#include <dev/ic/wdcvar.h>
|
|
|
|
|
2005-03-11 19:17:57 +03:00
|
|
|
#ifndef __BUS_SPACE_HAS_STREAM_METHODS
|
|
|
|
#define bus_space_write_multi_stream_2 bus_space_write_multi_2
|
|
|
|
#define bus_space_write_multi_stream_4 bus_space_write_multi_4
|
|
|
|
#define bus_space_read_multi_stream_2 bus_space_read_multi_2
|
|
|
|
#define bus_space_read_multi_stream_4 bus_space_read_multi_4
|
|
|
|
#endif /* __BUS_SPACE_HAS_STREAM_METHODS */
|
|
|
|
|
1998-01-19 22:49:03 +03:00
|
|
|
#define WDC_PCMCIA_REG_NPORTS 8
|
1998-09-10 23:55:30 +04:00
|
|
|
#define WDC_PCMCIA_AUXREG_OFFSET (WDC_PCMCIA_REG_NPORTS + 6)
|
1998-01-23 04:14:13 +03:00
|
|
|
#define WDC_PCMCIA_AUXREG_NPORTS 2
|
1998-01-19 22:49:03 +03:00
|
|
|
|
|
|
|
struct wdc_pcmcia_softc {
|
|
|
|
struct wdc_softc sc_wdcdev;
|
2004-08-14 19:08:04 +04:00
|
|
|
struct ata_channel *wdc_chanlist[1];
|
|
|
|
struct ata_channel ata_channel;
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_queue wdc_chqueue;
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs wdc_regs;
|
2004-08-10 07:54:26 +04:00
|
|
|
|
1998-11-20 04:52:22 +03:00
|
|
|
struct pcmcia_function *sc_pf;
|
2004-08-11 03:34:32 +04:00
|
|
|
void *sc_ih;
|
|
|
|
|
2004-08-10 07:54:26 +04:00
|
|
|
int sc_state;
|
|
|
|
#define WDC_PCMCIA_ATTACHED 3
|
1998-01-19 22:49:03 +03:00
|
|
|
};
|
|
|
|
|
2004-10-03 13:36:49 +04:00
|
|
|
#ifndef __BUS_SPACE_HAS_STREAM_METHODS
|
|
|
|
#define bus_space_read_region_stream_2 bus_space_read_region_2
|
|
|
|
#define bus_space_read_region_stream_4 bus_space_read_region_4
|
|
|
|
#define bus_space_write_region_stream_2 bus_space_write_region_2
|
|
|
|
#define bus_space_write_region_stream_4 bus_space_write_region_4
|
|
|
|
#endif /* __BUS_SPACE_HAS_STREAM_METHODS */
|
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static int wdc_pcmcia_match(struct device *, struct cfdata *, void *);
|
|
|
|
static int wdc_pcmcia_validate_config_io(struct pcmcia_config_entry *);
|
|
|
|
static int wdc_pcmcia_validate_config_memory(struct pcmcia_config_entry *);
|
|
|
|
static void wdc_pcmcia_attach(struct device *, struct device *, void *);
|
|
|
|
static int wdc_pcmcia_detach(struct device *, int);
|
1998-01-19 22:49:03 +03:00
|
|
|
|
2002-10-01 01:57:46 +04:00
|
|
|
CFATTACH_DECL(wdc_pcmcia, sizeof(struct wdc_pcmcia_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
wdc_pcmcia_match, wdc_pcmcia_attach, wdc_pcmcia_detach, wdcactivate);
|
1998-01-19 22:49:03 +03:00
|
|
|
|
2006-01-16 23:30:18 +03:00
|
|
|
static const struct wdc_pcmcia_product {
|
|
|
|
struct pcmcia_product wdc_product;
|
|
|
|
int wdc_ndrive;
|
|
|
|
} wdc_pcmcia_products[] = {
|
|
|
|
{ { PCMCIA_VENDOR_DIGITAL,
|
1998-09-10 23:55:30 +04:00
|
|
|
PCMCIA_PRODUCT_DIGITAL_MOBILE_MEDIA_CDROM,
|
2006-01-16 23:30:18 +03:00
|
|
|
{NULL, "Digital Mobile Media CD-ROM", NULL, NULL} }, 2 },
|
1998-09-10 23:55:30 +04:00
|
|
|
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_IBM,
|
1999-11-27 04:03:33 +03:00
|
|
|
PCMCIA_PRODUCT_IBM_PORTABLE_CDROM,
|
2006-01-16 23:30:18 +03:00
|
|
|
{NULL, "PCMCIA Portable CD-ROM Drive", NULL, NULL} }, 2 },
|
1999-02-20 00:49:43 +03:00
|
|
|
|
1998-09-10 23:55:30 +04:00
|
|
|
/* The TEAC IDE/Card II is used on the Sony Vaio */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_TEAC,
|
1998-09-10 23:55:30 +04:00
|
|
|
PCMCIA_PRODUCT_TEAC_IDECARDII,
|
2006-01-16 23:30:18 +03:00
|
|
|
PCMCIA_CIS_TEAC_IDECARDII }, 2 },
|
1998-09-10 23:55:30 +04:00
|
|
|
|
2001-10-14 23:21:45 +04:00
|
|
|
/*
|
2005-02-27 03:26:58 +03:00
|
|
|
* A fujitsu rebranded panasonic drive that reports
|
2001-10-14 23:21:45 +04:00
|
|
|
* itself as function "scsi", disk interface 0
|
|
|
|
*/
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_PANASONIC,
|
2001-10-14 23:21:45 +04:00
|
|
|
PCMCIA_PRODUCT_PANASONIC_KXLC005,
|
2006-01-16 23:30:18 +03:00
|
|
|
PCMCIA_CIS_PANASONIC_KXLC005 }, 2 },
|
2001-10-14 23:21:45 +04:00
|
|
|
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_SANDISK,
|
Add SanDisk pcmcia memory card adapter. Works like an IDE drive.
XXX: Linux driver has a hack not to probe the slave drive. We just
create a phantom drive:
wdc0 at pcmcia0 function 0: < , Memory Card Adapter II, V1.00>
wdc0: i/o mapped mode
atabus2 at wdc0 channel 0
wd1 at atabus2 drive 0: <Memory Card Adapter II>
wd1: drive supports 1-sector PIO transfers, LBA addressing
wd1: 241 MB, 965 cyl, 16 head, 32 sec, 512 bytes/sect x 494080 sectors
wd2 at atabus2 drive 1: <>
wd2: drive supports 1-sector PIO transfers, chs addressing
wd2: 0, 0 cyl, 0 head, 0 sec, 512 bytes/sect x 0 sectors
wd2: 32-bit data port
wd2: disk label read failed
wd2: disk label read failed
2006-01-11 16:34:33 +03:00
|
|
|
PCMCIA_PRODUCT_SANDISK_SDCFB,
|
2006-01-16 23:30:18 +03:00
|
|
|
PCMCIA_CIS_SANDISK_SDCFB }, 1 },
|
Add SanDisk pcmcia memory card adapter. Works like an IDE drive.
XXX: Linux driver has a hack not to probe the slave drive. We just
create a phantom drive:
wdc0 at pcmcia0 function 0: < , Memory Card Adapter II, V1.00>
wdc0: i/o mapped mode
atabus2 at wdc0 channel 0
wd1 at atabus2 drive 0: <Memory Card Adapter II>
wd1: drive supports 1-sector PIO transfers, LBA addressing
wd1: 241 MB, 965 cyl, 16 head, 32 sec, 512 bytes/sect x 494080 sectors
wd2 at atabus2 drive 1: <>
wd2: drive supports 1-sector PIO transfers, chs addressing
wd2: 0, 0 cyl, 0 head, 0 sec, 512 bytes/sect x 0 sectors
wd2: 32-bit data port
wd2: disk label read failed
wd2: disk label read failed
2006-01-11 16:34:33 +03:00
|
|
|
|
2000-01-25 02:14:23 +03:00
|
|
|
/*
|
|
|
|
* EXP IDE/ATAPI DVD Card use with some DVD players.
|
|
|
|
* Does not have a vendor ID or product ID.
|
|
|
|
*/
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
PCMCIA_CIS_EXP_EXPMULTIMEDIA }, 2 },
|
2000-01-08 10:34:49 +03:00
|
|
|
|
2000-12-18 20:21:11 +03:00
|
|
|
/* Mobile Dock 2, neither vendor ID nor product ID */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
{"SHUTTLE TECHNOLOGY LTD.", "PCCARD-IDE/ATAPI Adapter", NULL, NULL} }, 2 },
|
1999-11-21 13:13:08 +03:00
|
|
|
|
2000-12-18 20:21:11 +03:00
|
|
|
/* Toshiba Portege 3110 CD, neither vendor ID nor product ID */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
{"FREECOM", "PCCARD-IDE", NULL, NULL} }, 2 },
|
2000-07-21 03:20:01 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/* Random CD-ROM, (badged AMACOM), neither vendor ID nor product ID */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
{"PCMCIA", "CD-ROM", NULL, NULL} }, 2 },
|
2000-12-18 20:21:11 +03:00
|
|
|
|
2000-12-20 12:56:34 +03:00
|
|
|
/* IO DATA CBIDE2, with neither vendor ID nor product ID */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
PCMCIA_CIS_IODATA_CBIDE2 }, 2 },
|
2000-12-20 12:56:34 +03:00
|
|
|
|
2003-03-27 15:19:44 +03:00
|
|
|
/* TOSHIBA PA2673U(IODATA_CBIDE2 OEM), */
|
|
|
|
/* with neither vendor ID nor product ID */
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
PCMCIA_CIS_TOSHIBA_CBIDE2 }, 2 },
|
2003-03-27 15:19:44 +03:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
|
|
|
* Novac PCMCIA-IDE Card for HD530P IDE Box,
|
2000-12-27 13:41:00 +03:00
|
|
|
* with neither vendor ID nor product ID
|
|
|
|
*/
|
2006-01-16 23:30:18 +03:00
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
{"PCMCIA", "PnPIDE", NULL, NULL} }, 2 },
|
2006-06-20 01:53:57 +04:00
|
|
|
|
|
|
|
{ { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
|
|
|
|
{"PCMCIA", "IDE CARD", NULL, NULL} }, 2 },
|
|
|
|
|
1998-09-10 23:55:30 +04:00
|
|
|
};
|
2004-08-20 03:30:09 +04:00
|
|
|
static const size_t wdc_pcmcia_nproducts =
|
2004-08-10 22:39:08 +04:00
|
|
|
sizeof(wdc_pcmcia_products) / sizeof(wdc_pcmcia_products[0]);
|
1998-09-10 23:55:30 +04:00
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static int wdc_pcmcia_enable(struct device *, int);
|
|
|
|
static void wdc_pcmcia_datain_memory(struct ata_channel *, int, void *,
|
|
|
|
size_t);
|
|
|
|
static void wdc_pcmcia_dataout_memory(struct ata_channel *, int, void *,
|
|
|
|
size_t);
|
1998-10-29 12:49:51 +03:00
|
|
|
|
1998-01-19 22:49:03 +03:00
|
|
|
static int
|
2004-08-20 03:30:09 +04:00
|
|
|
wdc_pcmcia_match(struct device *parent, struct cfdata *match, void *aux)
|
1998-01-19 22:49:03 +03:00
|
|
|
{
|
|
|
|
struct pcmcia_attach_args *pa = aux;
|
2000-10-25 13:32:11 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if (pa->pf->function == PCMCIA_FUNCTION_DISK &&
|
2004-08-10 22:39:08 +04:00
|
|
|
pa->pf->pf_funce_disk_interface == PCMCIA_TPLFE_DDI_PCCARD_ATA)
|
1998-09-10 23:55:30 +04:00
|
|
|
return (1);
|
2004-08-10 22:39:08 +04:00
|
|
|
if (pcmcia_product_lookup(pa, wdc_pcmcia_products, wdc_pcmcia_nproducts,
|
|
|
|
sizeof(wdc_pcmcia_products[0]), NULL))
|
|
|
|
return (2);
|
1998-09-10 23:55:30 +04:00
|
|
|
return (0);
|
1998-01-19 22:49:03 +03:00
|
|
|
}
|
|
|
|
|
2004-08-10 06:56:42 +04:00
|
|
|
static int
|
2004-08-20 03:30:09 +04:00
|
|
|
wdc_pcmcia_validate_config_io(struct pcmcia_config_entry *cfe)
|
2004-08-10 06:56:42 +04:00
|
|
|
{
|
2004-08-11 23:48:57 +04:00
|
|
|
if (cfe->iftype != PCMCIA_IFTYPE_IO ||
|
|
|
|
cfe->num_iospace < 1 || cfe->num_iospace > 2)
|
2004-08-10 06:56:42 +04:00
|
|
|
return (EINVAL);
|
2004-08-11 23:48:57 +04:00
|
|
|
cfe->num_memspace = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-20 03:30:09 +04:00
|
|
|
wdc_pcmcia_validate_config_memory(struct pcmcia_config_entry *cfe)
|
2004-08-11 23:48:57 +04:00
|
|
|
{
|
|
|
|
if (cfe->iftype != PCMCIA_IFTYPE_MEMORY ||
|
|
|
|
cfe->num_memspace > 1 ||
|
|
|
|
cfe->memspace[0].length < 2048)
|
|
|
|
return (EINVAL);
|
|
|
|
cfe->num_iospace = 0;
|
2004-08-10 06:56:42 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-01-19 22:49:03 +03:00
|
|
|
static void
|
2004-08-20 03:30:09 +04:00
|
|
|
wdc_pcmcia_attach(struct device *parent, struct device *self, void *aux)
|
1998-01-19 22:49:03 +03:00
|
|
|
{
|
|
|
|
struct wdc_pcmcia_softc *sc = (void *)self;
|
|
|
|
struct pcmcia_attach_args *pa = aux;
|
1998-06-05 07:26:52 +04:00
|
|
|
struct pcmcia_config_entry *cfe;
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs *wdr;
|
2006-01-16 23:30:18 +03:00
|
|
|
const struct wdc_pcmcia_product *wdcp;
|
2004-08-10 06:56:42 +04:00
|
|
|
bus_size_t offset;
|
2004-08-10 07:00:29 +04:00
|
|
|
int i;
|
2004-08-10 06:56:42 +04:00
|
|
|
int error;
|
1998-01-19 22:49:03 +03:00
|
|
|
|
1998-11-20 04:52:22 +03:00
|
|
|
sc->sc_pf = pa->pf;
|
|
|
|
|
2004-08-11 23:48:57 +04:00
|
|
|
error = pcmcia_function_configure(pa->pf,
|
|
|
|
wdc_pcmcia_validate_config_io);
|
|
|
|
if (error)
|
|
|
|
/*XXXmem16|common*/
|
|
|
|
error = pcmcia_function_configure(pa->pf,
|
|
|
|
wdc_pcmcia_validate_config_memory);
|
2004-08-10 06:56:42 +04:00
|
|
|
if (error) {
|
|
|
|
aprint_error("%s: configure failed, error=%d\n", self->dv_xname,
|
|
|
|
error);
|
|
|
|
return;
|
1998-01-19 22:49:03 +03:00
|
|
|
}
|
|
|
|
|
2004-08-10 06:56:42 +04:00
|
|
|
cfe = pa->pf->cfe;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
|
2004-08-11 22:06:22 +04:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
|
|
|
|
|
2004-08-11 23:48:57 +04:00
|
|
|
if (cfe->iftype == PCMCIA_IFTYPE_MEMORY) {
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->cmd_iot = cfe->memspace[0].handle.memt;
|
|
|
|
wdr->cmd_baseioh = cfe->memspace[0].handle.memh;
|
2004-08-11 23:48:57 +04:00
|
|
|
offset = cfe->memspace[0].offset;
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->ctl_iot = cfe->memspace[0].handle.memt;
|
2004-08-11 23:48:57 +04:00
|
|
|
if (bus_space_subregion(cfe->memspace[0].handle.memt,
|
|
|
|
cfe->memspace[0].handle.memh,
|
|
|
|
offset + WDC_PCMCIA_AUXREG_OFFSET, WDC_PCMCIA_AUXREG_NPORTS,
|
2004-08-14 19:08:04 +04:00
|
|
|
&wdr->ctl_ioh))
|
2004-08-10 06:56:42 +04:00
|
|
|
goto fail;
|
2001-03-08 18:20:57 +03:00
|
|
|
} else {
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->cmd_iot = cfe->iospace[0].handle.iot;
|
|
|
|
wdr->cmd_baseioh = cfe->iospace[0].handle.ioh;
|
2004-08-11 23:48:57 +04:00
|
|
|
offset = 0;
|
|
|
|
if (cfe->num_iospace == 1) {
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->ctl_iot = cfe->iospace[0].handle.iot;
|
2004-08-11 23:48:57 +04:00
|
|
|
if (bus_space_subregion(cfe->iospace[0].handle.iot,
|
|
|
|
cfe->iospace[0].handle.ioh,
|
|
|
|
WDC_PCMCIA_AUXREG_OFFSET, WDC_PCMCIA_AUXREG_NPORTS,
|
2004-08-14 19:08:04 +04:00
|
|
|
&wdr->ctl_ioh))
|
2004-08-11 23:48:57 +04:00
|
|
|
goto fail;
|
|
|
|
} else {
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->ctl_iot = cfe->iospace[1].handle.iot;
|
|
|
|
wdr->ctl_ioh = cfe->iospace[1].handle.ioh;
|
2004-08-11 23:48:57 +04:00
|
|
|
}
|
1999-12-09 06:22:41 +03:00
|
|
|
}
|
1998-01-19 22:49:03 +03:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
for (i = 0; i < WDC_PCMCIA_REG_NPORTS; i++) {
|
2004-08-14 19:08:04 +04:00
|
|
|
if (bus_space_subregion(wdr->cmd_iot,
|
|
|
|
wdr->cmd_baseioh,
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
offset + i, i == 0 ? 4 : 1,
|
2004-08-14 19:08:04 +04:00
|
|
|
&wdr->cmd_iohs[i]) != 0) {
|
2004-07-07 10:43:22 +04:00
|
|
|
aprint_error("%s: can't subregion I/O space\n",
|
|
|
|
self->dv_xname);
|
2004-09-07 04:24:18 +04:00
|
|
|
goto fail;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
}
|
|
|
|
}
|
2004-08-11 22:06:22 +04:00
|
|
|
|
2004-08-11 23:48:57 +04:00
|
|
|
if (cfe->iftype == PCMCIA_IFTYPE_MEMORY) {
|
|
|
|
aprint_normal("%s: memory mapped mode\n", self->dv_xname);
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->data32iot = cfe->memspace[0].handle.memt;
|
2004-08-11 22:06:22 +04:00
|
|
|
if (bus_space_subregion(cfe->memspace[0].handle.memt,
|
2004-08-11 23:48:57 +04:00
|
|
|
cfe->memspace[0].handle.memh, offset + 1024, 1024,
|
2004-08-14 19:08:04 +04:00
|
|
|
&wdr->data32ioh))
|
2004-08-11 22:06:22 +04:00
|
|
|
goto fail;
|
2004-08-11 23:48:57 +04:00
|
|
|
sc->sc_wdcdev.datain_pio = wdc_pcmcia_datain_memory;
|
|
|
|
sc->sc_wdcdev.dataout_pio = wdc_pcmcia_dataout_memory;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
|
2004-08-11 22:06:22 +04:00
|
|
|
} else {
|
2004-08-11 23:48:57 +04:00
|
|
|
aprint_normal("%s: i/o mapped mode\n", self->dv_xname);
|
2004-08-14 19:08:04 +04:00
|
|
|
wdr->data32iot = wdr->cmd_iot;
|
|
|
|
wdr->data32ioh = wdr->cmd_iohs[wd_data];
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA32;
|
2004-08-11 22:06:22 +04:00
|
|
|
}
|
|
|
|
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->wdc_chanlist[0] = &sc->ata_channel;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
|
|
|
|
sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->ata_channel.ch_channel = 0;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
|
2004-08-14 19:08:04 +04:00
|
|
|
sc->ata_channel.ch_queue = &sc->wdc_chqueue;
|
2006-01-16 23:30:18 +03:00
|
|
|
wdcp = pcmcia_product_lookup(pa, wdc_pcmcia_products,
|
|
|
|
wdc_pcmcia_nproducts, sizeof(wdc_pcmcia_products[0]), NULL);
|
2006-01-22 03:08:38 +03:00
|
|
|
sc->ata_channel.ch_ndrive = wdcp ? wdcp->wdc_ndrive : 2;
|
2004-08-16 18:47:31 +04:00
|
|
|
wdc_init_shadow_regs(&sc->ata_channel);
|
1998-11-20 04:52:22 +03:00
|
|
|
|
2004-08-13 16:42:11 +04:00
|
|
|
error = wdc_pcmcia_enable(self, 1);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
|
1998-11-20 04:52:22 +03:00
|
|
|
/* We can enable and disable the controller. */
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_atapi_adapter._generic.adapt_enable =
|
2000-04-01 21:52:14 +04:00
|
|
|
wdc_pcmcia_enable;
|
2004-08-20 10:39:37 +04:00
|
|
|
sc->sc_wdcdev.sc_atac.atac_atapi_adapter._generic.adapt_refcnt = 1;
|
1998-11-20 04:52:22 +03:00
|
|
|
|
2005-06-19 22:19:19 +04:00
|
|
|
/*
|
|
|
|
* Some devices needs some more delay after power up to stabilize
|
|
|
|
* and probe properly, so give them half a second.
|
|
|
|
* See PR 25659 for details.
|
|
|
|
*/
|
2006-03-26 19:34:19 +04:00
|
|
|
config_pending_incr();
|
2005-06-19 22:19:19 +04:00
|
|
|
tsleep(wdc_pcmcia_attach, PWAIT, "wdcattach", hz / 2);
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
wdcattach(&sc->ata_channel);
|
2006-03-26 19:34:19 +04:00
|
|
|
config_pending_decr();
|
2004-08-14 19:08:04 +04:00
|
|
|
ata_delref(&sc->ata_channel);
|
2004-08-10 07:54:26 +04:00
|
|
|
sc->sc_state = WDC_PCMCIA_ATTACHED;
|
2000-02-04 12:31:07 +03:00
|
|
|
return;
|
|
|
|
|
2004-08-10 06:56:42 +04:00
|
|
|
fail:
|
|
|
|
pcmcia_function_unconfigure(pa->pf);
|
1998-01-19 22:49:03 +03:00
|
|
|
}
|
1998-11-20 04:52:22 +03:00
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static int
|
|
|
|
wdc_pcmcia_detach(struct device *self, int flags)
|
1999-09-23 15:04:29 +04:00
|
|
|
{
|
|
|
|
struct wdc_pcmcia_softc *sc = (struct wdc_pcmcia_softc *)self;
|
|
|
|
int error;
|
|
|
|
|
2004-08-10 07:54:26 +04:00
|
|
|
if (sc->sc_state != WDC_PCMCIA_ATTACHED)
|
2000-02-04 12:31:07 +03:00
|
|
|
return (0);
|
|
|
|
|
1999-09-23 15:04:29 +04:00
|
|
|
if ((error = wdcdetach(self, flags)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
2004-08-10 06:56:42 +04:00
|
|
|
pcmcia_function_unconfigure(sc->sc_pf);
|
1999-09-23 15:04:29 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static int
|
|
|
|
wdc_pcmcia_enable(struct device *self, int onoff)
|
1998-11-20 04:52:22 +03:00
|
|
|
{
|
2001-04-25 21:53:04 +04:00
|
|
|
struct wdc_pcmcia_softc *sc = (void *)self;
|
2004-08-10 19:29:56 +04:00
|
|
|
int error;
|
1998-11-20 04:52:22 +03:00
|
|
|
|
|
|
|
if (onoff) {
|
2004-08-11 02:49:12 +04:00
|
|
|
/* Establish the interrupt handler. */
|
|
|
|
sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_BIO,
|
2004-08-14 19:08:04 +04:00
|
|
|
wdcintr, &sc->ata_channel);
|
2004-08-11 02:49:12 +04:00
|
|
|
if (!sc->sc_ih)
|
|
|
|
return (EIO);
|
|
|
|
|
|
|
|
error = pcmcia_function_enable(sc->sc_pf);
|
|
|
|
if (error) {
|
|
|
|
pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
|
|
|
|
sc->sc_ih = 0;
|
|
|
|
return (error);
|
1998-11-20 04:52:22 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pcmcia_function_disable(sc->sc_pf);
|
2003-09-20 01:35:56 +04:00
|
|
|
pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
|
2004-08-10 06:56:42 +04:00
|
|
|
sc->sc_ih = 0;
|
1998-11-20 04:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2004-08-11 22:41:46 +04:00
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static void
|
|
|
|
wdc_pcmcia_datain_memory(struct ata_channel *chp, int flags, void *buf,
|
|
|
|
size_t len)
|
2004-08-11 22:41:46 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
|
2004-08-11 22:41:46 +04:00
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
n = min(len, 1024);
|
2004-08-12 00:27:42 +04:00
|
|
|
if ((flags & DRIVE_CAP32) && (n & 3) == 0)
|
2004-08-14 19:08:04 +04:00
|
|
|
bus_space_read_region_stream_4(wdr->data32iot,
|
|
|
|
wdr->data32ioh, 0, buf, n >> 2);
|
2004-08-12 00:27:42 +04:00
|
|
|
else
|
2004-08-14 19:08:04 +04:00
|
|
|
bus_space_read_region_stream_2(wdr->data32iot,
|
|
|
|
wdr->data32ioh, 0, buf, n >> 1);
|
2004-08-11 22:41:46 +04:00
|
|
|
buf = (char *)buf + n;
|
|
|
|
len -= n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-20 03:30:09 +04:00
|
|
|
static void
|
|
|
|
wdc_pcmcia_dataout_memory(struct ata_channel *chp, int flags, void *buf,
|
|
|
|
size_t len)
|
2004-08-11 22:41:46 +04:00
|
|
|
{
|
2004-08-20 03:25:35 +04:00
|
|
|
struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
|
2004-08-11 22:41:46 +04:00
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
n = min(len, 1024);
|
2004-08-12 00:27:42 +04:00
|
|
|
if ((flags & DRIVE_CAP32) && (n & 3) == 0)
|
2004-08-14 19:08:04 +04:00
|
|
|
bus_space_write_region_stream_4(wdr->data32iot,
|
|
|
|
wdr->data32ioh, 0, buf, n >> 2);
|
2004-08-12 00:27:42 +04:00
|
|
|
else
|
2004-08-14 19:08:04 +04:00
|
|
|
bus_space_write_region_stream_2(wdr->data32iot,
|
|
|
|
wdr->data32ioh, 0, buf, n >> 1);
|
2004-08-11 22:41:46 +04:00
|
|
|
buf = (char *)buf + n;
|
|
|
|
len -= n;
|
|
|
|
}
|
|
|
|
}
|