imx51_axi.c revision 1.2.6.2 1 1.2.6.2 rmind /* $NetBSD: imx51_axi.c,v 1.2.6.2 2011/03/05 20:49:34 rmind Exp $ */
2 1.2.6.2 rmind
3 1.2.6.2 rmind /*-
4 1.2.6.2 rmind * Copyright (c) 2010 SHIMIZU Ryo <ryo (at) nerv.org>
5 1.2.6.2 rmind * All rights reserved.
6 1.2.6.2 rmind *
7 1.2.6.2 rmind * Redistribution and use in source and binary forms, with or without
8 1.2.6.2 rmind * modification, are permitted provided that the following conditions
9 1.2.6.2 rmind * are met:
10 1.2.6.2 rmind * 1. Redistributions of source code must retain the above copyright
11 1.2.6.2 rmind * notice, this list of conditions and the following disclaimer.
12 1.2.6.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.6.2 rmind * notice, this list of conditions and the following disclaimer in the
14 1.2.6.2 rmind * documentation and/or other materials provided with the distribution.
15 1.2.6.2 rmind *
16 1.2.6.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.6.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.2.6.2 rmind * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.2.6.2 rmind * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.2.6.2 rmind * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.2.6.2 rmind * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.2.6.2 rmind * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2.6.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.2.6.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 1.2.6.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.2.6.2 rmind * POSSIBILITY OF SUCH DAMAGE.
27 1.2.6.2 rmind */
28 1.2.6.2 rmind
29 1.2.6.2 rmind #include <sys/cdefs.h>
30 1.2.6.2 rmind __KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.2.6.2 2011/03/05 20:49:34 rmind Exp $");
31 1.2.6.2 rmind
32 1.2.6.2 rmind #include <sys/param.h>
33 1.2.6.2 rmind #include <sys/bus.h>
34 1.2.6.2 rmind #include <sys/device.h>
35 1.2.6.2 rmind
36 1.2.6.2 rmind #include <uvm/uvm_extern.h>
37 1.2.6.2 rmind
38 1.2.6.2 rmind #include <arm/imx/imx51reg.h>
39 1.2.6.2 rmind #include <arm/imx/imx51var.h>
40 1.2.6.2 rmind
41 1.2.6.2 rmind #include "locators.h"
42 1.2.6.2 rmind
43 1.2.6.2 rmind struct axi_softc {
44 1.2.6.2 rmind device_t sc_dev;
45 1.2.6.2 rmind bus_space_tag_t sc_iot;
46 1.2.6.2 rmind bus_dma_tag_t sc_dmat;
47 1.2.6.2 rmind };
48 1.2.6.2 rmind
49 1.2.6.2 rmind static int axi_match(device_t, struct cfdata *, void *);
50 1.2.6.2 rmind static void axi_attach(device_t, device_t, void *);
51 1.2.6.2 rmind static int axi_search(device_t, struct cfdata *, const int *, void *);
52 1.2.6.2 rmind static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
53 1.2.6.2 rmind static int axi_search(device_t, struct cfdata *, const int *, void *);
54 1.2.6.2 rmind static int axi_print(void *, const char *);
55 1.2.6.2 rmind
56 1.2.6.2 rmind CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
57 1.2.6.2 rmind axi_match, axi_attach, NULL, NULL);
58 1.2.6.2 rmind
59 1.2.6.2 rmind /* ARGSUSED */
60 1.2.6.2 rmind static int
61 1.2.6.2 rmind axi_match(device_t parent __unused, struct cfdata *match __unused,
62 1.2.6.2 rmind void *aux __unused)
63 1.2.6.2 rmind {
64 1.2.6.2 rmind return 1;
65 1.2.6.2 rmind }
66 1.2.6.2 rmind
67 1.2.6.2 rmind /* ARGSUSED */
68 1.2.6.2 rmind static void
69 1.2.6.2 rmind axi_attach(device_t parent __unused, device_t self, void *aux __unused)
70 1.2.6.2 rmind {
71 1.2.6.2 rmind struct axi_softc *sc;
72 1.2.6.2 rmind struct axi_attach_args aa;
73 1.2.6.2 rmind
74 1.2.6.2 rmind aprint_normal(": Advanced eXtensible Interface\n");
75 1.2.6.2 rmind aprint_naive("\n");
76 1.2.6.2 rmind
77 1.2.6.2 rmind sc = device_private(self);
78 1.2.6.2 rmind sc->sc_iot = &imx_bs_tag;
79 1.2.6.2 rmind #if NBUS_DMA_GENERIC > 0
80 1.2.6.2 rmind sc->sc_dmat = &imx_bus_dma_tag;
81 1.2.6.2 rmind #else
82 1.2.6.2 rmind sc->sc_dmat = 0;
83 1.2.6.2 rmind #endif
84 1.2.6.2 rmind
85 1.2.6.2 rmind aa.aa_name = "axi";
86 1.2.6.2 rmind aa.aa_iot = sc->sc_iot;
87 1.2.6.2 rmind aa.aa_dmat = sc->sc_dmat;
88 1.2.6.2 rmind config_search_ia(axi_critical_search, self, "axi", &aa);
89 1.2.6.2 rmind config_search_ia(axi_search, self, "axi", &aa);
90 1.2.6.2 rmind }
91 1.2.6.2 rmind
92 1.2.6.2 rmind /* ARGSUSED */
93 1.2.6.2 rmind static int
94 1.2.6.2 rmind axi_critical_search(device_t parent, struct cfdata *cf,
95 1.2.6.2 rmind const int *ldesc __unused, void *aux)
96 1.2.6.2 rmind {
97 1.2.6.2 rmind struct axi_softc *sc;
98 1.2.6.2 rmind struct axi_attach_args *aa;
99 1.2.6.2 rmind
100 1.2.6.2 rmind sc = device_private(parent);
101 1.2.6.2 rmind aa = aux;
102 1.2.6.2 rmind
103 1.2.6.2 rmind if ((strcmp(cf->cf_name, "tzic") != 0) &&
104 1.2.6.2 rmind (strcmp(cf->cf_name, "imxuart") != 0) &&
105 1.2.6.2 rmind (strcmp(cf->cf_name, "imxgpio") != 0))
106 1.2.6.2 rmind return 0;
107 1.2.6.2 rmind
108 1.2.6.2 rmind aa->aa_name = cf->cf_name;
109 1.2.6.2 rmind aa->aa_addr = cf->cf_loc[AXICF_ADDR];
110 1.2.6.2 rmind aa->aa_size = cf->cf_loc[AXICF_SIZE];
111 1.2.6.2 rmind aa->aa_irq = cf->cf_loc[AXICF_IRQ];
112 1.2.6.2 rmind aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
113 1.2.6.2 rmind
114 1.2.6.2 rmind if (config_match(parent, cf, aux) > 0)
115 1.2.6.2 rmind config_attach(parent, cf, aux, axi_print);
116 1.2.6.2 rmind
117 1.2.6.2 rmind return 0;
118 1.2.6.2 rmind }
119 1.2.6.2 rmind
120 1.2.6.2 rmind
121 1.2.6.2 rmind /* ARGSUSED */
122 1.2.6.2 rmind static int
123 1.2.6.2 rmind axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
124 1.2.6.2 rmind void *aux)
125 1.2.6.2 rmind {
126 1.2.6.2 rmind struct axi_softc *sc;
127 1.2.6.2 rmind struct axi_attach_args *aa;
128 1.2.6.2 rmind
129 1.2.6.2 rmind sc = device_private(parent);
130 1.2.6.2 rmind aa = aux;
131 1.2.6.2 rmind
132 1.2.6.2 rmind aa->aa_addr = cf->cf_loc[AXICF_ADDR];
133 1.2.6.2 rmind aa->aa_size = cf->cf_loc[AXICF_SIZE];
134 1.2.6.2 rmind aa->aa_irq = cf->cf_loc[AXICF_IRQ];
135 1.2.6.2 rmind aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
136 1.2.6.2 rmind
137 1.2.6.2 rmind if (config_match(parent, cf, aux) > 0)
138 1.2.6.2 rmind config_attach(parent, cf, aux, axi_print);
139 1.2.6.2 rmind
140 1.2.6.2 rmind return 0;
141 1.2.6.2 rmind }
142 1.2.6.2 rmind
143 1.2.6.2 rmind /* ARGSUSED */
144 1.2.6.2 rmind static int
145 1.2.6.2 rmind axi_print(void *aux, const char *name __unused)
146 1.2.6.2 rmind {
147 1.2.6.2 rmind struct axi_attach_args *aa = (struct axi_attach_args *)aux;
148 1.2.6.2 rmind
149 1.2.6.2 rmind if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
150 1.2.6.2 rmind aprint_normal(" addr 0x%lx", aa->aa_addr);
151 1.2.6.2 rmind if (aa->aa_size > AXICF_SIZE_DEFAULT)
152 1.2.6.2 rmind aprint_normal("-0x%lx",
153 1.2.6.2 rmind aa->aa_addr + aa->aa_size-1);
154 1.2.6.2 rmind }
155 1.2.6.2 rmind if (aa->aa_irq != AXICF_IRQ_DEFAULT)
156 1.2.6.2 rmind aprint_normal(" intr %d", aa->aa_irq);
157 1.2.6.2 rmind if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
158 1.2.6.2 rmind aprint_normal(" irqbase %d", aa->aa_irqbase);
159 1.2.6.2 rmind
160 1.2.6.2 rmind return (UNCONF);
161 1.2.6.2 rmind }
162