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$"); 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 */ 50166248Skevlo 0x01000000, /* 16M: Two 4M x 16 chips */ 51166248Skevlo 0x02000000, /* 32M: Four 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 65164426Ssamuint32_t 66164426Ssamixp425_sdram_size(void) 67164426Ssam{ 68186352Ssam#define MCU_REG_READ(x) (*(volatile uint32_t *)(IXP425_MCU_VBASE + (x))) 69164426Ssam uint32_t size, sdr_config; 70164426Ssam 71164426Ssam sdr_config = MCU_REG_READ(MCU_SDR_CONFIG); 72164426Ssam 73164426Ssam if (sdr_config & MCU_SDR_CONFIG_64MBIT) 74164426Ssam size = sdram_64bit[MCU_SDR_CONFIG_MCONF(sdr_config)]; 75164426Ssam else 76164426Ssam size = sdram_other[MCU_SDR_CONFIG_MCONF(sdr_config)]; 77164426Ssam 78164426Ssam if (size == 0) { 79164426Ssam printf("** SDR_CONFIG retuns unknown value, using 32M\n"); 80164426Ssam size = 32 * 1024 * 1024; 81164426Ssam } 82164426Ssam 83164426Ssam return (size); 84186352Ssam#undef MCU_REG_READ 85164426Ssam} 86186352Ssam 87186352Ssamuint32_t 88186352Ssamixp435_ddram_size(void) 89186352Ssam{ 90186352Ssam#define MCU_REG_READ(x) (*(volatile uint32_t *)(IXP425_MCU_VBASE + (x))) 91186352Ssam uint32_t sbr0; 92186352Ssam 93186352Ssam /* 94186352Ssam * Table 198, page 516 shows DDR-I/II SDRAM bank sizes 95186352Ssam * for SBR0 and SBR1. The manual states both banks must 96186352Ssam * be programmed to be the same size. We just assume 97186352Ssam * it's done right and calculate 2x for the memory size. 98186352Ssam */ 99186352Ssam sbr0 = MCU_REG_READ(MCU_DDR_SBR0); 100186352Ssam return 2 * 16*(sbr0 & 0x7f) * 1024 * 1024; 101186352Ssam#undef MCU_REG_READ 102186352Ssam} 103