1/*	$NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh Exp $	*/
2
3/*-
4 * Copyright (c) 2010 SHIMIZU Ryo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh Exp $");
31
32#include <sys/param.h>
33#include <sys/bus.h>
34#include <sys/device.h>
35
36#include <uvm/uvm_extern.h>
37
38#include <arm/imx/imx51reg.h>
39#include <arm/imx/imx51var.h>
40
41#include "bus_dma_generic.h"
42#include "locators.h"
43
44struct axi_softc {
45	device_t sc_dev;
46	bus_space_tag_t sc_iot;
47	bus_dma_tag_t sc_dmat;
48};
49
50static int axi_match(device_t, struct cfdata *, void *);
51static void axi_attach(device_t, device_t, void *);
52static int axi_search(device_t, struct cfdata *, const int *, void *);
53static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
54static int axi_search(device_t, struct cfdata *, const int *, void *);
55static int axi_print(void *, const char *);
56
57CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
58    axi_match, axi_attach, NULL, NULL);
59
60/* ARGSUSED */
61static int
62axi_match(device_t parent __unused, struct cfdata *match __unused,
63    void *aux __unused)
64{
65	return 1;
66}
67
68/* ARGSUSED */
69static void
70axi_attach(device_t parent __unused, device_t self, void *aux __unused)
71{
72	struct axi_softc *sc;
73	struct axi_attach_args aa;
74
75	aprint_normal(": Advanced eXtensible Interface\n");
76	aprint_naive("\n");
77
78	sc = device_private(self);
79	sc->sc_iot = &armv7_generic_bs_tag;
80#if NBUS_DMA_GENERIC > 0
81	sc->sc_dmat = &arm_generic_dma_tag;
82#else
83	sc->sc_dmat = 0;
84#endif
85
86	aa.aa_name = "axi";
87	aa.aa_iot = sc->sc_iot;
88	aa.aa_dmat = sc->sc_dmat;
89	config_search(self, &aa,
90	    CFARGS(.search = axi_critical_search));
91	config_search(self, &aa,
92	    CFARGS(.search = axi_search));
93}
94
95/* ARGSUSED */
96static int
97axi_critical_search(device_t parent, struct cfdata *cf,
98    const int *ldesc __unused, void *aux)
99{
100	struct axi_attach_args *aa;
101
102	aa = aux;
103
104	if ((strcmp(cf->cf_name, "tzic") != 0) &&
105	    (strcmp(cf->cf_name, "imxuart") != 0) &&
106	    (strcmp(cf->cf_name, "imxccm") != 0) &&
107	    (strcmp(cf->cf_name, "imxgpio") != 0))
108		return 0;
109
110	aa->aa_name = cf->cf_name;
111	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
112	aa->aa_size = cf->cf_loc[AXICF_SIZE];
113	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
114	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
115
116	if (config_probe(parent, cf, aux))
117		config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
118
119	return 0;
120}
121
122
123/* ARGSUSED */
124static int
125axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
126    void *aux)
127{
128	struct axi_attach_args *aa;
129
130	aa = aux;
131
132	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
133	aa->aa_size = cf->cf_loc[AXICF_SIZE];
134	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
135	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
136
137	if (config_probe(parent, cf, aux))
138		config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
139
140	return 0;
141}
142
143/* ARGSUSED */
144static int
145axi_print(void *aux, const char *name __unused)
146{
147	struct axi_attach_args *aa = (struct axi_attach_args *)aux;
148
149	if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
150		aprint_normal(" addr 0x%lx", aa->aa_addr);
151		if (aa->aa_size > AXICF_SIZE_DEFAULT)
152			aprint_normal("-0x%lx",
153			    aa->aa_addr + aa->aa_size-1);
154	}
155	if (aa->aa_irq != AXICF_IRQ_DEFAULT)
156		aprint_normal(" intr %d", aa->aa_irq);
157	if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
158		aprint_normal(" irqbase %d", aa->aa_irqbase);
159
160	return (UNCONF);
161}
162