imx51_axi.c revision 1.8 1 /* $NetBSD: imx51_axi.c,v 1.8 2021/04/24 23:36:27 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2010 SHIMIZU Ryo <ryo (at) nerv.org>
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.8 2021/04/24 23:36:27 thorpej 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
44 struct axi_softc {
45 device_t sc_dev;
46 bus_space_tag_t sc_iot;
47 bus_dma_tag_t sc_dmat;
48 };
49
50 static int axi_match(device_t, struct cfdata *, void *);
51 static void axi_attach(device_t, device_t, void *);
52 static int axi_search(device_t, struct cfdata *, const int *, void *);
53 static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
54 static int axi_search(device_t, struct cfdata *, const int *, void *);
55 static int axi_print(void *, const char *);
56
57 CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
58 axi_match, axi_attach, NULL, NULL);
59
60 /* ARGSUSED */
61 static int
62 axi_match(device_t parent __unused, struct cfdata *match __unused,
63 void *aux __unused)
64 {
65 return 1;
66 }
67
68 /* ARGSUSED */
69 static void
70 axi_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 CFARG_SEARCH, axi_critical_search,
91 CFARG_EOL);
92 config_search(self, &aa,
93 CFARG_SEARCH, axi_search,
94 CFARG_EOL);
95 }
96
97 /* ARGSUSED */
98 static int
99 axi_critical_search(device_t parent, struct cfdata *cf,
100 const int *ldesc __unused, void *aux)
101 {
102 struct axi_attach_args *aa;
103
104 aa = aux;
105
106 if ((strcmp(cf->cf_name, "tzic") != 0) &&
107 (strcmp(cf->cf_name, "imxuart") != 0) &&
108 (strcmp(cf->cf_name, "imxccm") != 0) &&
109 (strcmp(cf->cf_name, "imxgpio") != 0))
110 return 0;
111
112 aa->aa_name = cf->cf_name;
113 aa->aa_addr = cf->cf_loc[AXICF_ADDR];
114 aa->aa_size = cf->cf_loc[AXICF_SIZE];
115 aa->aa_irq = cf->cf_loc[AXICF_IRQ];
116 aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
117
118 if (config_probe(parent, cf, aux))
119 config_attach(parent, cf, aux, axi_print, CFARG_EOL);
120
121 return 0;
122 }
123
124
125 /* ARGSUSED */
126 static int
127 axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
128 void *aux)
129 {
130 struct axi_attach_args *aa;
131
132 aa = aux;
133
134 aa->aa_addr = cf->cf_loc[AXICF_ADDR];
135 aa->aa_size = cf->cf_loc[AXICF_SIZE];
136 aa->aa_irq = cf->cf_loc[AXICF_IRQ];
137 aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
138
139 if (config_probe(parent, cf, aux))
140 config_attach(parent, cf, aux, axi_print, CFARG_EOL);
141
142 return 0;
143 }
144
145 /* ARGSUSED */
146 static int
147 axi_print(void *aux, const char *name __unused)
148 {
149 struct axi_attach_args *aa = (struct axi_attach_args *)aux;
150
151 if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
152 aprint_normal(" addr 0x%lx", aa->aa_addr);
153 if (aa->aa_size > AXICF_SIZE_DEFAULT)
154 aprint_normal("-0x%lx",
155 aa->aa_addr + aa->aa_size-1);
156 }
157 if (aa->aa_irq != AXICF_IRQ_DEFAULT)
158 aprint_normal(" intr %d", aa->aa_irq);
159 if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
160 aprint_normal(" irqbase %d", aa->aa_irqbase);
161
162 return (UNCONF);
163 }
164