s3c2800.c revision 1.2 1 1.2 thorpej /* $NetBSD: s3c2800.c,v 1.2 2003/01/01 00:46:15 thorpej Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.1 bsh * Copyright (c) 2002 Fujitsu Component Limited
5 1.1 bsh * Copyright (c) 2002 Genetec Corporation
6 1.1 bsh * All rights reserved.
7 1.1 bsh *
8 1.1 bsh * Redistribution and use in source and binary forms, with or without
9 1.1 bsh * modification, are permitted provided that the following conditions
10 1.1 bsh * are met:
11 1.1 bsh * 1. Redistributions of source code must retain the above copyright
12 1.1 bsh * notice, this list of conditions and the following disclaimer.
13 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 bsh * notice, this list of conditions and the following disclaimer in the
15 1.1 bsh * documentation and/or other materials provided with the distribution.
16 1.1 bsh * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 1.1 bsh * Genetec corporation may not be used to endorse or promote products
18 1.1 bsh * derived from this software without specific prior written permission.
19 1.1 bsh *
20 1.1 bsh * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 1.1 bsh * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 1.1 bsh * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 1.1 bsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 1.1 bsh * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 1.1 bsh * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 bsh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 1.1 bsh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 1.1 bsh * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 1.1 bsh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 1.1 bsh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 1.1 bsh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 bsh * SUCH DAMAGE.
33 1.1 bsh */
34 1.1 bsh
35 1.1 bsh
36 1.1 bsh #include <sys/param.h>
37 1.1 bsh #include <sys/systm.h>
38 1.1 bsh #include <sys/device.h>
39 1.1 bsh #include <sys/kernel.h>
40 1.1 bsh #include <sys/reboot.h>
41 1.1 bsh
42 1.1 bsh #include <machine/cpu.h>
43 1.1 bsh #include <machine/bus.h>
44 1.1 bsh
45 1.1 bsh #include <arm/cpufunc.h>
46 1.1 bsh #include <arm/mainbus/mainbus.h>
47 1.1 bsh #include <arm/s3c2xx0/s3c2800reg.h>
48 1.1 bsh #include <arm/s3c2xx0/s3c2800var.h>
49 1.1 bsh
50 1.1 bsh #include "locators.h"
51 1.1 bsh
52 1.1 bsh /* prototypes */
53 1.1 bsh static int s3c2800_match(struct device *, struct cfdata *, void *);
54 1.1 bsh static void s3c2800_attach(struct device *, struct device *, void *);
55 1.1 bsh static int s3c2800_search(struct device *, struct cfdata *, void *);
56 1.1 bsh
57 1.1 bsh /* attach structures */
58 1.1 bsh CFATTACH_DECL(ssio, sizeof(struct s3c2800_softc), s3c2800_match, s3c2800_attach,
59 1.1 bsh NULL, NULL);
60 1.1 bsh
61 1.1 bsh extern struct bus_space s3c2xx0_bs_tag;
62 1.1 bsh
63 1.1 bsh struct s3c2xx0_softc *s3c2xx0_softc;
64 1.1 bsh
65 1.1 bsh static int
66 1.1 bsh s3c2800_print(void *aux, const char *name)
67 1.1 bsh {
68 1.1 bsh struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *) aux;
69 1.1 bsh
70 1.1 bsh if (sa->sa_size)
71 1.2 thorpej aprint_normal(" addr 0x%lx", sa->sa_addr);
72 1.1 bsh if (sa->sa_size > 1)
73 1.2 thorpej aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
74 1.1 bsh if (sa->sa_intr != SSIOCF_INTR_DEFAULT)
75 1.2 thorpej aprint_normal(" intr %d", sa->sa_intr);
76 1.1 bsh if (sa->sa_index != SSIOCF_INDEX_DEFAULT)
77 1.2 thorpej aprint_normal(" unit %d", sa->sa_index);
78 1.1 bsh
79 1.1 bsh return (UNCONF);
80 1.1 bsh }
81 1.1 bsh
82 1.1 bsh int
83 1.1 bsh s3c2800_match(struct device *parent, struct cfdata *match, void *aux)
84 1.1 bsh {
85 1.1 bsh return 1;
86 1.1 bsh }
87 1.1 bsh
88 1.1 bsh void
89 1.1 bsh s3c2800_attach(struct device *parent, struct device *self, void *aux)
90 1.1 bsh {
91 1.1 bsh struct s3c2800_softc *sc = (struct s3c2800_softc *) self;
92 1.1 bsh bus_space_tag_t iot;
93 1.1 bsh const char *which_registers; /* for panic message */
94 1.1 bsh
95 1.1 bsh #define FAIL(which) do { \
96 1.1 bsh which_registers=(which); goto abort; }while(/*CONSTCOND*/0)
97 1.1 bsh
98 1.1 bsh s3c2xx0_softc = &(sc->sc_sx);
99 1.1 bsh sc->sc_sx.sc_iot = iot = &s3c2xx0_bs_tag;
100 1.1 bsh
101 1.1 bsh if (bus_space_map(iot,
102 1.1 bsh S3C2800_INTCTL_BASE, S3C2800_INTCTL_SIZE,
103 1.1 bsh BUS_SPACE_MAP_LINEAR, &sc->sc_sx.sc_intctl_ioh))
104 1.1 bsh FAIL("intc");
105 1.1 bsh /* tell register addresses to interrupt handler */
106 1.1 bsh s3c2800_intr_init(sc);
107 1.1 bsh
108 1.1 bsh /* Map the GPIO registers */
109 1.1 bsh if (bus_space_map(iot, S3C2800_GPIO_BASE, S3C2800_GPIO_SIZE,
110 1.1 bsh 0, &sc->sc_sx.sc_gpio_ioh))
111 1.1 bsh FAIL("GPIO");
112 1.1 bsh
113 1.1 bsh #if 0
114 1.1 bsh /* Map the DMA controller registers */
115 1.1 bsh if (bus_space_map(iot, S3C2800_DMAC_BASE, S3C2800_DMAC_SIZE,
116 1.1 bsh 0, &sc->sc_sx.sc_dmach))
117 1.1 bsh FAIL("DMAC");
118 1.1 bsh #endif
119 1.1 bsh
120 1.1 bsh /* Memory controller */
121 1.1 bsh if (bus_space_map(iot, S3C2800_MEMCTL_BASE,
122 1.1 bsh S3C2800_MEMCTL_SIZE, 0, &sc->sc_sx.sc_memctl_ioh))
123 1.1 bsh FAIL("MEMC");
124 1.1 bsh /* Clock manager */
125 1.1 bsh if (bus_space_map(iot, S3C2800_CLKMAN_BASE,
126 1.1 bsh S3C2800_CLKMAN_SIZE, 0, &sc->sc_sx.sc_clkman_ioh))
127 1.1 bsh FAIL("CLK");
128 1.1 bsh
129 1.1 bsh #if 0
130 1.1 bsh /* Real time clock */
131 1.1 bsh if (bus_space_map(iot, S3C2800_RTC_BASE,
132 1.1 bsh S3C2800_RTC_SIZE, 0, &sc->sc_sx.sc_rtc_ioh))
133 1.1 bsh FAIL("RTC");
134 1.1 bsh #endif
135 1.1 bsh
136 1.1 bsh if (bus_space_map(iot, S3C2800_TIMER0_BASE,
137 1.1 bsh S3C2800_TIMER_SIZE, 0, &sc->sc_tmr0_ioh))
138 1.1 bsh FAIL("TIMER0");
139 1.1 bsh
140 1.1 bsh if (bus_space_map(iot, S3C2800_TIMER1_BASE,
141 1.1 bsh S3C2800_TIMER_SIZE, 0, &sc->sc_tmr1_ioh))
142 1.1 bsh FAIL("TIMER0");
143 1.1 bsh
144 1.1 bsh
145 1.1 bsh printf("\n");
146 1.1 bsh
147 1.1 bsh
148 1.1 bsh /*
149 1.1 bsh * Attach devices.
150 1.1 bsh */
151 1.1 bsh config_search(s3c2800_search, self, NULL);
152 1.1 bsh return;
153 1.1 bsh
154 1.1 bsh abort:
155 1.1 bsh panic("%s: unable to map %s registers",
156 1.1 bsh self->dv_xname, which_registers);
157 1.1 bsh
158 1.1 bsh #undef FAIL
159 1.1 bsh }
160 1.1 bsh
161 1.1 bsh int
162 1.1 bsh s3c2800_search(struct device * parent, struct cfdata * cf, void *aux)
163 1.1 bsh {
164 1.1 bsh struct s3c2800_softc *sc = (struct s3c2800_softc *) parent;
165 1.1 bsh struct s3c2xx0_attach_args aa;
166 1.1 bsh
167 1.1 bsh aa.sa_sc = sc;
168 1.1 bsh aa.sa_iot = sc->sc_sx.sc_iot;
169 1.1 bsh aa.sa_addr = cf->cf_loc[SSIOCF_ADDR];
170 1.1 bsh aa.sa_size = cf->cf_loc[SSIOCF_SIZE];
171 1.1 bsh aa.sa_index = cf->cf_loc[SSIOCF_INDEX];
172 1.1 bsh aa.sa_intr = cf->cf_loc[SSIOCF_INTR];
173 1.1 bsh
174 1.1 bsh if (config_match(parent, cf, &aa))
175 1.1 bsh config_attach(parent, cf, &aa, s3c2800_print);
176 1.1 bsh
177 1.1 bsh return 0;
178 1.1 bsh }
179 1.1 bsh
180 1.1 bsh void
181 1.1 bsh s3c2800_softreset(void)
182 1.1 bsh {
183 1.1 bsh /* XXX */
184 1.1 bsh }
185