No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / ep93xx / epsoc.c
blob3b26bf0709307496a03250f96729c9c9d0b6b4ae
1 /* $NetBSD: epsoc.c,v 1.9 2009/03/14 15:36:01 dsl Exp $ */
3 /*
4 * Copyright (c) 2004 Jesse Off
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: epsoc.c,v 1.9 2009/03/14 15:36:01 dsl Exp $");
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/time.h>
37 #include <sys/device.h>
39 #include <machine/bus.h>
40 #include <machine/intr.h>
42 #include <arm/cpufunc.h>
44 #include <arm/ep93xx/ep93xxreg.h>
45 #include <arm/ep93xx/ep93xxvar.h>
46 #include <arm/ep93xx/epsocvar.h>
48 #include "locators.h"
50 static int epsoc_match(struct device *, struct cfdata *, void *);
51 static void epsoc_attach(struct device *, struct device *, void *);
52 static int epsoc_search(struct device *, struct cfdata *,
53 const int *, void *);
54 static int epsoc_print(void *, const char *);
55 static int epsoc_submatch(struct device *, struct cfdata *,
56 const int *, void *);
58 CFATTACH_DECL(epsoc, sizeof(struct epsoc_softc),
59 epsoc_match, epsoc_attach, NULL, NULL);
61 struct epsoc_softc *epsoc_sc = NULL;
63 static int
64 epsoc_match(struct device *parent, struct cfdata *match, void *aux)
66 bus_space_handle_t ioh;
67 u_int32_t id, ret = 0;
69 bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
70 EP93XX_APB_SYSCON_SIZE, 0, &ioh);
71 id = bus_space_read_4(&ep93xx_bs_tag, ioh, EP93XX_SYSCON_ChipID);
72 if ((id & 0x01faffff) == 0x9213) ret = 1;
73 bus_space_unmap(&ep93xx_bs_tag, ioh, EP93XX_APB_SYSCON_SIZE);
74 return ret;
77 static void
78 epsoc_attach(struct device *parent, struct device *self, void *aux)
80 struct epsoc_softc *sc;
81 u_int64_t fclk, pclk, hclk;
82 u_int32_t id, clkset1;
83 const char *rev;
84 int locs[EPSOCCF_NLOCS];
85 struct epsoc_attach_args sa;
87 sc = (struct epsoc_softc*) self;
89 if (epsoc_sc == NULL)
90 epsoc_sc = sc;
92 sc->sc_iot = &ep93xx_bs_tag;
93 bus_space_map(sc->sc_iot, EP93XX_APB_HWBASE + EP93XX_APB_SYSCON,
94 EP93XX_APB_SYSCON_SIZE, 0, &sc->sc_ioh);
95 id = bus_space_read_4(sc->sc_iot, sc->sc_ioh, EP93XX_SYSCON_ChipID);
96 switch(id >> 28) {
97 case 0:
98 rev = "A";
99 break;
100 case 1:
101 rev = "B";
102 break;
103 case 2:
104 rev = "C";
105 break;
106 case 3:
107 rev = "D0";
108 break;
109 case 4:
110 rev = "D1";
111 break;
112 case 5:
113 rev = "E0";
114 break;
115 case 6:
116 rev = "E1";
117 break;
118 default:
119 rev = ">E1";
120 break;
122 printf(": Cirrus Logic EP93xx SoC rev %s\n", rev);
124 clkset1 = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
125 EP93XX_SYSCON_ClkSet1);
127 int fclkdiv, hclkdiv, pclkdiv, pll1_ps;
128 int pll1x1fbd1, pll1x2fbd2, pll1x2ipd;
129 int hclkdivisors[] = {1, 2, 4, 5, 6, 8, 16, 32};
131 fclkdiv = (clkset1 & 0x0e000000) >> 25;
132 hclkdiv = (clkset1 & 0x00700000) >> 20;
133 pclkdiv = (clkset1 & 0x000c0000) >> 18;
134 pll1_ps = (clkset1 & 0x00030000) >> 16;
135 pll1x1fbd1 = (clkset1 & 0x0000f800) >> 11;
136 pll1x2fbd2 = (clkset1 & 0x000007e0) >> 5;
137 pll1x2ipd = (clkset1 & 0x0000001f);
138 fclk = 14745600ULL * ((pll1x1fbd1 + 1) * (pll1x2fbd2 + 1)) /
139 ((pll1x2ipd + 1) * (1 << pll1_ps));
140 hclk = fclk / hclkdivisors[hclkdiv];
141 pclk = hclk >> pclkdiv;
142 if (fclkdiv > 4) fclkdiv = 0;
143 if (clkset1 & 0x00800000) /* nBYP1 bypasses PLL */
144 fclk = fclk >> fclkdiv;
145 else
146 fclk = 14745600ULL;
148 printf("%s: fclk %lld.%02lld MHz hclk %lld.%02lld MHz pclk %lld.%02lld MHz\n",
149 sc->sc_dev.dv_xname,
150 fclk / 1000000, (fclk % 1000000 + 5000) / 10000,
151 hclk / 1000000, (hclk % 1000000 + 5000) / 10000,
152 pclk / 1000000, (pclk % 1000000 + 5000) / 10000);
154 sc->sc_fclk = fclk;
155 sc->sc_hclk = hclk;
156 sc->sc_pclk = pclk;
158 /* get busdma tag for the platform */
159 sc->sc_dmat = ep93xx_bus_dma_init(&ep93xx_bus_dma);
162 * Attach each devices
163 * some device is used by other system device. so attach first.
165 sa.sa_iot = sc->sc_iot;
166 sa.sa_dmat = sc->sc_dmat;
167 sa.sa_hclk = sc->sc_hclk;
168 sa.sa_pclk = sc->sc_pclk;
169 locs[EPSOCCF_ADDR] = EP93XX_APB_HWBASE + EP93XX_APB_TIMERS;
170 config_found_sm_loc(self, "epsoc", locs, &sa,
171 epsoc_print, epsoc_submatch);
172 locs[EPSOCCF_ADDR] = EP93XX_APB_HWBASE + EP93XX_APB_GPIO;
173 sa.sa_gpio = (struct epgpio_softc *)
174 config_found_sm_loc(self, "epsoc", locs, &sa,
175 epsoc_print, epsoc_submatch);
176 config_search_ia(epsoc_search, self, "epsoc", &sa);
181 epsoc_submatch(struct device *parent, struct cfdata *cf, const int *ldesc, void *aux)
183 struct epsoc_attach_args *sa = aux;
185 if (cf->cf_loc[EPSOCCF_ADDR] == ldesc[EPSOCCF_ADDR]) {
186 sa->sa_addr = cf->cf_loc[EPSOCCF_ADDR];
187 sa->sa_size = cf->cf_loc[EPSOCCF_SIZE];
188 sa->sa_intr = cf->cf_loc[EPSOCCF_INTR];
189 return (config_match(parent, cf, aux));
190 } else
191 return (0);
195 epsoc_search(struct device *parent, struct cfdata *cf, const int *ldesc, void *aux)
197 struct epsoc_attach_args *sa = aux;
199 sa->sa_addr = cf->cf_loc[EPSOCCF_ADDR];
200 sa->sa_size = cf->cf_loc[EPSOCCF_SIZE];
201 sa->sa_intr = cf->cf_loc[EPSOCCF_INTR];
203 if (config_match(parent, cf, aux) > 0)
204 config_attach(parent, cf, aux, epsoc_print);
206 return (0);
209 static int
210 epsoc_print(void *aux, const char *name)
212 struct epsoc_attach_args *sa = (struct epsoc_attach_args*)aux;
214 if (sa->sa_size)
215 aprint_normal(" addr 0x%lx", sa->sa_addr);
216 if (sa->sa_size > 1)
217 aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
218 if (sa->sa_intr > 1)
219 aprint_normal(" intr %d", sa->sa_intr);
221 return (UNCONF);