1 /* $NetBSD: plcom_acpi.c,v 1.3 2020/04/25 21:34:26 jmcneill Exp $ */ 2 3 /*- 4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jared McNeill <jmcneill@invisible.ca>. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: plcom_acpi.c,v 1.3 2020/04/25 21:34:26 jmcneill Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/bus.h> 37 #include <sys/cpu.h> 38 #include <sys/device.h> 39 #include <sys/termios.h> 40 41 #include <dev/acpi/acpireg.h> 42 #include <dev/acpi/acpivar.h> 43 #include <dev/acpi/acpi_intr.h> 44 45 #include <evbarm/dev/plcomreg.h> 46 #include <evbarm/dev/plcomvar.h> 47 48 static int plcom_acpi_match(device_t, cfdata_t, void *); 49 static void plcom_acpi_attach(device_t, device_t, void *); 50 51 CFATTACH_DECL_NEW(plcom_acpi, sizeof(struct plcom_softc), plcom_acpi_match, plcom_acpi_attach, NULL, NULL); 52 53 static const char * const compatible[] = { 54 "ARMH0011", 55 NULL 56 }; 57 58 static int 59 plcom_acpi_match(device_t parent, cfdata_t cf, void *aux) 60 { 61 struct acpi_attach_args *aa = aux; 62 63 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 64 return 0; 65 66 return acpi_match_hid(aa->aa_node->ad_devinfo, compatible); 67 } 68 69 static void 70 plcom_acpi_attach(device_t parent, device_t self, void *aux) 71 { 72 struct plcom_softc * const sc = device_private(self); 73 struct acpi_attach_args *aa = aux; 74 struct acpi_resources res; 75 struct acpi_mem *mem; 76 struct acpi_irq *irq; 77 ACPI_STATUS rv; 78 void *ih; 79 80 sc->sc_dev = self; 81 82 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 83 &res, &acpi_resource_parse_ops_default); 84 if (ACPI_FAILURE(rv)) 85 return; 86 87 mem = acpi_res_mem(&res, 0); 88 if (mem == NULL) { 89 aprint_error(": couldn't find mem resource\n"); 90 goto done; 91 } 92 93 irq = acpi_res_irq(&res, 0); 94 if (irq == NULL) { 95 aprint_error(": couldn't find irq resource\n"); 96 goto done; 97 } 98 99 sc->sc_hwflags = 0; 100 sc->sc_swflags = 0; 101 102 sc->sc_pi.pi_type = PLCOM_TYPE_PL011; 103 sc->sc_pi.pi_flags = PLC_FLAG_32BIT_ACCESS; 104 sc->sc_pi.pi_iot = aa->aa_memt; 105 sc->sc_pi.pi_iobase = mem->ar_base; 106 if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0, &sc->sc_pi.pi_ioh) != 0) { 107 aprint_error(": couldn't map registers\n"); 108 goto done; 109 } 110 111 plcom_attach_subr(sc); 112 113 ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle, 114 IPL_SERIAL, true, plcomintr, sc, device_xname(self)); 115 if (ih == NULL) { 116 aprint_error_dev(self, "couldn't install interrupt handler\n"); 117 return; 118 } 119 120 done: 121 acpi_resource_cleanup(&res); 122 } 123