1 /* $NetBSD: a9wdt_fdt.c,v 1.1 2019/08/10 17:03:59 skrll Exp $ */ 2 3 /*- 4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nick Hudson 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: a9wdt_fdt.c,v 1.1 2019/08/10 17:03:59 skrll Exp $"); 34 35 #if 0 36 #include <sys/param.h> 37 #include <sys/bus.h> 38 #include <sys/device.h> 39 #include <sys/intr.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/kmem.h> 43 44 #include <arm/cortex/a9tmr_intr.h> 45 #include <arm/cortex/mpcore_var.h> 46 #include <arm/cortex/a9tmr_var.h> 47 #endif 48 49 50 #include <sys/param.h> 51 #include <sys/bus.h> 52 53 #include <arm/cortex/mpcore_var.h> 54 55 56 #include <dev/fdt/fdtvar.h> 57 #include <arm/fdt/arm_fdtvar.h> 58 59 static int a9wdt_fdt_match(device_t, cfdata_t, void *); 60 static void a9wdt_fdt_attach(device_t, device_t, void *); 61 62 struct a9wdt_fdt_softc { 63 device_t sc_dev; 64 struct clk *sc_clk; 65 }; 66 67 CFATTACH_DECL_NEW(a9wdt_fdt, sizeof(struct a9wdt_fdt_softc), 68 a9wdt_fdt_match, a9wdt_fdt_attach, NULL, NULL); 69 70 static int 71 a9wdt_fdt_match(device_t parent, cfdata_t cf, void *aux) 72 { 73 const char * const compatible[] = { 74 "arm,cortex-a9-twd-wdt", 75 "arm,cortex-a5-twd-wdt", 76 NULL 77 }; 78 struct fdt_attach_args * const faa = aux; 79 80 return of_compatible(faa->faa_phandle, compatible) >= 0; 81 } 82 83 static void 84 a9wdt_fdt_attach(device_t parent, device_t self, void *aux) 85 { 86 struct a9wdt_fdt_softc * const sc = device_private(self); 87 struct fdt_attach_args * const faa = aux; 88 const int phandle = faa->faa_phandle; 89 bus_space_handle_t bsh; 90 91 sc->sc_dev = self; 92 93 char intrstr[128]; 94 if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) { 95 aprint_error(": failed to decode interrupt\n"); 96 return; 97 } 98 99 aprint_naive("\n"); 100 aprint_normal("\n"); 101 102 bus_addr_t addr; 103 bus_size_t size; 104 if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 105 aprint_error(": couldn't get registers\n"); 106 return; 107 } 108 if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) { 109 aprint_error(": couldn't map registers\n"); 110 return; 111 } 112 113 struct mpcore_attach_args mpcaa = { 114 .mpcaa_name = "a9wdt", 115 .mpcaa_memt = faa->faa_bst, 116 .mpcaa_memh = bsh, 117 .mpcaa_irq = -1, 118 }; 119 120 config_found(self, &mpcaa, NULL); 121 } 122 123