11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
2c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov * Copyright 2000, 2007-2008 MontaVista Software Inc.
3c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov * Author: MontaVista Software, Inc. <source@mvista.com
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Updates to 2.6, Pete Popov, Embedded Alley Solutions, Inc.
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  This program is free software; you can redistribute  it and/or modify it
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  under  the terms of  the GNU General  Public License as published by the
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  Free Software Foundation;  either version 2 of the  License, or (at your
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  option) any later version.
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  You should have received a copy of the  GNU General Public License along
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  with this program; if not, write  to the Free Software Foundation, Inc.,
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *  675 Mass Ave, Cambridge, MA 02139, USA.
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
27ce28f94ca5a9ba3cd6bdcc47b52ea1b7a3bd933bSergei Shtylyov
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h>
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/ioport.h>
30a7bcb1ae6094db78b077ae17e92c69de7643014fManuel Lauss#include <linux/jiffies.h>
31efe29c0f34dc3ee3511e46458f335edb7ee50327Pete Popov#include <linux/module.h>
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/mipsregs.h>
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/time.h>
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
3625b31cb118f399e9996ed7a3766b86c69a6bb07eYoichi Yuasa#include <au1000.h>
3725b31cb118f399e9996ed7a3766b86c69a6bb07eYoichi Yuasa
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void __init board_setup(void);
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void set_cpuspec(void);
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
412925aba4223f4532e85f0c6f64584b3e0b2849c3Ralf Baechlevoid __init plat_mem_setup(void)
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
432699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	unsigned long est_freq;
442699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss
452699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	/* determine core clock */
462699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	est_freq = au1xxx_calc_clock();
472699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	est_freq += 5000;    /* round */
482699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	est_freq -= est_freq % 10000;
492699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	printk(KERN_INFO "(PRId %08x) @ %lu.%02lu MHz\n", read_c0_prid(),
502699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss	       est_freq / 1000000, ((est_freq % 1000000) * 100) / 1000000);
512699cdfb765c3b7d77d28ea3bc7d84e486697177Manuel Lauss
52a7bcb1ae6094db78b077ae17e92c69de7643014fManuel Lauss	/* this is faster than wasting cycles trying to approximate it */
53a7bcb1ae6094db78b077ae17e92c69de7643014fManuel Lauss	preset_lpj = (est_freq >> 1) / HZ;
54a7bcb1ae6094db78b077ae17e92c69de7643014fManuel Lauss
55074cf656700ddd1d2bd7f815f78e785418beb898Manuel Lauss	if (au1xxx_cpu_needs_config_od())
56c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov		/* Various early Au1xx0 errata corrected by this */
57c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov		set_c0_config(1 << 19); /* Set Config[OD] */
58c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov	else
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* Clear to obtain best system bus performance */
60c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov		clear_c0_config(1 << 19); /* Clear Config[OD] */
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
620591128066bdfe07e0ef0ab7f877f794d8ba071dManuel Lauss	board_setup();  /* board specific setup */
630591128066bdfe07e0ef0ab7f877f794d8ba071dManuel Lauss
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* IO/MEM resources. */
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	set_io_port_base(0);
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ioport_resource.start = IOPORT_RESOURCE_START;
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	ioport_resource.end = IOPORT_RESOURCE_END;
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	iomem_resource.start = IOMEM_RESOURCE_START;
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	iomem_resource.end = IOMEM_RESOURCE_END;
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
7211b897cf84c37e6522db914793677e933ef311fbManuel Lauss#if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_PCI)
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* This routine should be valid for all Au1x based boards */
74c3455b0efc2b5b1bdc755602f77ce7f43725bf61Maciej W. Rozyckiphys_t __fixup_bigphys_addr(phys_t phys_addr, phys_t size)
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
767517de348663b08a808aff44b5300e817157a568Manuel Lauss	unsigned long start = ALCHEMY_PCI_MEMWIN_START;
777517de348663b08a808aff44b5300e817157a568Manuel Lauss	unsigned long end = ALCHEMY_PCI_MEMWIN_END;
7811b897cf84c37e6522db914793677e933ef311fbManuel Lauss
79c1dcb14ec2ae3c594ce1c2db953004083f2bd4a0Sergei Shtylyov	/* Don't fixup 36-bit addresses */
80722b05a0c1498ef12972bbd5084eded498d75fb4Ralf Baechle	if ((phys_addr >> 32) != 0)
81722b05a0c1498ef12972bbd5084eded498d75fb4Ralf Baechle		return phys_addr;
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8311b897cf84c37e6522db914793677e933ef311fbManuel Lauss	/* Check for PCI memory window */
8411b897cf84c37e6522db914793677e933ef311fbManuel Lauss	if (phys_addr >= start && (phys_addr + size - 1) <= end)
857517de348663b08a808aff44b5300e817157a568Manuel Lauss		return (phys_t)(AU1500_PCI_MEM_PHYS_ADDR + phys_addr);
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* default nop */
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return phys_addr;
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
90efe29c0f34dc3ee3511e46458f335edb7ee50327Pete PopovEXPORT_SYMBOL(__fixup_bigphys_addr);
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
92