Home | History | Annotate | Line # | Download | only in fdt
      1 /* $NetBSD: a9wdt_fdt.c,v 1.4 2021/08/07 16:18:43 thorpej 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.4 2021/08/07 16:18:43 thorpej 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 const struct device_compatible_entry compat_data[] = {
     71 	{ .compat = "arm,cortex-a9-twd-wdt" },
     72 	{ .compat = "arm,cortex-a5-twd-wdt" },
     73 	DEVICE_COMPAT_EOL
     74 };
     75 
     76 static int
     77 a9wdt_fdt_match(device_t parent, cfdata_t cf, void *aux)
     78 {
     79 	struct fdt_attach_args * const faa = aux;
     80 
     81 	return of_compatible_match(faa->faa_phandle, compat_data);
     82 }
     83 
     84 static void
     85 a9wdt_fdt_attach(device_t parent, device_t self, void *aux)
     86 {
     87 	struct a9wdt_fdt_softc * const sc = device_private(self);
     88 	struct fdt_attach_args * const faa = aux;
     89 	const int phandle = faa->faa_phandle;
     90 	bus_space_handle_t bsh;
     91 
     92 	sc->sc_dev = self;
     93 
     94 	char intrstr[128];
     95 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
     96 		aprint_error(": failed to decode interrupt\n");
     97 		return;
     98 	}
     99 
    100 	aprint_naive("\n");
    101 	aprint_normal("\n");
    102 
    103 	bus_addr_t addr;
    104 	bus_size_t size;
    105 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
    106 		aprint_error(": couldn't get registers\n");
    107 		return;
    108 	}
    109 	if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) {
    110 		aprint_error(": couldn't map registers\n");
    111 		return;
    112 	}
    113 
    114 	struct mpcore_attach_args mpcaa = {
    115 		.mpcaa_name = "a9wdt",
    116 		.mpcaa_memt = faa->faa_bst,
    117 		.mpcaa_memh = bsh,
    118 		.mpcaa_irq = -1,
    119 	};
    120 
    121 	config_found(self, &mpcaa, NULL, CFARGS_NONE);
    122 }
    123 
    124