Annotation of sys/arch/arm/sa11x0/sa11x0.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: pxa2x0.c,v 1.11 2005/11/11 23:59:58 deraadt Exp $ */
2: /* $NetBSD: pxa2x0.c,v 1.5 2003/12/12 16:42:44 thorpej Exp $ */
3:
4: /*
5: * Copyright (c) 2002 Genetec Corporation. All rights reserved.
6: * Written by Hiroyuki Bessho for Genetec Corporation.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed for the NetBSD Project by
19: * Genetec Corporation.
20: * 4. The name of Genetec Corporation may not be used to endorse or
21: * promote products derived from this software without specific prior
22: * written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
28: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34: * POSSIBILITY OF SUCH DAMAGE.
35: *
36: *
37: * Autoconfiguration support for the Intel PXA2[15]0 application
38: * processor. This code is derived from arm/sa11x0/sa11x0.c
39: */
40:
41: /*-
42: * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
43: *
44: * This code is derived from software contributed to The NetBSD Foundation
45: * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
46: *
47: * Redistribution and use in source and binary forms, with or without
48: * modification, are permitted provided that the following conditions
49: * are met:
50: * 1. Redistributions of source code must retain the above copyright
51: * notice, this list of conditions and the following disclaimer.
52: * 2. Redistributions in binary form must reproduce the above copyright
53: * notice, this list of conditions and the following disclaimer in the
54: * documentation and/or other materials provided with the distribution.
55: * 3. All advertising materials mentioning features or use of this software
56: * must display the following acknowledgement:
57: * This product includes software developed by the NetBSD
58: * Foundation, Inc. and its contributors.
59: * 4. Neither the name of The NetBSD Foundation nor the names of its
60: * contributors may be used to endorse or promote products derived
61: * from this software without specific prior written permission.
62: */
63: /*-
64: * Copyright (c) 1999
65: * Shin Takemura and PocketBSD Project. All rights reserved.
66: *
67: * Redistribution and use in source and binary forms, with or without
68: * modification, are permitted provided that the following conditions
69: * are met:
70: * 1. Redistributions of source code must retain the above copyright
71: * notice, this list of conditions and the following disclaimer.
72: * 2. Redistributions in binary form must reproduce the above copyright
73: * notice, this list of conditions and the following disclaimer in the
74: * documentation and/or other materials provided with the distribution.
75: * 3. All advertising materials mentioning features or use of this software
76: * must display the following acknowledgement:
77: * This product includes software developed by the PocketBSD project
78: * and its contributors.
79: * 4. Neither the name of the project nor the names of its contributors
80: * may be used to endorse or promote products derived from this software
81: * without specific prior written permission.
82: *
83: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
84: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
85: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
86: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
87: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
88: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
89: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
90: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
91: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
92: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93: * SUCH DAMAGE.
94: *
95: */
96:
97: #include <sys/cdefs.h>
98: /*
99: __KERNEL_RCSID(0, "$NetBSD: pxa2x0.c,v 1.5 2003/12/12 16:42:44 thorpej Exp $");
100: */
101:
102: //#include "saic.h"
103: //#include "sagpio.h"
104: //#include "sadmac.h"
105:
106: #include <sys/param.h>
107: #include <sys/systm.h>
108: #include <sys/device.h>
109: #include <sys/kernel.h>
110: #include <sys/reboot.h>
111:
112: #include <machine/cpu.h>
113: #include <machine/bus.h>
114:
115: #include <arm/cpufunc.h>
116: #include <arm/mainbus/mainbus.h>
117: #include <arm/sa11x0/sa11x0_reg.h>
118: #include <arm/sa11x0/sa11x0_var.h>
119:
120: struct saip_softc {
121: struct device sc_dev;
122: bus_space_tag_t sc_bust;
123: bus_dma_tag_t sc_dmat;
124: // bus_space_handle_t sc_bush_clk;
125: bus_space_handle_t sc_bush_rtc;
126: };
127:
128: /* prototypes */
129: int saip_match(struct device *, void *, void *);
130: void saip_attach(struct device *, struct device *, void *);
131: int saip_search(struct device *, void *, void *);
132: void saip_attach_critical(struct saip_softc *);
133: int saip_print(void *, const char *);
134:
135: //int saip_measure_cpuclock(struct saip_softc *);
136: extern volatile struct timeval time;
137:
138: /* attach structures */
139: struct cfattach saip_ca = {
140: sizeof(struct saip_softc), saip_match, saip_attach
141: };
142:
143: struct cfdriver saip_cd = {
144: NULL, "saip", DV_DULL
145: };
146:
147: struct saip_softc *saip_sc;
148:
149: int
150: saip_match(struct device *parent, void *match, void *aux)
151: {
152:
153: return 1;
154: }
155:
156: void
157: saip_attach(struct device *parent, struct device *self, void *aux)
158: {
159: struct saip_softc *sc = (struct saip_softc *)self;
160: extern struct arm32_bus_dma_tag sa11x0_bus_dma_tag;
161:
162: saip_sc = sc;
163: sc->sc_bust = &sa11x0_bs_tag;
164: sc->sc_dmat = &sa11x0_bus_dma_tag;
165:
166: if (bus_space_map(sc->sc_bust, SARTC_BASE, 0x20 /* XXX SARTC_SIZE */,
167: 0, &sc->sc_bush_rtc))
168: panic("saip_attach: failed to map RTC");
169:
170: printf("\n");
171:
172: /* TODO: calculate cpu clock */
173:
174: /*
175: * Attach critical devices
176: */
177: saip_attach_critical(sc);
178:
179: /*
180: * Attach all other devices
181: */
182: config_search(saip_search, self, sc);
183:
184: }
185:
186: int
187: saip_search(struct device *parent, void *c, void *aux)
188: {
189: struct saip_softc *sc = aux;
190: struct saip_attach_args aa;
191: struct cfdata *cf = c;
192:
193: aa.sai_iot = sc->sc_bust;
194: aa.sai_dmat = sc->sc_dmat;
195:
196: aa.sai_addr = (cf->cf_loc)[0];
197: aa.sai_size = (cf->cf_loc)[1];
198: aa.sai_intr = (cf->cf_loc)[2];
199: aa.sai_index = (cf->cf_loc)[3];
200:
201: config_found(parent, &aa, saip_print);
202:
203: return 0;
204: }
205:
206: void
207: saip_attach_critical(struct saip_softc *sc)
208: {
209: /*
210: * Attach critical devices.
211: * This includes saic and sadmac.
212: */
213:
214: struct saip_attach_args aa;
215:
216: aa.sai_iot = sc->sc_bust;
217: aa.sai_dmat = sc->sc_dmat;
218: aa.sai_addr = SAIPIC_BASE;
219: aa.sai_size = 0x10 /* XXX SAIPIC_SIZE */;
220: aa.sai_intr = -1;
221: if (config_found(&sc->sc_dev, &aa, saip_print) == NULL)
222: panic("saip_attach_critical: failed to attach INTC!");
223:
224: #if NSADMAC > 0
225: aa.sai_iot = sc->sc_bust;
226: aa.sai_dmat = sc->sc_dmat;
227: aa.sai_addr = SADMAC_BASE;
228: aa.sai_size = 0xc0 /* XXX SADMAC_SIZE */;
229: aa.sai_intr = -1; /* XXX */
230: if (config_found(&sc->sc_dev, &aa, saip_print) == NULL)
231: panic("saip_attach_critical: failed to attach DMAC!");
232: #endif
233: }
234:
235: int
236: saip_print(void *aux, const char *name)
237: {
238: struct saip_attach_args *sa = (struct saip_attach_args*)aux;
239:
240: if (sa->sai_addr != -1) {
241: printf(" addr 0x%lx", sa->sai_addr);
242: if (sa->sai_size > -1)
243: printf("-0x%lx", sa->sai_addr + sa->sai_size-1);
244: }
245: if (sa->sai_intr != -1)
246: printf(" intr %d", sa->sai_intr);
247:
248: return (UNCONF);
249: }
250:
251: # if 0
252: static inline uint32_t
253: read_clock_counter(void)
254: {
255: uint32_t x;
256: __asm __volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (x));
257:
258: return x;
259: }
260:
261: int
262: saip_measure_cpuclock(struct saip_softc *sc)
263: {
264: uint32_t rtc0, rtc1, start, end;
265: uint32_t pmcr_save;
266: bus_space_handle_t ioh;
267: int irq;
268:
269: ioh = sc->sc_bush_rtc;
270: irq = disable_interrupts(I32_bit|F32_bit);
271:
272: __asm __volatile( "mrc p14, 0, %0, c0, c1, 0" : "=r" (pmcr_save));
273: /* Enable clock counter */
274: __asm __volatile( "mcr p14, 0, %0, c0, c1, 0" : : "r" (0x0001));
275:
276: rtc0 = bus_space_read_4(sc->sc_bust, ioh, RTC_RCNR);
277: /* Wait for next second starts */
278: while ((rtc1 = bus_space_read_4(sc->sc_bust, ioh, RTC_RCNR)) == rtc0)
279: ;
280: start = read_clock_counter();
281: while(rtc1 == bus_space_read_4(sc->sc_bust, ioh, RTC_RCNR))
282: ; /* Wait for 1sec */
283: end = read_clock_counter();
284:
285: __asm __volatile( "mcr p14, 0, %0, c0, c1, 0" : : "r" (pmcr_save));
286: restore_interrupts(irq);
287:
288: return end - start;
289: }
290:
291: void
292: pxa2x0_turbo_mode(int f)
293: {
294: __asm __volatile("mcr p14, 0, %0, c6, c0, 0" : : "r" (f));
295: }
296:
297: void
298: pxa2x0_probe_sdram(vaddr_t memctl_va, paddr_t *start, paddr_t *size)
299: {
300: u_int32_t mdcnfg, dwid, dcac, drac, dnb;
301: int i;
302:
303: mdcnfg = *((volatile u_int32_t *)(memctl_va + MEMCTL_MDCNFG));
304:
305: /*
306: * Scan all 4 SDRAM banks
307: */
308: for (i = 0; i < PXA2X0_SDRAM_BANKS; i++) {
309: start[i] = 0;
310: size[i] = 0;
311:
312: switch (i) {
313: case 0:
314: case 1:
315: if ((i == 0 && (mdcnfg & MDCNFG_DE0) == 0) ||
316: (i == 1 && (mdcnfg & MDCNFG_DE1) == 0))
317: continue;
318: dwid = mdcnfg >> MDCNFD_DWID01_SHIFT;
319: dcac = mdcnfg >> MDCNFD_DCAC01_SHIFT;
320: drac = mdcnfg >> MDCNFD_DRAC01_SHIFT;
321: dnb = mdcnfg >> MDCNFD_DNB01_SHIFT;
322: break;
323:
324: case 2:
325: case 3:
326: if ((i == 2 && (mdcnfg & MDCNFG_DE2) == 0) ||
327: (i == 3 && (mdcnfg & MDCNFG_DE3) == 0))
328: continue;
329: dwid = mdcnfg >> MDCNFD_DWID23_SHIFT;
330: dcac = mdcnfg >> MDCNFD_DCAC23_SHIFT;
331: drac = mdcnfg >> MDCNFD_DRAC23_SHIFT;
332: dnb = mdcnfg >> MDCNFD_DNB23_SHIFT;
333: break;
334: default:
335: panic("pxa2x0_probe_sdram: impossible");
336: }
337:
338: dwid = 2 << (1 - (dwid & MDCNFD_DWID_MASK)); /* 16/32 width */
339: dcac = 1 << ((dcac & MDCNFD_DCAC_MASK) + 8); /* 8-11 columns */
340: drac = 1 << ((drac & MDCNFD_DRAC_MASK) + 11); /* 11-13 rows */
341: dnb = 2 << (dnb & MDCNFD_DNB_MASK); /* # of banks */
342:
343: size[i] = (paddr_t)(dwid * dcac * drac * dnb);
344: start[i] = PXA2X0_SDRAM0_START + (i * PXA2X0_SDRAM_BANK_SIZE);
345: }
346: }
347:
348: void
349: pxa2x0_clkman_config(u_int clk, int enable)
350: {
351: struct saip_softc *sc;
352: u_int32_t rv;
353:
354: KDASSERT(saip_sc != NULL);
355: sc = saip_sc;
356:
357: rv = bus_space_read_4(sc->sc_bust, sc->sc_bush_clk, CLKMAN_CKEN);
358: rv &= ~clk;
359:
360: if (enable)
361: rv |= clk;
362:
363: bus_space_write_4(sc->sc_bust, sc->sc_bush_clk, CLKMAN_CKEN, rv);
364: }
365: #endif /* 0 */
366: #if 0
367: void
368: pxa2x0_rtc_setalarm(u_int32_t secs)
369: {
370: struct saip_softc *sc;
371: u_int32_t rv;
372: int s;
373:
374: KDASSERT(saip_sc != NULL);
375: sc = saip_sc;
376:
377: s = splhigh();
378: bus_space_write_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RTAR, secs);
379: rv = bus_space_read_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RTSR);
380: if (secs == 0)
381: bus_space_write_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RTSR,
382: (rv | RTSR_AL) & ~RTSR_ALE);
383: else
384: bus_space_write_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RTSR,
385: (rv | RTSR_AL | RTSR_ALE));
386: splx(s);
387: }
388:
389: u_int32_t
390: pxa2x0_rtc_getalarm(void)
391: {
392: struct saip_softc *sc;
393:
394: KDASSERT(saip_sc != NULL);
395: sc = saip_sc;
396:
397: return (bus_space_read_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RTAR));
398: }
399:
400: u_int32_t
401: pxa2x0_rtc_getsecs(void)
402: {
403: struct saip_softc *sc;
404:
405: KDASSERT(saip_sc != NULL);
406: sc = saip_sc;
407:
408: return (bus_space_read_4(sc->sc_bust, sc->sc_bush_rtc, RTC_RCNR));
409: }
410: #endif /* 0 */
411:
412: void
413: resettodr(void)
414: {
415: struct saip_softc *sc = saip_sc;
416:
417: bus_space_write_4(sc->sc_bust, sc->sc_bush_rtc, SARTC_RCNR,
418: (u_int32_t)time.tv_sec);
419: }
420:
421: void
422: inittodr(time_t base)
423: {
424: struct saip_softc *sc = saip_sc;
425: u_int32_t rcnr;
426:
427: /* XXX decide if RCNR can be valid, based on the last reset
428: * XXX reason, i.e. RCSR. */
429: rcnr = bus_space_read_4(sc->sc_bust, sc->sc_bush_rtc, SARTC_RCNR);
430:
431: /* XXX check how much RCNR differs from the filesystem date. */
432: if (rcnr > base)
433: time.tv_sec = rcnr;
434: else {
435: printf("WARNING: using filesystem date -- CHECK AND RESET THE DATE!\n");
436: time.tv_sec = base;
437: }
438:
439: time.tv_usec = 0;
440: }
CVSweb