ixp425_mem.c revision 164426
1164426Ssam/*	$NetBSD: ixp425_mem.c,v 1.2 2005/12/11 12:16:51 christos Exp $	*/
2164426Ssam
3164426Ssam/*
4164426Ssam * Copyright (c) 2003 Wasabi Systems, Inc.
5164426Ssam * All rights reserved.
6164426Ssam *
7164426Ssam * Written by Steve C. Woodford for Wasabi Systems, Inc.
8164426Ssam *
9164426Ssam * Redistribution and use in source and binary forms, with or without
10164426Ssam * modification, are permitted provided that the following conditions
11164426Ssam * are met:
12164426Ssam * 1. Redistributions of source code must retain the above copyright
13164426Ssam *    notice, this list of conditions and the following disclaimer.
14164426Ssam * 2. Redistributions in binary form must reproduce the above copyright
15164426Ssam *    notice, this list of conditions and the following disclaimer in the
16164426Ssam *    documentation and/or other materials provided with the distribution.
17164426Ssam * 3. All advertising materials mentioning features or use of this software
18164426Ssam *    must display the following acknowledgement:
19164426Ssam *      This product includes software developed for the NetBSD Project by
20164426Ssam *      Wasabi Systems, Inc.
21164426Ssam * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22164426Ssam *    or promote products derived from this software without specific prior
23164426Ssam *    written permission.
24164426Ssam *
25164426Ssam * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26164426Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27164426Ssam * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28164426Ssam * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29164426Ssam * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30164426Ssam * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31164426Ssam * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32164426Ssam * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33164426Ssam * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34164426Ssam * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35164426Ssam * POSSIBILITY OF SUCH DAMAGE.
36164426Ssam */
37164426Ssam
38164426Ssam#include <sys/cdefs.h>
39164426Ssam__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/ixp425_mem.c 164426 2006-11-19 23:55:23Z sam $");
40164426Ssam
41164426Ssam#include <sys/param.h>
42164426Ssam#include <sys/systm.h>
43164426Ssam
44164426Ssam#include <arm/xscale/ixp425/ixp425reg.h>
45164426Ssam#include <arm/xscale/ixp425/ixp425var.h>
46164426Ssam
47164426Ssamstatic uint32_t sdram_64bit[] = {
48164426Ssam	0x00800000,	/* 8M:  One 2M x 32 chip */
49164426Ssam	0x01000000,	/* 16M: Two 2M x 32 chips */
50164426Ssam	0x01000000,	/* 16M: One 4M x 32 chip */
51164426Ssam	0x02000000,	/* 32M: Two 4M x 32 chips */
52164426Ssam	0, 0, 0, 0
53164426Ssam};
54164426Ssam
55164426Ssamstatic uint32_t sdram_other[] = {
56164426Ssam	0x02000000,	/*  32M: Two   8M x 16 chips */
57164426Ssam	0x04000000,	/*  64M: Four  8M x 16 chips */
58164426Ssam	0x04000000,	/*  64M: Two  16M x 16 chips */
59164426Ssam	0x08000000,	/* 128M: Four 16M x 16 chips */
60164426Ssam	0x08000000,	/* 128M: Two  32M x 16 chips */
61164426Ssam	0x10000000,	/* 256M: Four 32M x 16 chips */
62164426Ssam	0, 0
63164426Ssam};
64164426Ssam
65164426Ssam#define MCU_REG_READ(x)	(*(volatile uint32_t *)(IXP425_MCU_VBASE + (x)))
66164426Ssam
67164426Ssamuint32_t
68164426Ssamixp425_sdram_size(void)
69164426Ssam{
70164426Ssam	uint32_t size, sdr_config;
71164426Ssam
72164426Ssam	sdr_config = MCU_REG_READ(MCU_SDR_CONFIG);
73164426Ssam
74164426Ssam	if (sdr_config & MCU_SDR_CONFIG_64MBIT)
75164426Ssam		size = sdram_64bit[MCU_SDR_CONFIG_MCONF(sdr_config)];
76164426Ssam	else
77164426Ssam		size = sdram_other[MCU_SDR_CONFIG_MCONF(sdr_config)];
78164426Ssam
79164426Ssam	if (size == 0) {
80164426Ssam		printf("** SDR_CONFIG retuns unknown value, using 32M\n");
81164426Ssam		size = 32 * 1024 * 1024;
82164426Ssam	}
83164426Ssam
84164426Ssam	return (size);
85164426Ssam}
86