imx23_apbx.c revision 1.2 1 /* $Id: imx23_apbx.c,v 1.2 2021/04/24 23:36:27 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Petri Laakso.
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/param.h>
33 #include <sys/bus.h>
34 #include <sys/device.h>
35 #include <sys/errno.h>
36
37 #include <arm/mainbus/mainbus.h>
38
39 #include <arm/imx/imx23var.h>
40
41 #include "locators.h"
42
43 static int apbx_match(device_t, cfdata_t, void *);
44 static void apbx_attach(device_t, device_t, void *);
45 static int apbx_detach(device_t, int);
46 static int apbx_activate(device_t, enum devact );
47
48 static int apbx_search_cb(device_t, cfdata_t, const int *, void *);
49 static int apbx_search_crit_cb(device_t, cfdata_t, const int *, void *);
50 static int apbx_print(void *,const char *);
51
52 struct apbx_softc {
53 device_t sc_dev;
54 device_t dmac; /* DMA controller device for this bus. */
55 };
56
57 CFATTACH_DECL3_NEW(apbx,
58 sizeof(struct apbx_softc),
59 apbx_match,
60 apbx_attach,
61 apbx_detach,
62 apbx_activate,
63 NULL,
64 NULL,
65 0);
66
67 static int
68 apbx_match(device_t parent, cfdata_t match, void *aux)
69 {
70 struct mainbus_attach_args *mb = aux;
71
72 if ((mb->mb_iobase == APBX_BASE) && (mb->mb_iosize == APBX_SIZE))
73 return 1;
74
75 return 0;
76 }
77
78 static void
79 apbx_attach(device_t parent, device_t self, void *aux)
80 {
81 struct apb_attach_args aa;
82 static int apbx_attached = 0;
83
84 if (apbx_attached)
85 return;
86
87 aa.aa_iot = &imx23_bus_space;
88 aa.aa_dmat = &imx23_bus_dma_tag;
89
90 aprint_normal("\n");
91
92 config_search(self, &aa,
93 CFARG_SEARCH, apbx_search_crit_cb,
94 CFARG_EOL);
95 config_search(self, &aa,
96 CFARG_SEARCH, apbx_search_cb,
97 CFARG_EOL);
98
99 apbx_attached = 1;
100
101 return;
102 }
103
104 static int
105 apbx_detach(device_t self, int flags)
106 {
107 return 0;
108 }
109
110 static int
111 apbx_activate(device_t self, enum devact act)
112 {
113 return EOPNOTSUPP;
114 }
115
116 /*
117 * config_search_ia() callback function.
118 */
119 static int
120 apbx_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
121 {
122 struct apb_attach_args *aa = aux;
123
124 aa->aa_name = cf->cf_name;
125 aa->aa_addr = cf->cf_loc[APBXCF_ADDR];
126 aa->aa_size = cf->cf_loc[APBXCF_SIZE];
127 aa->aa_irq = cf->cf_loc[APBXCF_IRQ];
128
129 if (config_probe(parent, cf, aux))
130 config_attach(parent, cf, aux, apbx_print, CFARG_EOL);
131
132 return 0;
133 }
134
135 /*
136 * config_search_ia() callback function which only applies to critical devices.
137 */
138 static int
139 apbx_search_crit_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
140 {
141 struct apb_attach_args *aa = aux;
142
143 /* Return if not critical device. */
144 if ((strcmp(cf->cf_name, "timrot") != 0)
145 && (strcmp(cf->cf_name, "apbdma") != 0))
146 return 0;
147
148 aa->aa_name = cf->cf_name;
149 aa->aa_addr = cf->cf_loc[APBXCF_ADDR];
150 aa->aa_size = cf->cf_loc[APBXCF_SIZE];
151 aa->aa_irq = cf->cf_loc[APBXCF_IRQ];
152
153 if (config_probe(parent, cf, aux))
154 config_attach(parent, cf, aux, apbx_print, CFARG_EOL);
155
156 return 0;
157 }
158
159 /*
160 * Called from config_attach()
161 */
162 static int
163 apbx_print(void *aux, const char *name __unused)
164 {
165 struct apb_attach_args *aa = aux;
166
167 if (aa->aa_addr != APBXCF_ADDR_DEFAULT) {
168 aprint_normal(" addr 0x%lx", aa->aa_addr);
169 if (aa->aa_size > APBXCF_SIZE_DEFAULT)
170 aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
171 }
172
173 if (aa->aa_irq != APBXCF_IRQ_DEFAULT)
174 aprint_normal(" irq %d", aa->aa_irq);
175
176 return UNCONF;
177 }
178