imx23_apbh.c revision 1.1.2.2 1 1.1.2.2 yamt /* $Id: imx23_apbh.c,v 1.1.2.2 2013/01/16 05:32:47 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*
4 1.1.2.2 yamt * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 1.1.2.2 yamt * All rights reserved.
6 1.1.2.2 yamt *
7 1.1.2.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 yamt * by Petri Laakso.
9 1.1.2.2 yamt *
10 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 yamt * modification, are permitted provided that the following conditions
12 1.1.2.2 yamt * are met:
13 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.2.2 yamt *
19 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.1.2.2 yamt */
31 1.1.2.2 yamt
32 1.1.2.2 yamt #include <sys/param.h>
33 1.1.2.2 yamt #include <sys/bus.h>
34 1.1.2.2 yamt #include <sys/device.h>
35 1.1.2.2 yamt #include <sys/errno.h>
36 1.1.2.2 yamt
37 1.1.2.2 yamt #include <arm/mainbus/mainbus.h>
38 1.1.2.2 yamt
39 1.1.2.2 yamt #include <arm/imx/imx23var.h>
40 1.1.2.2 yamt
41 1.1.2.2 yamt #include "locators.h"
42 1.1.2.2 yamt
43 1.1.2.2 yamt static int apbh_match(device_t, cfdata_t, void *);
44 1.1.2.2 yamt static void apbh_attach(device_t, device_t, void *);
45 1.1.2.2 yamt static int apbh_detach(device_t, int);
46 1.1.2.2 yamt static int apbh_activate(device_t, enum devact);
47 1.1.2.2 yamt
48 1.1.2.2 yamt static int apbh_search_cb(device_t, cfdata_t, const int *, void *);
49 1.1.2.2 yamt static int apbh_search_crit_cb(device_t, cfdata_t, const int *, void *);
50 1.1.2.2 yamt static int apbh_print(void *,const char *);
51 1.1.2.2 yamt
52 1.1.2.2 yamt struct apbh_softc {
53 1.1.2.2 yamt device_t sc_dev;
54 1.1.2.2 yamt device_t dmac; /* DMA controller device for this bus. */
55 1.1.2.2 yamt };
56 1.1.2.2 yamt
57 1.1.2.2 yamt CFATTACH_DECL3_NEW(apbh,
58 1.1.2.2 yamt sizeof(struct apbh_softc),
59 1.1.2.2 yamt apbh_match,
60 1.1.2.2 yamt apbh_attach,
61 1.1.2.2 yamt apbh_detach,
62 1.1.2.2 yamt apbh_activate,
63 1.1.2.2 yamt NULL,
64 1.1.2.2 yamt NULL,
65 1.1.2.2 yamt 0);
66 1.1.2.2 yamt
67 1.1.2.2 yamt static int
68 1.1.2.2 yamt apbh_match(device_t parent, cfdata_t match, void *aux)
69 1.1.2.2 yamt {
70 1.1.2.2 yamt struct mainbus_attach_args *mb = aux;
71 1.1.2.2 yamt
72 1.1.2.2 yamt if ((mb->mb_iobase == APBH_BASE) && (mb->mb_iosize == APBH_SIZE))
73 1.1.2.2 yamt return 1;
74 1.1.2.2 yamt
75 1.1.2.2 yamt return 0;
76 1.1.2.2 yamt }
77 1.1.2.2 yamt
78 1.1.2.2 yamt static void
79 1.1.2.2 yamt apbh_attach(device_t parent, device_t self, void *aux)
80 1.1.2.2 yamt {
81 1.1.2.2 yamt struct apb_attach_args aa;
82 1.1.2.2 yamt static int apbh_attached = 0;
83 1.1.2.2 yamt
84 1.1.2.2 yamt if (apbh_attached)
85 1.1.2.2 yamt return;
86 1.1.2.2 yamt
87 1.1.2.2 yamt aa.aa_iot = &imx23_bus_space;
88 1.1.2.2 yamt aa.aa_dmat = &imx23_bus_dma_tag;
89 1.1.2.2 yamt
90 1.1.2.2 yamt aprint_normal("\n");
91 1.1.2.2 yamt
92 1.1.2.2 yamt config_search_ia(apbh_search_crit_cb, self, "apbh", &aa);
93 1.1.2.2 yamt config_search_ia(apbh_search_cb, self, "apbh", &aa);
94 1.1.2.2 yamt
95 1.1.2.2 yamt apbh_attached = 1;
96 1.1.2.2 yamt
97 1.1.2.2 yamt return;
98 1.1.2.2 yamt }
99 1.1.2.2 yamt
100 1.1.2.2 yamt static int
101 1.1.2.2 yamt apbh_detach(device_t self, int flags)
102 1.1.2.2 yamt {
103 1.1.2.2 yamt return 0;
104 1.1.2.2 yamt }
105 1.1.2.2 yamt
106 1.1.2.2 yamt static int
107 1.1.2.2 yamt apbh_activate(device_t self, enum devact act)
108 1.1.2.2 yamt {
109 1.1.2.2 yamt return EOPNOTSUPP;
110 1.1.2.2 yamt }
111 1.1.2.2 yamt
112 1.1.2.2 yamt /*
113 1.1.2.2 yamt * config_search_ia() callback function.
114 1.1.2.2 yamt */
115 1.1.2.2 yamt static int
116 1.1.2.2 yamt apbh_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
117 1.1.2.2 yamt {
118 1.1.2.2 yamt struct apb_attach_args *aa = aux;
119 1.1.2.2 yamt
120 1.1.2.2 yamt aa->aa_name = cf->cf_name;
121 1.1.2.2 yamt aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
122 1.1.2.2 yamt aa->aa_size = cf->cf_loc[APBHCF_SIZE];
123 1.1.2.2 yamt aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
124 1.1.2.2 yamt
125 1.1.2.2 yamt if (config_match(parent, cf, aux) > 0)
126 1.1.2.2 yamt config_attach(parent, cf, aux, apbh_print);
127 1.1.2.2 yamt
128 1.1.2.2 yamt return 0;
129 1.1.2.2 yamt }
130 1.1.2.2 yamt
131 1.1.2.2 yamt /*
132 1.1.2.2 yamt * config_search_ia() callback function which only applies to critical devices.
133 1.1.2.2 yamt */
134 1.1.2.2 yamt static int
135 1.1.2.2 yamt apbh_search_crit_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
136 1.1.2.2 yamt {
137 1.1.2.2 yamt struct apb_attach_args *aa = aux;
138 1.1.2.2 yamt
139 1.1.2.2 yamt /* Return if not critical device. */
140 1.1.2.2 yamt if ((strcmp(cf->cf_name, "icoll") != 0)
141 1.1.2.2 yamt && (strcmp(cf->cf_name, "apbdma") != 0))
142 1.1.2.2 yamt return 0;
143 1.1.2.2 yamt
144 1.1.2.2 yamt aa->aa_name = cf->cf_name;
145 1.1.2.2 yamt aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
146 1.1.2.2 yamt aa->aa_size = cf->cf_loc[APBHCF_SIZE];
147 1.1.2.2 yamt aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
148 1.1.2.2 yamt
149 1.1.2.2 yamt if (config_match(parent, cf, aux) > 0)
150 1.1.2.2 yamt config_attach(parent, cf, aux, apbh_print);
151 1.1.2.2 yamt
152 1.1.2.2 yamt return 0;
153 1.1.2.2 yamt }
154 1.1.2.2 yamt
155 1.1.2.2 yamt /*
156 1.1.2.2 yamt * Called from config_attach()
157 1.1.2.2 yamt */
158 1.1.2.2 yamt static int
159 1.1.2.2 yamt apbh_print(void *aux, const char *name __unused)
160 1.1.2.2 yamt {
161 1.1.2.2 yamt struct apb_attach_args *aa = aux;
162 1.1.2.2 yamt
163 1.1.2.2 yamt if (aa->aa_addr != APBHCF_ADDR_DEFAULT) {
164 1.1.2.2 yamt aprint_normal(" addr 0x%lx", aa->aa_addr);
165 1.1.2.2 yamt if (aa->aa_size > APBHCF_SIZE_DEFAULT)
166 1.1.2.2 yamt aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
167 1.1.2.2 yamt }
168 1.1.2.2 yamt
169 1.1.2.2 yamt if (aa->aa_irq != APBHCF_IRQ_DEFAULT)
170 1.1.2.2 yamt aprint_normal(" irq %d", aa->aa_irq);
171 1.1.2.2 yamt
172 1.1.2.2 yamt return UNCONF;
173 1.1.2.2 yamt }
174