Sun Dec 29 12:46:43 2019 UTC ()
Read clock frequency from device properties


(jmcneill)
diff -r1.8 -r1.9 src/sys/dev/acpi/sdhc_acpi.c

cvs diff -r1.8 -r1.9 src/sys/dev/acpi/sdhc_acpi.c (expand / switch to unified diff)

--- src/sys/dev/acpi/sdhc_acpi.c 2019/10/15 00:13:52 1.8
+++ src/sys/dev/acpi/sdhc_acpi.c 2019/12/29 12:46:43 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sdhc_acpi.c,v 1.8 2019/10/15 00:13:52 chs Exp $ */ 1/* $NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@NetBSD.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@NetBSD.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 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 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. 13 * derived from this software without specific prior written permission.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 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 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE. 25 * SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.8 2019/10/15 00:13:52 chs Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $");
30 30
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/device.h> 32#include <sys/device.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/kmem.h> 34#include <sys/kmem.h>
35 35
36#include <dev/acpi/acpireg.h> 36#include <dev/acpi/acpireg.h>
37#include <dev/acpi/acpivar.h> 37#include <dev/acpi/acpivar.h>
38#include <dev/acpi/acpi_intr.h> 38#include <dev/acpi/acpi_intr.h>
39 39
40#include <dev/sdmmc/sdhcreg.h> 40#include <dev/sdmmc/sdhcreg.h>
41#include <dev/sdmmc/sdhcvar.h> 41#include <dev/sdmmc/sdhcvar.h>
42#include <dev/sdmmc/sdmmcvar.h> 42#include <dev/sdmmc/sdmmcvar.h>
@@ -125,26 +125,27 @@ sdhc_acpi_match(device_t parent, cfdata_ @@ -125,26 +125,27 @@ sdhc_acpi_match(device_t parent, cfdata_
125 return sdhc_acpi_find_slot(aa->aa_node->ad_devinfo) != NULL; 125 return sdhc_acpi_find_slot(aa->aa_node->ad_devinfo) != NULL;
126} 126}
127 127
128static void 128static void
129sdhc_acpi_attach(device_t parent, device_t self, void *opaque) 129sdhc_acpi_attach(device_t parent, device_t self, void *opaque)
130{ 130{
131 struct sdhc_acpi_softc *sc = device_private(self); 131 struct sdhc_acpi_softc *sc = device_private(self);
132 struct acpi_attach_args *aa = opaque; 132 struct acpi_attach_args *aa = opaque;
133 const struct sdhc_acpi_slot *slot; 133 const struct sdhc_acpi_slot *slot;
134 struct acpi_resources res; 134 struct acpi_resources res;
135 struct acpi_mem *mem; 135 struct acpi_mem *mem;
136 struct acpi_irq *irq; 136 struct acpi_irq *irq;
137 ACPI_STATUS rv; 137 ACPI_STATUS rv;
 138 ACPI_INTEGER clock_freq;
138 139
139 sc->sc.sc_dev = self; 140 sc->sc.sc_dev = self;
140 sc->sc.sc_dmat = aa->aa_dmat; 141 sc->sc.sc_dmat = aa->aa_dmat;
141 sc->sc.sc_host = NULL; 142 sc->sc.sc_host = NULL;
142 sc->sc_memt = aa->aa_memt; 143 sc->sc_memt = aa->aa_memt;
143 144
144 slot = sdhc_acpi_find_slot(aa->aa_node->ad_devinfo); 145 slot = sdhc_acpi_find_slot(aa->aa_node->ad_devinfo);
145 if (slot->type == SLOT_TYPE_EMMC) 146 if (slot->type == SLOT_TYPE_EMMC)
146 sc->sc.sc_vendor_hw_reset = sdhc_acpi_intel_emmc_hw_reset; 147 sc->sc.sc_vendor_hw_reset = sdhc_acpi_intel_emmc_hw_reset;
147 148
148 rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", 149 rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
149 &res, &acpi_resource_parse_ops_default); 150 &res, &acpi_resource_parse_ops_default);
150 if (ACPI_FAILURE(rv)) 151 if (ACPI_FAILURE(rv))
@@ -183,26 +184,32 @@ sdhc_acpi_attach(device_t parent, device @@ -183,26 +184,32 @@ sdhc_acpi_attach(device_t parent, device
183 (uint64_t)(uintptr_t)aa->aa_node->ad_handle, 184 (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
184 IPL_BIO, false, sdhc_intr, &sc->sc, device_xname(self)); 185 IPL_BIO, false, sdhc_intr, &sc->sc, device_xname(self));
185 if (sc->sc_ih == NULL) { 186 if (sc->sc_ih == NULL) {
186 aprint_error_dev(self, 187 aprint_error_dev(self,
187 "couldn't establish interrupt handler\n"); 188 "couldn't establish interrupt handler\n");
188 goto unmap; 189 goto unmap;
189 } 190 }
190 191
191 sc->sc.sc_host = kmem_zalloc(sizeof(struct sdhc_host *), KM_SLEEP); 192 sc->sc.sc_host = kmem_zalloc(sizeof(struct sdhc_host *), KM_SLEEP);
192 193
193 /* Enable DMA transfer */ 194 /* Enable DMA transfer */
194 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA; 195 sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
195 196
 197 /* Read clock frequency from device properties */
 198 rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency",
 199 &clock_freq);
 200 if (ACPI_SUCCESS(rv))
 201 sc->sc.sc_clkbase = clock_freq / 1000;
 202
196 if (sdhc_host_found(&sc->sc, sc->sc_memt, sc->sc_memh, 203 if (sdhc_host_found(&sc->sc, sc->sc_memt, sc->sc_memh,
197 sc->sc_memsize) != 0) { 204 sc->sc_memsize) != 0) {
198 aprint_error_dev(self, "couldn't initialize host\n"); 205 aprint_error_dev(self, "couldn't initialize host\n");
199 goto fail; 206 goto fail;
200 } 207 }
201 208
202 if (!pmf_device_register1(self, sdhc_suspend, sdhc_acpi_resume, 209 if (!pmf_device_register1(self, sdhc_suspend, sdhc_acpi_resume,
203 sdhc_shutdown)) { 210 sdhc_shutdown)) {
204 aprint_error_dev(self, "couldn't establish powerhook\n"); 211 aprint_error_dev(self, "couldn't establish powerhook\n");
205 } 212 }
206 213
207 acpi_resource_cleanup(&res); 214 acpi_resource_cleanup(&res);
208 return; 215 return;