xref: /netbsd-src/sys/arch/arm/fdt/a9wdt_fdt.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /* $NetBSD: a9wdt_fdt.c,v 1.4 2021/08/07 16:18:43 thorpej Exp $ */
23f3994cbSskrll 
33f3994cbSskrll /*-
43f3994cbSskrll  * Copyright (c) 2019 The NetBSD Foundation, Inc.
53f3994cbSskrll  * All rights reserved.
63f3994cbSskrll  *
73f3994cbSskrll  * This code is derived from software contributed to The NetBSD Foundation
83f3994cbSskrll  * by Nick Hudson
93f3994cbSskrll  *
103f3994cbSskrll  * Redistribution and use in source and binary forms, with or without
113f3994cbSskrll  * modification, are permitted provided that the following conditions
123f3994cbSskrll  * are met:
133f3994cbSskrll  * 1. Redistributions of source code must retain the above copyright
143f3994cbSskrll  *    notice, this list of conditions and the following disclaimer.
153f3994cbSskrll  * 2. Redistributions in binary form must reproduce the above copyright
163f3994cbSskrll  *    notice, this list of conditions and the following disclaimer in the
173f3994cbSskrll  *    documentation and/or other materials provided with the distribution.
183f3994cbSskrll  *
193f3994cbSskrll  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203f3994cbSskrll  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213f3994cbSskrll  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223f3994cbSskrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233f3994cbSskrll  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243f3994cbSskrll  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253f3994cbSskrll  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263f3994cbSskrll  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273f3994cbSskrll  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283f3994cbSskrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293f3994cbSskrll  * POSSIBILITY OF SUCH DAMAGE.
303f3994cbSskrll  */
313f3994cbSskrll 
323f3994cbSskrll #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: a9wdt_fdt.c,v 1.4 2021/08/07 16:18:43 thorpej Exp $");
343f3994cbSskrll 
353f3994cbSskrll #if 0
363f3994cbSskrll #include <sys/param.h>
373f3994cbSskrll #include <sys/bus.h>
383f3994cbSskrll #include <sys/device.h>
393f3994cbSskrll #include <sys/intr.h>
403f3994cbSskrll #include <sys/systm.h>
413f3994cbSskrll #include <sys/kernel.h>
423f3994cbSskrll #include <sys/kmem.h>
433f3994cbSskrll 
443f3994cbSskrll #include <arm/cortex/a9tmr_intr.h>
453f3994cbSskrll #include <arm/cortex/mpcore_var.h>
463f3994cbSskrll #include <arm/cortex/a9tmr_var.h>
473f3994cbSskrll #endif
483f3994cbSskrll 
493f3994cbSskrll 
503f3994cbSskrll #include <sys/param.h>
513f3994cbSskrll #include <sys/bus.h>
523f3994cbSskrll 
533f3994cbSskrll #include <arm/cortex/mpcore_var.h>
543f3994cbSskrll 
553f3994cbSskrll 
563f3994cbSskrll #include <dev/fdt/fdtvar.h>
573f3994cbSskrll #include <arm/fdt/arm_fdtvar.h>
583f3994cbSskrll 
593f3994cbSskrll static int	a9wdt_fdt_match(device_t, cfdata_t, void *);
603f3994cbSskrll static void	a9wdt_fdt_attach(device_t, device_t, void *);
613f3994cbSskrll 
623f3994cbSskrll struct a9wdt_fdt_softc {
633f3994cbSskrll 	device_t	sc_dev;
643f3994cbSskrll 	struct clk	*sc_clk;
653f3994cbSskrll };
663f3994cbSskrll 
673f3994cbSskrll CFATTACH_DECL_NEW(a9wdt_fdt, sizeof(struct a9wdt_fdt_softc),
683f3994cbSskrll     a9wdt_fdt_match, a9wdt_fdt_attach, NULL, NULL);
693f3994cbSskrll 
706e54367aSthorpej static const struct device_compatible_entry compat_data[] = {
716e54367aSthorpej 	{ .compat = "arm,cortex-a9-twd-wdt" },
726e54367aSthorpej 	{ .compat = "arm,cortex-a5-twd-wdt" },
736e54367aSthorpej 	DEVICE_COMPAT_EOL
746e54367aSthorpej };
756e54367aSthorpej 
763f3994cbSskrll static int
a9wdt_fdt_match(device_t parent,cfdata_t cf,void * aux)773f3994cbSskrll a9wdt_fdt_match(device_t parent, cfdata_t cf, void *aux)
783f3994cbSskrll {
793f3994cbSskrll 	struct fdt_attach_args * const faa = aux;
803f3994cbSskrll 
816e54367aSthorpej 	return of_compatible_match(faa->faa_phandle, compat_data);
823f3994cbSskrll }
833f3994cbSskrll 
843f3994cbSskrll static void
a9wdt_fdt_attach(device_t parent,device_t self,void * aux)853f3994cbSskrll a9wdt_fdt_attach(device_t parent, device_t self, void *aux)
863f3994cbSskrll {
873f3994cbSskrll 	struct a9wdt_fdt_softc * const sc = device_private(self);
883f3994cbSskrll 	struct fdt_attach_args * const faa = aux;
893f3994cbSskrll 	const int phandle = faa->faa_phandle;
903f3994cbSskrll 	bus_space_handle_t bsh;
913f3994cbSskrll 
923f3994cbSskrll 	sc->sc_dev = self;
933f3994cbSskrll 
943f3994cbSskrll 	char intrstr[128];
953f3994cbSskrll 	if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
963f3994cbSskrll 		aprint_error(": failed to decode interrupt\n");
973f3994cbSskrll 		return;
983f3994cbSskrll 	}
993f3994cbSskrll 
1003f3994cbSskrll 	aprint_naive("\n");
1013f3994cbSskrll 	aprint_normal("\n");
1023f3994cbSskrll 
1033f3994cbSskrll 	bus_addr_t addr;
1043f3994cbSskrll 	bus_size_t size;
1053f3994cbSskrll 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
1063f3994cbSskrll 		aprint_error(": couldn't get registers\n");
1073f3994cbSskrll 		return;
1083f3994cbSskrll 	}
1093f3994cbSskrll 	if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) {
1103f3994cbSskrll 		aprint_error(": couldn't map registers\n");
1113f3994cbSskrll 		return;
1123f3994cbSskrll 	}
1133f3994cbSskrll 
1143f3994cbSskrll 	struct mpcore_attach_args mpcaa = {
1153f3994cbSskrll 		.mpcaa_name = "a9wdt",
1163f3994cbSskrll 		.mpcaa_memt = faa->faa_bst,
1173f3994cbSskrll 		.mpcaa_memh = bsh,
1183f3994cbSskrll 		.mpcaa_irq = -1,
1193f3994cbSskrll 	};
1203f3994cbSskrll 
121*c7fb772bSthorpej 	config_found(self, &mpcaa, NULL, CFARGS_NONE);
1223f3994cbSskrll }
1233f3994cbSskrll 
124