11.1Sthorpej/*	$NetBSD: ixp425_mem.c,v 1.1 2020/02/12 06:57:35 thorpej Exp $	*/
21.1Sthorpej
31.1Sthorpej/*
41.1Sthorpej * Copyright (c) 2003 Wasabi Systems, Inc.
51.1Sthorpej * All rights reserved.
61.1Sthorpej *
71.1Sthorpej * Written by Steve C. Woodford for Wasabi Systems, Inc.
81.1Sthorpej *
91.1Sthorpej * Redistribution and use in source and binary forms, with or without
101.1Sthorpej * modification, are permitted provided that the following conditions
111.1Sthorpej * are met:
121.1Sthorpej * 1. Redistributions of source code must retain the above copyright
131.1Sthorpej *    notice, this list of conditions and the following disclaimer.
141.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
151.1Sthorpej *    notice, this list of conditions and the following disclaimer in the
161.1Sthorpej *    documentation and/or other materials provided with the distribution.
171.1Sthorpej * 3. All advertising materials mentioning features or use of this software
181.1Sthorpej *    must display the following acknowledgement:
191.1Sthorpej *	This product includes software developed for the NetBSD Project by
201.1Sthorpej *	Wasabi Systems, Inc.
211.1Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Sthorpej *    or promote products derived from this software without specific prior
231.1Sthorpej *    written permission.
241.1Sthorpej *
251.1Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Sthorpej * POSSIBILITY OF SUCH DAMAGE.
361.1Sthorpej */
371.1Sthorpej
381.1Sthorpej/*
391.1Sthorpej * This file provides the mem_init() function for boards using the
401.1Sthorpej * Intel IXP425 Network Processor.
411.1Sthorpej */
421.1Sthorpej
431.1Sthorpej#include <sys/types.h>
441.1Sthorpej#include <lib/libsa/stand.h>
451.1Sthorpej
461.1Sthorpej#include <arm/xscale/ixp425reg.h>
471.1Sthorpej
481.1Sthorpej#include "board.h"
491.1Sthorpej
501.1Sthorpej#define	MCU_REG_READ(x)	(*(volatile uint32_t *)(IXP425_MCU_HWBASE + (x)))
511.1Sthorpej
521.1Sthorpejstatic const uint32_t sdram_64bit[] = {
531.1Sthorpej	0x00800000,	/* 8M:  One 2M x 32 chip */
541.1Sthorpej	0x01000000,	/* 16M: Two 2M x 32 chips */
551.1Sthorpej	0x01000000,	/* 16M: One 4M x 32 chip */
561.1Sthorpej	0x02000000,	/* 32M: Two 4M x 32 chips */
571.1Sthorpej	0, 0, 0, 0
581.1Sthorpej};
591.1Sthorpej
601.1Sthorpejstatic const uint32_t sdram_other[] = {
611.1Sthorpej	0x02000000,	/*  32M: Two   8M x 16 chips */
621.1Sthorpej	0x04000000,	/*  64M: Four  8M x 16 chips */
631.1Sthorpej	0x04000000,	/*  64M: Two  16M x 16 chips */
641.1Sthorpej	0x08000000,	/* 128M: Four 16M x 16 chips */
651.1Sthorpej	0x08000000,	/* 128M: Two  32M x 16 chips */
661.1Sthorpej	0x10000000,	/* 256M: Four 32M x 16 chips */
671.1Sthorpej	0, 0
681.1Sthorpej};
691.1Sthorpej
701.1Sthorpejvoid
711.1Sthorpejmem_init(void)
721.1Sthorpej{
731.1Sthorpej	uint32_t sdr_config;
741.1Sthorpej	uint32_t start, size, heap;
751.1Sthorpej
761.1Sthorpej	sdr_config = MCU_REG_READ(MCU_SDR_CONFIG);
771.1Sthorpej
781.1Sthorpej	start = 0x00000000;		/* fixed SDRAM base address */
791.1Sthorpej
801.1Sthorpej	if (sdr_config & MCU_SDR_CONFIG_64MBIT)
811.1Sthorpej		size = sdram_64bit[MCU_SDR_CONFIG_MCONF(sdr_config)];
821.1Sthorpej	else
831.1Sthorpej		size = sdram_other[MCU_SDR_CONFIG_MCONF(sdr_config)];
841.1Sthorpej
851.1Sthorpej	if (size == 0) {
861.1Sthorpej		printf("** SDR_CONFIG returns unknown value, using 32M\n");
871.1Sthorpej		size = 32 * 1024 * 1024;
881.1Sthorpej	}
891.1Sthorpej
901.1Sthorpej	heap = (start + size) - BOARD_HEAP_SIZE;
911.1Sthorpej
921.1Sthorpej	printf(">> RAM 0x%x - 0x%x, heap at 0x%x\n",
931.1Sthorpej	    start, (start + size) - 1, heap);
941.1Sthorpej	setheap((void *)heap, (void *)(start + size - 1));
951.1Sthorpej}
96