1 /* $NetBSD: sa11x0.c,v 1.24 2009/05/29 14:15:44 rjs Exp $ */
4 * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 * Shin Takemura and PocketBSD Project. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the PocketBSD project
45 * and its contributors.
46 * 4. Neither the name of the project nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: sa11x0.c,v 1.24 2009/05/29 14:15:44 rjs Exp $");
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/device.h>
70 #include <sys/kernel.h>
71 #include <sys/reboot.h>
73 #include <uvm/uvm_extern.h>
75 #include <machine/cpu.h>
76 #include <machine/bus.h>
78 #include <arm/arm32/psl.h>
79 #include <arm/arm32/machdep.h>
80 #include <arm/mainbus/mainbus.h>
81 #include <arm/sa11x0/sa11x0_reg.h>
82 #include <arm/sa11x0/sa11x0_var.h>
83 #include <arm/sa11x0/sa11x0_dmacreg.h>
84 #include <arm/sa11x0/sa11x0_ppcreg.h>
85 #include <arm/sa11x0/sa11x0_gpioreg.h>
90 static int sa11x0_match(device_t
, cfdata_t
, void *);
91 static void sa11x0_attach(device_t
, device_t
, void *);
92 static int sa11x0_search(device_t
, cfdata_t
, const int *, void *);
93 static int sa11x0_print(void *, const char *);
95 /* attach structures */
96 CFATTACH_DECL_NEW(saip
, sizeof(struct sa11x0_softc
),
97 sa11x0_match
, sa11x0_attach
, NULL
, NULL
);
99 extern struct bus_space sa11x0_bs_tag
;
100 extern vaddr_t saipic_base
;
103 * int sa11x0_print(void *aux, const char *name)
104 * print configuration info for children
108 sa11x0_print(void *aux
, const char *name
)
110 struct sa11x0_attach_args
*sa
= (struct sa11x0_attach_args
*)aux
;
113 aprint_normal(" addr 0x%lx", sa
->sa_addr
);
115 aprint_normal("-0x%lx", sa
->sa_addr
+ sa
->sa_size
- 1);
117 aprint_normal(" intr %d", sa
->sa_intr
);
118 if (sa
->sa_gpio
!= -1)
119 aprint_normal(" gpio %d", sa
->sa_gpio
);
125 sa11x0_match(device_t parent
, cfdata_t match
, void *aux
)
132 sa11x0_attach(device_t parent
, device_t self
, void *aux
)
134 struct sa11x0_softc
*sc
= device_private(self
);
137 sc
->sc_iot
= &sa11x0_bs_tag
;
140 if (bus_space_map(sc
->sc_iot
, SAIPIC_BASE
, SAIPIC_NPORTS
,
142 panic("%s: Cannot map registers", self
->dv_xname
);
143 saipic_base
= sc
->sc_ioh
;
145 /* Map the GPIO registers */
146 if (bus_space_map(sc
->sc_iot
, SAGPIO_BASE
, SAGPIO_NPORTS
,
148 panic("%s: unable to map GPIO registers", self
->dv_xname
);
149 bus_space_write_4(sc
->sc_iot
, sc
->sc_gpioh
, SAGPIO_EDR
, 0xffffffff);
151 /* Map the PPC registers */
152 if (bus_space_map(sc
->sc_iot
, SAPPC_BASE
, SAPPC_NPORTS
,
154 panic("%s: unable to map PPC registers", self
->dv_xname
);
156 /* Map the DMA controller registers */
157 if (bus_space_map(sc
->sc_iot
, SADMAC_BASE
, SADMAC_NPORTS
,
159 panic("%s: unable to map DMAC registers", self
->dv_xname
);
161 /* Map the reset controller registers */
162 if (bus_space_map(sc
->sc_iot
, SARCR_BASE
, PAGE_SIZE
,
164 panic("%s: unable to map reset registers", self
->dv_xname
);
169 * Mask all interrupts.
170 * They are later unmasked at each device's attach routine.
172 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, SAIPIC_MR
, 0);
174 /* Route all bits to IRQ */
175 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, SAIPIC_LR
, 0);
177 /* Exit idle mode only when unmasked intr is received */
178 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, SAIPIC_CR
, 1);
180 /* disable all DMAC channels */
181 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR0_CLR
, 1);
182 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR1_CLR
, 1);
183 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR2_CLR
, 1);
184 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR3_CLR
, 1);
185 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR4_CLR
, 1);
186 bus_space_write_4(sc
->sc_iot
, sc
->sc_dmach
, SADMAC_DCR5_CLR
, 1);
188 /* Make sure to init spl masks, note we set the mask to 0 above */
194 * Attach each devices
196 config_search_ia(sa11x0_search
, self
, "saip", NULL
);
200 sa11x0_search(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
202 struct sa11x0_softc
*sc
= device_private(parent
);
203 struct sa11x0_attach_args sa
;
206 sa
.sa_iot
= sc
->sc_iot
;
207 sa
.sa_name
= cf
->cf_name
;
208 sa
.sa_addr
= cf
->cf_loc
[SAIPCF_ADDR
];
209 sa
.sa_size
= cf
->cf_loc
[SAIPCF_SIZE
];
210 sa
.sa_intr
= cf
->cf_loc
[SAIPCF_INTR
];
211 sa
.sa_gpio
= cf
->cf_loc
[SAIPCF_GPIO
];
213 if (config_match(parent
, cf
, &sa
) > 0)
214 config_attach(parent
, cf
, &sa
, sa11x0_print
);