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