imx23_ahb.c revision 1.1 1 /* $Id: imx23_ahb.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */
2
3 /*
4 * Copyright (c) 2013 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 ahb_match(device_t, cfdata_t, void *);
44 static void ahb_attach(device_t, device_t, void *);
45 static int ahb_detach(device_t, int);
46 static int ahb_activate(device_t, enum devact);
47
48 static int ahb_search_cb(device_t, cfdata_t, const int *, void *);
49 static int ahb_print(void *,const char *);
50
51 CFATTACH_DECL3_NEW(ahb,
52 sizeof(struct ahb_softc),
53 ahb_match,
54 ahb_attach,
55 ahb_detach,
56 ahb_activate,
57 NULL,
58 NULL,
59 0);
60
61 static int
62 ahb_match(device_t parent, cfdata_t match, void *aux)
63 {
64 struct mainbus_attach_args *mb = aux;
65
66 if ((mb->mb_iobase == AHB_BASE) && (mb->mb_iosize == AHB_SIZE))
67 return 1;
68
69 return 0;
70 }
71
72 static void
73 ahb_attach(device_t parent, device_t self, void *aux)
74 {
75 struct ahb_attach_args aa;
76 static int ahb_attached = 0;
77
78 if (ahb_attached)
79 return;
80
81 aa.aa_iot = &imx23_bus_space;
82 aa.aa_dmat = &imx23_bus_dma_tag;
83
84 aprint_normal("\n");
85
86 config_search_ia(ahb_search_cb, self, "ahb", &aa);
87
88 ahb_attached = 1;
89
90 return;
91 }
92
93 static int
94 ahb_detach(device_t self, int flags)
95 {
96 return 0;
97 }
98
99 static int
100 ahb_activate(device_t self, enum devact act)
101 {
102 return EOPNOTSUPP;
103 }
104
105 /*
106 * config_search_ia() callback function.
107 */
108 static int
109 ahb_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
110 {
111 struct apb_attach_args *aa = aux;
112
113 aa->aa_name = cf->cf_name;
114 aa->aa_addr = cf->cf_loc[AHBCF_ADDR];
115 aa->aa_size = cf->cf_loc[AHBCF_SIZE];
116 aa->aa_irq = cf->cf_loc[AHBCF_IRQ];
117
118 if (config_match(parent, cf, aux) > 0)
119 config_attach(parent, cf, aux, ahb_print);
120
121 return 0;
122 }
123
124 /*
125 * Called from config_attach()
126 */
127 static int
128 ahb_print(void *aux, const char *name __unused)
129 {
130 struct apb_attach_args *aa = aux;
131
132 if (aa->aa_addr != AHBCF_ADDR_DEFAULT) {
133 aprint_normal(" addr 0x%lx", aa->aa_addr);
134 if (aa->aa_size > AHBCF_SIZE_DEFAULT)
135 aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
136 }
137
138 if (aa->aa_irq != AHBCF_IRQ_DEFAULT)
139 aprint_normal(" irq %d", aa->aa_irq);
140
141 return UNCONF;
142 }
143