4 * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/errno.h>
34 #include <sys/ioctl.h>
35 #include <sys/syslog.h>
36 #include <sys/device.h>
41 #include <dev/isa/isavar.h>
42 #include <dev/isa/isadmavar.h>
44 #include <dev/acpi/acpica.h>
45 #include <dev/acpi/acpireg.h>
46 #include <dev/acpi/acpivar.h>
48 #include <dev/sdmmc/sdmmcvar.h>
49 #include <dev/ic/w83l518dvar.h>
50 #include <dev/ic/w83l518dreg.h>
52 static int wb_acpi_match(device_t
, cfdata_t
, void *);
53 static void wb_acpi_attach(device_t
, device_t
, void *);
54 static int wb_acpi_detach(device_t
, int);
56 struct wb_acpi_softc
{
57 struct wb_softc sc_wb
;
58 isa_chipset_tag_t sc_ic
;
63 CFATTACH_DECL_NEW(wb_acpi
, sizeof(struct wb_acpi_softc
),
70 static const char * const wb_acpi_ids
[] = {
72 "WEC0515", /* Memory Stick interface */
74 "WEC0517", /* SD Memory Card interface */
79 wb_acpi_match(device_t parent
, cfdata_t match
, void *opaque
)
81 struct acpi_attach_args
*aa
= opaque
;
83 if (aa
->aa_node
->ad_type
!= ACPI_TYPE_DEVICE
)
86 return acpi_match_hid(aa
->aa_node
->ad_devinfo
, wb_acpi_ids
);
90 wb_acpi_attach(device_t parent
, device_t self
, void *opaque
)
92 struct wb_acpi_softc
*sc
= device_private(self
);
93 struct acpi_attach_args
*aa
= opaque
;
94 struct acpi_resources res
;
97 bus_space_handle_t ioh
;
100 sc
->sc_ic
= aa
->aa_ic
;
102 rv
= acpi_resource_parse(self
, aa
->aa_node
->ad_handle
, "_CRS",
103 &res
, &acpi_resource_parse_ops_default
);
104 if (ACPI_FAILURE(rv
))
107 io
= acpi_res_io(&res
, 0);
108 irq
= acpi_res_irq(&res
, 0);
109 if (io
== NULL
|| irq
== NULL
) {
110 aprint_error_dev(self
, "incomplete resources\n");
114 if (bus_space_map(aa
->aa_iot
, io
->ar_base
, io
->ar_length
, 0, &ioh
)) {
115 aprint_error_dev(self
, "couldn't map registers\n");
118 sc
->sc_ioh_length
= io
->ar_length
;
120 sc
->sc_ih
= isa_intr_establish(sc
->sc_ic
, irq
->ar_irq
,
121 (irq
->ar_type
== ACPI_EDGE_SENSITIVE
) ? IST_EDGE
: IST_LEVEL
,
122 IPL_SDMMC
, wb_intr
, &sc
->sc_wb
);
123 if (sc
->sc_ih
== NULL
) {
124 aprint_error_dev(self
,
125 "couldn't establish interrupt handler\n");
129 sc
->sc_wb
.wb_dev
= self
;
130 sc
->sc_wb
.wb_type
= WB_DEVNO_SD
;
131 sc
->sc_wb
.wb_iot
= aa
->aa_iot
;
132 sc
->sc_wb
.wb_ioh
= ioh
;
133 sc
->sc_wb
.wb_irq
= irq
->ar_irq
;
134 sc
->sc_wb
.wb_base
= io
->ar_base
;
135 wb_attach(&sc
->sc_wb
);
138 acpi_resource_cleanup(&res
);
142 wb_acpi_detach(device_t self
, int flags
)
144 struct wb_acpi_softc
*sc
= device_private(self
);
147 rv
= wb_detach(&sc
->sc_wb
, flags
);
152 isa_intr_disestablish(sc
->sc_ic
, sc
->sc_ih
);
154 if (sc
->sc_ioh_length
> 0)
155 bus_space_unmap(sc
->sc_wb
.wb_iot
, sc
->sc_wb
.wb_ioh
,