imx23_apbh.c revision 1.1 1 /* $Id: imx23_apbh.c,v 1.1 2012/11/20 19:06:12 jkunz 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 apbh_match(device_t, cfdata_t, void *);
44 static void apbh_attach(device_t, device_t, void *);
45 static int apbh_detach(device_t, int);
46 static int apbh_activate(device_t, enum devact);
47
48 static int apbh_search_cb(device_t, cfdata_t, const int *, void *);
49 static int apbh_search_crit_cb(device_t, cfdata_t, const int *, void *);
50 static int apbh_print(void *,const char *);
51
52 struct apbh_softc {
53 device_t sc_dev;
54 device_t dmac; /* DMA controller device for this bus. */
55 };
56
57 CFATTACH_DECL3_NEW(apbh,
58 sizeof(struct apbh_softc),
59 apbh_match,
60 apbh_attach,
61 apbh_detach,
62 apbh_activate,
63 NULL,
64 NULL,
65 0);
66
67 static int
68 apbh_match(device_t parent, cfdata_t match, void *aux)
69 {
70 struct mainbus_attach_args *mb = aux;
71
72 if ((mb->mb_iobase == APBH_BASE) && (mb->mb_iosize == APBH_SIZE))
73 return 1;
74
75 return 0;
76 }
77
78 static void
79 apbh_attach(device_t parent, device_t self, void *aux)
80 {
81 struct apb_attach_args aa;
82 static int apbh_attached = 0;
83
84 if (apbh_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_ia(apbh_search_crit_cb, self, "apbh", &aa);
93 config_search_ia(apbh_search_cb, self, "apbh", &aa);
94
95 apbh_attached = 1;
96
97 return;
98 }
99
100 static int
101 apbh_detach(device_t self, int flags)
102 {
103 return 0;
104 }
105
106 static int
107 apbh_activate(device_t self, enum devact act)
108 {
109 return EOPNOTSUPP;
110 }
111
112 /*
113 * config_search_ia() callback function.
114 */
115 static int
116 apbh_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
117 {
118 struct apb_attach_args *aa = aux;
119
120 aa->aa_name = cf->cf_name;
121 aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
122 aa->aa_size = cf->cf_loc[APBHCF_SIZE];
123 aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
124
125 if (config_match(parent, cf, aux) > 0)
126 config_attach(parent, cf, aux, apbh_print);
127
128 return 0;
129 }
130
131 /*
132 * config_search_ia() callback function which only applies to critical devices.
133 */
134 static int
135 apbh_search_crit_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
136 {
137 struct apb_attach_args *aa = aux;
138
139 /* Return if not critical device. */
140 if ((strcmp(cf->cf_name, "icoll") != 0)
141 && (strcmp(cf->cf_name, "apbdma") != 0))
142 return 0;
143
144 aa->aa_name = cf->cf_name;
145 aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
146 aa->aa_size = cf->cf_loc[APBHCF_SIZE];
147 aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
148
149 if (config_match(parent, cf, aux) > 0)
150 config_attach(parent, cf, aux, apbh_print);
151
152 return 0;
153 }
154
155 /*
156 * Called from config_attach()
157 */
158 static int
159 apbh_print(void *aux, const char *name __unused)
160 {
161 struct apb_attach_args *aa = aux;
162
163 if (aa->aa_addr != APBHCF_ADDR_DEFAULT) {
164 aprint_normal(" addr 0x%lx", aa->aa_addr);
165 if (aa->aa_size > APBHCF_SIZE_DEFAULT)
166 aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
167 }
168
169 if (aa->aa_irq != APBHCF_IRQ_DEFAULT)
170 aprint_normal(" irq %d", aa->aa_irq);
171
172 return UNCONF;
173 }
174