1262600Simp/*-
2262600Simp * Copyright (c) 2014 Warner Losh.  All rights reserved.
3262600Simp *
4262600Simp * Redistribution and use in source and binary forms, with or without
5262600Simp * modification, are permitted provided that the following conditions
6262600Simp * are met:
7262600Simp * 1. Redistributions of source code must retain the above copyright
8262600Simp *    notice, this list of conditions and the following disclaimer.
9262600Simp * 2. Redistributions in binary form must reproduce the above copyright
10262600Simp *    notice, this list of conditions and the following disclaimer in the
11262600Simp *    documentation and/or other materials provided with the distribution.
12262600Simp *
13262600Simp * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14262600Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15262600Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16262600Simp * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17262600Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18262600Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19262600Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20262600Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21262600Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22262600Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23262600Simp * SUCH DAMAGE.
24262600Simp */
25262600Simp
26262600Simp#include "opt_platform.h"
27262600Simp
28262600Simp#include <sys/cdefs.h>
29262600Simp__FBSDID("$FreeBSD$");
30262600Simp
31262600Simp#include <sys/param.h>
32262600Simp#include <sys/bus.h>
33262600Simp#include <sys/kernel.h>
34262600Simp#include <sys/module.h>
35262600Simp#include <sys/resource.h>
36262600Simp#include <sys/systm.h>
37262600Simp#include <sys/rman.h>
38262600Simp
39262600Simp#include <machine/bus.h>
40262600Simp
41262600Simp#include <arm/at91/at91var.h>
42262600Simp#include <arm/at91/at91_aicreg.h>
43262600Simp
44262600Simp#ifdef FDT
45262600Simp#include <dev/fdt/fdt_common.h>
46262600Simp#include <dev/ofw/ofw_bus.h>
47262600Simp#include <dev/ofw/ofw_bus_subr.h>
48262600Simp#endif
49262600Simp
50262600Simpstruct tcb_softc {
51262600Simp	struct resource	*mem_res;	/* Memory resource */
52262600Simp	device_t	sc_dev;
53262600Simp};
54262600Simp
55262600Simpstatic int
56262600Simpat91_tcb_probe(device_t dev)
57262600Simp{
58262600Simp#ifdef FDT
59262600Simp	if (!ofw_bus_is_compatible(dev, "atmel,at91rm9200-tcb"))
60262600Simp		return (ENXIO);
61262600Simp#endif
62262600Simp	device_set_desc(dev, "TCB");
63262600Simp        return (0);
64262600Simp}
65262600Simp
66262600Simpstatic int
67262600Simpat91_tcb_attach(device_t dev)
68262600Simp{
69262600Simp	int rid, err = 0;
70262600Simp	struct tcb_softc *sc;
71262600Simp
72262600Simp	sc = device_get_softc(dev);
73262600Simp	sc->sc_dev = dev;
74262600Simp
75262600Simp	rid = 0;
76262600Simp	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
77262600Simp	    RF_ACTIVE);
78262600Simp
79262600Simp	if (sc->mem_res == NULL)
80262600Simp		panic("couldn't allocate register resources");
81262600Simp
82262600Simp	return (err);
83262600Simp}
84262600Simp
85262600Simpstatic device_method_t at91_tcb_methods[] = {
86262600Simp	DEVMETHOD(device_probe, at91_tcb_probe),
87262600Simp	DEVMETHOD(device_attach, at91_tcb_attach),
88262600Simp	DEVMETHOD_END
89262600Simp};
90262600Simp
91262600Simpstatic driver_t at91_tcb_driver = {
92262600Simp	"at91_tcb",
93262600Simp	at91_tcb_methods,
94262600Simp	sizeof(struct tcb_softc),
95262600Simp};
96262600Simp
97262600Simpstatic devclass_t at91_tcb_devclass;
98262600Simp
99262600Simp#ifdef FDT
100262600SimpDRIVER_MODULE(at91_tcb, simplebus, at91_tcb_driver, at91_tcb_devclass, NULL,
101262600Simp    NULL);
102262600Simp#else
103262600SimpDRIVER_MODULE(at91_tcb, atmelarm, at91_tcb_driver, at91_tcb_devclass, NULL,
104262600Simp    NULL);
105262600Simp#endif
106