Home | History | Annotate | Line # | Download | only in acpi
wb_acpi.c revision 1.2.2.2
      1  1.2.2.2  yamt /* $NetBSD: wb_acpi.c,v 1.2.2.2 2010/03/11 15:03:23 yamt Exp $ */
      2  1.2.2.2  yamt 
      3  1.2.2.2  yamt /*
      4  1.2.2.2  yamt  * Copyright (c) 2009 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.2.2.2  yamt  * All rights reserved.
      6  1.2.2.2  yamt  *
      7  1.2.2.2  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.2.2.2  yamt  * modification, are permitted provided that the following conditions
      9  1.2.2.2  yamt  * are met:
     10  1.2.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.2.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.2.2.2  yamt  * 2. The name of the author may not be used to endorse or promote products
     13  1.2.2.2  yamt  *    derived from this software without specific prior written permission.
     14  1.2.2.2  yamt  *
     15  1.2.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.2.2.2  yamt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.2.2.2  yamt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.2.2.2  yamt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.2.2.2  yamt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     20  1.2.2.2  yamt  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21  1.2.2.2  yamt  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     22  1.2.2.2  yamt  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23  1.2.2.2  yamt  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.2.2.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.2.2.2  yamt  * SUCH DAMAGE.
     26  1.2.2.2  yamt  */
     27  1.2.2.2  yamt 
     28  1.2.2.2  yamt #include <sys/cdefs.h>
     29  1.2.2.2  yamt __KERNEL_RCSID(0, "$NetBSD: wb_acpi.c,v 1.2.2.2 2010/03/11 15:03:23 yamt Exp $");
     30  1.2.2.2  yamt 
     31  1.2.2.2  yamt #include <sys/param.h>
     32  1.2.2.2  yamt #include <sys/device.h>
     33  1.2.2.2  yamt #include <sys/systm.h>
     34  1.2.2.2  yamt 
     35  1.2.2.2  yamt #include <dev/acpi/acpivar.h>
     36  1.2.2.2  yamt 
     37  1.2.2.2  yamt #include <dev/ic/w83l518dvar.h>
     38  1.2.2.2  yamt #include <dev/ic/w83l518dreg.h>
     39  1.2.2.2  yamt 
     40  1.2.2.2  yamt #include <dev/isa/isadmavar.h>
     41  1.2.2.2  yamt 
     42  1.2.2.2  yamt #include <dev/sdmmc/sdmmcvar.h>
     43  1.2.2.2  yamt 
     44  1.2.2.2  yamt static int	wb_acpi_match(device_t, cfdata_t, void *);
     45  1.2.2.2  yamt static void	wb_acpi_attach(device_t, device_t, void *);
     46  1.2.2.2  yamt static int	wb_acpi_detach(device_t, int);
     47  1.2.2.2  yamt 
     48  1.2.2.2  yamt struct wb_acpi_softc {
     49  1.2.2.2  yamt 	struct wb_softc sc_wb;
     50  1.2.2.2  yamt 	isa_chipset_tag_t sc_ic;
     51  1.2.2.2  yamt 	void *sc_ih;
     52  1.2.2.2  yamt 	int sc_ioh_length;
     53  1.2.2.2  yamt };
     54  1.2.2.2  yamt 
     55  1.2.2.2  yamt CFATTACH_DECL_NEW(wb_acpi, sizeof(struct wb_acpi_softc),
     56  1.2.2.2  yamt     wb_acpi_match,
     57  1.2.2.2  yamt     wb_acpi_attach,
     58  1.2.2.2  yamt     wb_acpi_detach,
     59  1.2.2.2  yamt     NULL
     60  1.2.2.2  yamt );
     61  1.2.2.2  yamt 
     62  1.2.2.2  yamt static const char * const wb_acpi_ids[] = {
     63  1.2.2.2  yamt #if notyet
     64  1.2.2.2  yamt 	"WEC0515",	/* Memory Stick interface */
     65  1.2.2.2  yamt #endif
     66  1.2.2.2  yamt 	"WEC0517",	/* SD Memory Card interface */
     67  1.2.2.2  yamt 	NULL
     68  1.2.2.2  yamt };
     69  1.2.2.2  yamt 
     70  1.2.2.2  yamt static int
     71  1.2.2.2  yamt wb_acpi_match(device_t parent, cfdata_t match, void *opaque)
     72  1.2.2.2  yamt {
     73  1.2.2.2  yamt 	struct acpi_attach_args *aa = opaque;
     74  1.2.2.2  yamt 
     75  1.2.2.2  yamt 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     76  1.2.2.2  yamt 		return 0;
     77  1.2.2.2  yamt 
     78  1.2.2.2  yamt 	return acpi_match_hid(aa->aa_node->ad_devinfo, wb_acpi_ids);
     79  1.2.2.2  yamt }
     80  1.2.2.2  yamt 
     81  1.2.2.2  yamt static void
     82  1.2.2.2  yamt wb_acpi_attach(device_t parent, device_t self, void *opaque)
     83  1.2.2.2  yamt {
     84  1.2.2.2  yamt 	struct wb_acpi_softc *sc = device_private(self);
     85  1.2.2.2  yamt 	struct acpi_attach_args *aa = opaque;
     86  1.2.2.2  yamt 	struct acpi_resources res;
     87  1.2.2.2  yamt 	struct acpi_io *io;
     88  1.2.2.2  yamt 	struct acpi_irq *irq;
     89  1.2.2.2  yamt 	bus_space_handle_t ioh;
     90  1.2.2.2  yamt 	ACPI_STATUS rv;
     91  1.2.2.2  yamt 
     92  1.2.2.2  yamt 	sc->sc_ic = aa->aa_ic;
     93  1.2.2.2  yamt 
     94  1.2.2.2  yamt 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
     95  1.2.2.2  yamt 	    &res, &acpi_resource_parse_ops_default);
     96  1.2.2.2  yamt 	if (ACPI_FAILURE(rv))
     97  1.2.2.2  yamt 		return;
     98  1.2.2.2  yamt 
     99  1.2.2.2  yamt 	io = acpi_res_io(&res, 0);
    100  1.2.2.2  yamt 	irq = acpi_res_irq(&res, 0);
    101  1.2.2.2  yamt 	if (io == NULL || irq == NULL) {
    102  1.2.2.2  yamt 		aprint_error_dev(self, "incomplete resources\n");
    103  1.2.2.2  yamt 		goto cleanup;
    104  1.2.2.2  yamt 	}
    105  1.2.2.2  yamt 
    106  1.2.2.2  yamt 	if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length, 0, &ioh)) {
    107  1.2.2.2  yamt 		aprint_error_dev(self, "couldn't map registers\n");
    108  1.2.2.2  yamt 		goto cleanup;
    109  1.2.2.2  yamt 	}
    110  1.2.2.2  yamt 	sc->sc_ioh_length = io->ar_length;
    111  1.2.2.2  yamt 
    112  1.2.2.2  yamt 	sc->sc_ih = isa_intr_establish(sc->sc_ic, irq->ar_irq,
    113  1.2.2.2  yamt 	    (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
    114  1.2.2.2  yamt 	    IPL_SDMMC, wb_intr, &sc->sc_wb);
    115  1.2.2.2  yamt 	if (sc->sc_ih == NULL) {
    116  1.2.2.2  yamt 		aprint_error_dev(self,
    117  1.2.2.2  yamt 		    "couldn't establish interrupt handler\n");
    118  1.2.2.2  yamt 		goto cleanup;
    119  1.2.2.2  yamt 	}
    120  1.2.2.2  yamt 
    121  1.2.2.2  yamt 	sc->sc_wb.wb_dev = self;
    122  1.2.2.2  yamt 	sc->sc_wb.wb_type = WB_DEVNO_SD;
    123  1.2.2.2  yamt 	sc->sc_wb.wb_iot = aa->aa_iot;
    124  1.2.2.2  yamt 	sc->sc_wb.wb_ioh = ioh;
    125  1.2.2.2  yamt 	sc->sc_wb.wb_irq = irq->ar_irq;
    126  1.2.2.2  yamt 	sc->sc_wb.wb_base = io->ar_base;
    127  1.2.2.2  yamt 	wb_attach(&sc->sc_wb);
    128  1.2.2.2  yamt 
    129  1.2.2.2  yamt cleanup:
    130  1.2.2.2  yamt 	acpi_resource_cleanup(&res);
    131  1.2.2.2  yamt }
    132  1.2.2.2  yamt 
    133  1.2.2.2  yamt static int
    134  1.2.2.2  yamt wb_acpi_detach(device_t self, int flags)
    135  1.2.2.2  yamt {
    136  1.2.2.2  yamt 	struct wb_acpi_softc *sc = device_private(self);
    137  1.2.2.2  yamt 	int rv;
    138  1.2.2.2  yamt 
    139  1.2.2.2  yamt 	rv = wb_detach(&sc->sc_wb, flags);
    140  1.2.2.2  yamt 	if (rv)
    141  1.2.2.2  yamt 		return rv;
    142  1.2.2.2  yamt 
    143  1.2.2.2  yamt 	if (sc->sc_ih)
    144  1.2.2.2  yamt 		isa_intr_disestablish(sc->sc_ic, sc->sc_ih);
    145  1.2.2.2  yamt 
    146  1.2.2.2  yamt 	if (sc->sc_ioh_length > 0)
    147  1.2.2.2  yamt 		bus_space_unmap(sc->sc_wb.wb_iot, sc->sc_wb.wb_ioh,
    148  1.2.2.2  yamt 		    sc->sc_ioh_length);
    149  1.2.2.2  yamt 
    150  1.2.2.2  yamt 	return 0;
    151  1.2.2.2  yamt }
    152