epsoc.c revision 1.2 1 1.2 he /* $NetBSD: epsoc.c,v 1.2 2005/06/04 22:37:51 he Exp $ */
2 1.1 joff
3 1.1 joff /*
4 1.1 joff * Copyright (c) 2004 Jesse Off
5 1.1 joff * All rights reserved.
6 1.1 joff *
7 1.1 joff * Redistribution and use in source and binary forms, with or without
8 1.1 joff * modification, are permitted provided that the following conditions
9 1.1 joff * are met:
10 1.1 joff * 1. Redistributions of source code must retain the above copyright
11 1.1 joff * notice, this list of conditions and the following disclaimer.
12 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 joff * notice, this list of conditions and the following disclaimer in the
14 1.1 joff * documentation and/or other materials provided with the distribution.
15 1.1 joff * 3. All advertising materials mentioning features or use of this software
16 1.1 joff * must display the following acknowledgement:
17 1.1 joff * This product includes software developed by the NetBSD
18 1.1 joff * Foundation, Inc. and its contributors.
19 1.1 joff * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1 joff * contributors may be used to endorse or promote products derived
21 1.1 joff * from this software without specific prior written permission.
22 1.1 joff *
23 1.1 joff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 joff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 joff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 joff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 joff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 joff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 joff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 joff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 joff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 joff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 joff * POSSIBILITY OF SUCH DAMAGE.
34 1.1 joff */
35 1.1 joff
36 1.1 joff #include <sys/cdefs.h>
37 1.2 he __KERNEL_RCSID(0, "$NetBSD: epsoc.c,v 1.2 2005/06/04 22:37:51 he Exp $");
38 1.1 joff
39 1.1 joff #include <sys/types.h>
40 1.1 joff #include <sys/param.h>
41 1.1 joff #include <sys/systm.h>
42 1.1 joff #include <sys/kernel.h>
43 1.1 joff #include <sys/time.h>
44 1.1 joff #include <sys/device.h>
45 1.1 joff
46 1.1 joff #include <machine/bus.h>
47 1.1 joff #include <machine/intr.h>
48 1.1 joff
49 1.1 joff #include <arm/cpufunc.h>
50 1.1 joff
51 1.1 joff #include <arm/ep93xx/ep93xxreg.h>
52 1.1 joff #include <arm/ep93xx/ep93xxvar.h>
53 1.1 joff #include <arm/ep93xx/epsocvar.h>
54 1.1 joff
55 1.1 joff #include "locators.h"
56 1.1 joff
57 1.1 joff static int epsoc_match(struct device *, struct cfdata *, void *);
58 1.1 joff static void epsoc_attach(struct device *, struct device *, void *);
59 1.1 joff static int epsoc_search(struct device *, struct cfdata *, void *);
60 1.1 joff static int epsoc_print(void *, const char *);
61 1.1 joff
62 1.1 joff CFATTACH_DECL(epsoc, sizeof(struct epsoc_softc),
63 1.1 joff epsoc_match, epsoc_attach, NULL, NULL);
64 1.1 joff
65 1.1 joff struct epsoc_softc *epsoc_sc = NULL;
66 1.1 joff
67 1.1 joff static int
68 1.1 joff epsoc_match(struct device *parent, struct cfdata *match, void *aux)
69 1.1 joff {
70 1.1 joff bus_space_handle_t ioh;
71 1.1 joff u_int32_t id, ret = 0;
72 1.1 joff
73 1.1 joff bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
74 1.1 joff EP93XX_APB_SYSCON_SIZE, 0, &ioh);
75 1.1 joff id = bus_space_read_4(&ep93xx_bs_tag, ioh, EP93XX_SYSCON_ChipID);
76 1.1 joff if ((id & 0x01faffff) == 0x9213) ret = 1;
77 1.1 joff bus_space_unmap(&ep93xx_bs_tag, ioh, EP93XX_APB_SYSCON_SIZE);
78 1.1 joff return ret;
79 1.1 joff }
80 1.1 joff
81 1.1 joff static void
82 1.1 joff epsoc_attach(struct device *parent, struct device *self, void *aux)
83 1.1 joff {
84 1.1 joff struct epsoc_softc *sc;
85 1.1 joff u_int64_t fclk, pclk, hclk;
86 1.1 joff u_int32_t id, clkset1;
87 1.2 he const char *rev;
88 1.1 joff
89 1.1 joff
90 1.1 joff sc = (struct epsoc_softc*) self;
91 1.1 joff
92 1.1 joff if (epsoc_sc == NULL)
93 1.1 joff epsoc_sc = sc;
94 1.1 joff
95 1.1 joff sc->sc_iot = &ep93xx_bs_tag;
96 1.1 joff bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
97 1.1 joff EP93XX_APB_SYSCON_SIZE, 0, &sc->sc_ioh);
98 1.1 joff id = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_SYSCON_ChipID);
99 1.1 joff switch(id >> 28) {
100 1.1 joff case 0:
101 1.1 joff rev = "A";
102 1.1 joff break;
103 1.1 joff case 1:
104 1.1 joff rev = "B";
105 1.1 joff break;
106 1.1 joff case 2:
107 1.1 joff rev = "C";
108 1.1 joff break;
109 1.1 joff case 3:
110 1.1 joff rev = "D0";
111 1.1 joff break;
112 1.1 joff case 4:
113 1.1 joff rev = "D1";
114 1.1 joff break;
115 1.1 joff case 5:
116 1.1 joff rev = "E0";
117 1.1 joff break;
118 1.1 joff case 6:
119 1.1 joff rev = "E1";
120 1.1 joff break;
121 1.1 joff default:
122 1.1 joff rev = ">E1";
123 1.1 joff break;
124 1.1 joff }
125 1.1 joff printf(": Cirrus Logic EP93xx SoC rev %s\n", rev);
126 1.1 joff
127 1.1 joff clkset1 = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
128 1.1 joff EP93XX_SYSCON_ClkSet1);
129 1.1 joff {
130 1.1 joff int fclkdiv, hclkdiv, pclkdiv, pll1_ps;
131 1.1 joff int pll1x1fbd1, pll1x2fbd2, pll1x2ipd;
132 1.1 joff int hclkdivisors[] = {1, 2, 4, 5, 6, 8, 16, 32};
133 1.1 joff
134 1.1 joff fclkdiv = (clkset1 & 0x0e000000) >> 25;
135 1.1 joff hclkdiv = (clkset1 & 0x00700000) >> 20;
136 1.1 joff pclkdiv = (clkset1 & 0x000c0000) >> 18;
137 1.1 joff pll1_ps = (clkset1 & 0x00030000) >> 16;
138 1.1 joff pll1x1fbd1 = (clkset1 & 0x0000f800) >> 11;
139 1.1 joff pll1x2fbd2 = (clkset1 & 0x000007e0) >> 5;
140 1.1 joff pll1x2ipd = (clkset1 & 0x0000001f);
141 1.1 joff fclk = 14745600ULL * ((pll1x1fbd1 + 1) * (pll1x2fbd2 + 1)) /
142 1.1 joff ((pll1x2ipd + 1) * (1 << pll1_ps));
143 1.1 joff hclk = fclk / hclkdivisors[hclkdiv];
144 1.1 joff pclk = hclk >> pclkdiv;
145 1.1 joff if (fclkdiv > 4) fclkdiv = 0;
146 1.1 joff if (clkset1 & 0x00800000) /* nBYP1 bypasses PLL */
147 1.1 joff fclk = fclk >> fclkdiv;
148 1.1 joff else
149 1.1 joff fclk = 14745600ULL;
150 1.1 joff }
151 1.1 joff printf("%s: fclk %lld.%02lld Mhz hclk %lld.%02lld Mhz pclk %lld.%02lld Mhz\n",
152 1.1 joff sc->sc_dev.dv_xname,
153 1.1 joff fclk / 1000000, (fclk % 1000000 + 5000) / 10000,
154 1.1 joff hclk / 1000000, (hclk % 1000000 + 5000) / 10000,
155 1.1 joff pclk / 1000000, (pclk % 1000000 + 5000) / 10000);
156 1.1 joff
157 1.1 joff sc->sc_fclk = fclk;
158 1.1 joff sc->sc_hclk = hclk;
159 1.1 joff sc->sc_pclk = pclk;
160 1.1 joff
161 1.1 joff /* get busdma tag for the platform */
162 1.1 joff sc->sc_dmat = ep93xx_bus_dma_init(&ep93xx_bus_dma);
163 1.1 joff
164 1.1 joff /*
165 1.1 joff * Attach each devices
166 1.1 joff */
167 1.1 joff config_search(epsoc_search, self, NULL);
168 1.1 joff
169 1.1 joff }
170 1.1 joff
171 1.1 joff int
172 1.1 joff epsoc_search(parent, cf, aux)
173 1.1 joff struct device *parent;
174 1.1 joff struct cfdata *cf;
175 1.1 joff void *aux;
176 1.1 joff {
177 1.1 joff struct epsoc_softc *sc = (struct epsoc_softc *)parent;
178 1.1 joff struct epsoc_attach_args sa;
179 1.1 joff
180 1.1 joff sa.sa_iot = sc->sc_iot;
181 1.1 joff sa.sa_dmat = sc->sc_dmat;
182 1.1 joff sa.sa_addr = cf->cf_loc[EPSOCCF_ADDR];
183 1.1 joff sa.sa_size = cf->cf_loc[EPSOCCF_SIZE];
184 1.1 joff sa.sa_intr = cf->cf_loc[EPSOCCF_INTR];
185 1.1 joff sa.sa_hclk = sc->sc_hclk;
186 1.1 joff sa.sa_pclk = sc->sc_pclk;
187 1.1 joff
188 1.1 joff if (config_match(parent, cf, &sa) > 0)
189 1.1 joff config_attach(parent, cf, &sa, epsoc_print);
190 1.1 joff
191 1.1 joff return (0);
192 1.1 joff }
193 1.1 joff
194 1.1 joff static int
195 1.1 joff epsoc_print(aux, name)
196 1.1 joff void *aux;
197 1.1 joff const char *name;
198 1.1 joff {
199 1.1 joff struct epsoc_attach_args *sa = (struct epsoc_attach_args*)aux;
200 1.1 joff
201 1.1 joff if (sa->sa_size)
202 1.1 joff aprint_normal(" addr 0x%lx", sa->sa_addr);
203 1.1 joff if (sa->sa_size > 1)
204 1.1 joff aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
205 1.1 joff if (sa->sa_intr > 1)
206 1.1 joff aprint_normal(" intr %d", sa->sa_intr);
207 1.1 joff
208 1.1 joff return (UNCONF);
209 1.1 joff }
210