ixp425_mem.c revision 266406
10Sstevel@tonic-gate/*	$NetBSD: ixp425_mem.c,v 1.2 2005/12/11 12:16:51 christos Exp $	*/
20Sstevel@tonic-gate
30Sstevel@tonic-gate/*
40Sstevel@tonic-gate * Copyright (c) 2003 Wasabi Systems, Inc.
53066Sjg * All rights reserved.
63066Sjg *
70Sstevel@tonic-gate * Written by Steve C. Woodford for Wasabi Systems, Inc.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
100Sstevel@tonic-gate * modification, are permitted provided that the following conditions
110Sstevel@tonic-gate * are met:
120Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
150Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
160Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
170Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
180Sstevel@tonic-gate *    must display the following acknowledgement:
190Sstevel@tonic-gate *      This product includes software developed for the NetBSD Project by
200Sstevel@tonic-gate *      Wasabi Systems, Inc.
210Sstevel@tonic-gate * 4. The name of Wasabi Systems, Inc. may not be used to endorse
220Sstevel@tonic-gate *    or promote products derived from this software without specific prior
233066Sjg *    written permission.
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
260Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
270Sstevel@tonic-gate * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
280Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
290Sstevel@tonic-gate * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
300Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
310Sstevel@tonic-gate * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
320Sstevel@tonic-gate * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
330Sstevel@tonic-gate * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
340Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
350Sstevel@tonic-gate * POSSIBILITY OF SUCH DAMAGE.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate
380Sstevel@tonic-gate#include <sys/cdefs.h>
390Sstevel@tonic-gate__FBSDID("$FreeBSD: stable/10/sys/arm/xscale/ixp425/ixp425_mem.c 266406 2014-05-18 16:07:35Z ian $");
400Sstevel@tonic-gate
410Sstevel@tonic-gate#include <sys/param.h>
420Sstevel@tonic-gate#include <sys/systm.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate#include <arm/xscale/ixp425/ixp425reg.h>
450Sstevel@tonic-gate#include <arm/xscale/ixp425/ixp425var.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gatestatic uint32_t sdram_64bit[] = {
480Sstevel@tonic-gate	0x00800000,	/* 8M:  One 2M x 32 chip */
490Sstevel@tonic-gate	0x01000000,	/* 16M: Two 2M x 32 chips */
500Sstevel@tonic-gate	0x01000000,	/* 16M: Two 4M x 16 chips */
510Sstevel@tonic-gate	0x02000000,	/* 32M: Four 4M x 32 chips */
520Sstevel@tonic-gate	0, 0, 0, 0
530Sstevel@tonic-gate};
540Sstevel@tonic-gate
550Sstevel@tonic-gatestatic uint32_t sdram_other[] = {
560Sstevel@tonic-gate	0x02000000,	/*  32M: Two   8M x 16 chips */
570Sstevel@tonic-gate	0x04000000,	/*  64M: Four  8M x 16 chips */
580Sstevel@tonic-gate	0x04000000,	/*  64M: Two  16M x 16 chips */
590Sstevel@tonic-gate	0x08000000,	/* 128M: Four 16M x 16 chips */
600Sstevel@tonic-gate	0x08000000,	/* 128M: Two  32M x 16 chips */
610Sstevel@tonic-gate	0x10000000,	/* 256M: Four 32M x 16 chips */
620Sstevel@tonic-gate	0, 0
630Sstevel@tonic-gate};
640Sstevel@tonic-gate
650Sstevel@tonic-gateuint32_t
660Sstevel@tonic-gateixp425_sdram_size(void)
670Sstevel@tonic-gate{
680Sstevel@tonic-gate#define MCU_REG_READ(x)	(*(volatile uint32_t *)(IXP425_MCU_VBASE + (x)))
690Sstevel@tonic-gate	uint32_t size, sdr_config;
700Sstevel@tonic-gate
710Sstevel@tonic-gate	sdr_config = MCU_REG_READ(MCU_SDR_CONFIG);
720Sstevel@tonic-gate
733066Sjg	if (sdr_config & MCU_SDR_CONFIG_64MBIT)
743066Sjg		size = sdram_64bit[MCU_SDR_CONFIG_MCONF(sdr_config)];
753066Sjg	else
763066Sjg		size = sdram_other[MCU_SDR_CONFIG_MCONF(sdr_config)];
773066Sjg
783066Sjg	if (size == 0) {
793066Sjg		printf("** SDR_CONFIG returns unknown value, using 32M\n");
803066Sjg		size = 32 * 1024 * 1024;
810Sstevel@tonic-gate	}
820Sstevel@tonic-gate
830Sstevel@tonic-gate	return (size);
840Sstevel@tonic-gate#undef MCU_REG_READ
850Sstevel@tonic-gate}
860Sstevel@tonic-gate
870Sstevel@tonic-gateuint32_t
880Sstevel@tonic-gateixp435_ddram_size(void)
890Sstevel@tonic-gate{
900Sstevel@tonic-gate#define MCU_REG_READ(x)	(*(volatile uint32_t *)(IXP425_MCU_VBASE + (x)))
910Sstevel@tonic-gate	uint32_t sbr0;
920Sstevel@tonic-gate
930Sstevel@tonic-gate	/*
940Sstevel@tonic-gate	 * Table 198, page 516 shows DDR-I/II SDRAM bank sizes
950Sstevel@tonic-gate	 * for SBR0 and SBR1.  The manual states both banks must
960Sstevel@tonic-gate	 * be programmed to be the same size.  We just assume
970Sstevel@tonic-gate	 * it's done right and calculate 2x for the memory size.
980Sstevel@tonic-gate	 */
990Sstevel@tonic-gate	sbr0 = MCU_REG_READ(MCU_DDR_SBR0);
1000Sstevel@tonic-gate	return 2 * 16*(sbr0 & 0x7f) * 1024 * 1024;
1010Sstevel@tonic-gate#undef MCU_REG_READ
1020Sstevel@tonic-gate}
1030Sstevel@tonic-gate