epsoc.c revision 1.4 1 /* $NetBSD: epsoc.c,v 1.4 2005/08/26 13:19:34 drochner 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.4 2005/08/26 13:19:34 drochner 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 *,
60 const int *, void *);
61 static int epsoc_print(void *, const char *);
62
63 CFATTACH_DECL(epsoc, sizeof(struct epsoc_softc),
64 epsoc_match, epsoc_attach, NULL, NULL);
65
66 struct epsoc_softc *epsoc_sc = NULL;
67
68 static int
69 epsoc_match(struct device *parent, struct cfdata *match, void *aux)
70 {
71 bus_space_handle_t ioh;
72 u_int32_t id, ret = 0;
73
74 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
75 EP93XX_APB_SYSCON_SIZE, 0, &ioh);
76 id = bus_space_read_4(&ep93xx_bs_tag, ioh, EP93XX_SYSCON_ChipID);
77 if ((id & 0x01faffff) == 0x9213) ret = 1;
78 bus_space_unmap(&ep93xx_bs_tag, ioh, EP93XX_APB_SYSCON_SIZE);
79 return ret;
80 }
81
82 static void
83 epsoc_attach(struct device *parent, struct device *self, void *aux)
84 {
85 struct epsoc_softc *sc;
86 u_int64_t fclk, pclk, hclk;
87 u_int32_t id, clkset1;
88 const char *rev;
89
90
91 sc = (struct epsoc_softc*) self;
92
93 if (epsoc_sc == NULL)
94 epsoc_sc = sc;
95
96 sc->sc_iot = &ep93xx_bs_tag;
97 bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
98 EP93XX_APB_SYSCON_SIZE, 0, &sc->sc_ioh);
99 id = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_SYSCON_ChipID);
100 switch(id >> 28) {
101 case 0:
102 rev = "A";
103 break;
104 case 1:
105 rev = "B";
106 break;
107 case 2:
108 rev = "C";
109 break;
110 case 3:
111 rev = "D0";
112 break;
113 case 4:
114 rev = "D1";
115 break;
116 case 5:
117 rev = "E0";
118 break;
119 case 6:
120 rev = "E1";
121 break;
122 default:
123 rev = ">E1";
124 break;
125 }
126 printf(": Cirrus Logic EP93xx SoC rev %s\n", rev);
127
128 clkset1 = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
129 EP93XX_SYSCON_ClkSet1);
130 {
131 int fclkdiv, hclkdiv, pclkdiv, pll1_ps;
132 int pll1x1fbd1, pll1x2fbd2, pll1x2ipd;
133 int hclkdivisors[] = {1, 2, 4, 5, 6, 8, 16, 32};
134
135 fclkdiv = (clkset1 & 0x0e000000) >> 25;
136 hclkdiv = (clkset1 & 0x00700000) >> 20;
137 pclkdiv = (clkset1 & 0x000c0000) >> 18;
138 pll1_ps = (clkset1 & 0x00030000) >> 16;
139 pll1x1fbd1 = (clkset1 & 0x0000f800) >> 11;
140 pll1x2fbd2 = (clkset1 & 0x000007e0) >> 5;
141 pll1x2ipd = (clkset1 & 0x0000001f);
142 fclk = 14745600ULL * ((pll1x1fbd1 + 1) * (pll1x2fbd2 + 1)) /
143 ((pll1x2ipd + 1) * (1 << pll1_ps));
144 hclk = fclk / hclkdivisors[hclkdiv];
145 pclk = hclk >> pclkdiv;
146 if (fclkdiv > 4) fclkdiv = 0;
147 if (clkset1 & 0x00800000) /* nBYP1 bypasses PLL */
148 fclk = fclk >> fclkdiv;
149 else
150 fclk = 14745600ULL;
151 }
152 printf("%s: fclk %lld.%02lld Mhz hclk %lld.%02lld Mhz pclk %lld.%02lld Mhz\n",
153 sc->sc_dev.dv_xname,
154 fclk / 1000000, (fclk % 1000000 + 5000) / 10000,
155 hclk / 1000000, (hclk % 1000000 + 5000) / 10000,
156 pclk / 1000000, (pclk % 1000000 + 5000) / 10000);
157
158 sc->sc_fclk = fclk;
159 sc->sc_hclk = hclk;
160 sc->sc_pclk = pclk;
161
162 /* get busdma tag for the platform */
163 sc->sc_dmat = ep93xx_bus_dma_init(&ep93xx_bus_dma);
164
165 /*
166 * Attach each devices
167 */
168 config_search_ia(epsoc_search, self, "epsoc", NULL);
169
170 }
171
172 int
173 epsoc_search(parent, cf, ldesc, aux)
174 struct device *parent;
175 struct cfdata *cf;
176 const int *ldesc;
177 void *aux;
178 {
179 struct epsoc_softc *sc = (struct epsoc_softc *)parent;
180 struct epsoc_attach_args sa;
181
182 sa.sa_iot = sc->sc_iot;
183 sa.sa_dmat = sc->sc_dmat;
184 sa.sa_addr = cf->cf_loc[EPSOCCF_ADDR];
185 sa.sa_size = cf->cf_loc[EPSOCCF_SIZE];
186 sa.sa_intr = cf->cf_loc[EPSOCCF_INTR];
187 sa.sa_hclk = sc->sc_hclk;
188 sa.sa_pclk = sc->sc_pclk;
189
190 if (config_match(parent, cf, &sa) > 0)
191 config_attach(parent, cf, &sa, epsoc_print);
192
193 return (0);
194 }
195
196 static int
197 epsoc_print(aux, name)
198 void *aux;
199 const char *name;
200 {
201 struct epsoc_attach_args *sa = (struct epsoc_attach_args*)aux;
202
203 if (sa->sa_size)
204 aprint_normal(" addr 0x%lx", sa->sa_addr);
205 if (sa->sa_size > 1)
206 aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
207 if (sa->sa_intr > 1)
208 aprint_normal(" intr %d", sa->sa_intr);
209
210 return (UNCONF);
211 }
212