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