162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2000, 2007-2008 MontaVista Software Inc.
362306a36Sopenharmony_ci * Author: MontaVista Software, Inc. <source@mvista.com
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Updates to 2.6, Pete Popov, Embedded Alley Solutions, Inc.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci *  This program is free software; you can redistribute  it and/or modify it
862306a36Sopenharmony_ci *  under  the terms of  the GNU General  Public License as published by the
962306a36Sopenharmony_ci *  Free Software Foundation;  either version 2 of the  License, or (at your
1062306a36Sopenharmony_ci *  option) any later version.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
1362306a36Sopenharmony_ci *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
1462306a36Sopenharmony_ci *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
1562306a36Sopenharmony_ci *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
1662306a36Sopenharmony_ci *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1762306a36Sopenharmony_ci *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
1862306a36Sopenharmony_ci *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1962306a36Sopenharmony_ci *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
2062306a36Sopenharmony_ci *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2162306a36Sopenharmony_ci *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci *  You should have received a copy of the  GNU General Public License along
2462306a36Sopenharmony_ci *  with this program; if not, write  to the Free Software Foundation, Inc.,
2562306a36Sopenharmony_ci *  675 Mass Ave, Cambridge, MA 02139, USA.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#include <linux/init.h>
2962306a36Sopenharmony_ci#include <linux/ioport.h>
3062306a36Sopenharmony_ci#include <linux/mm.h>
3162306a36Sopenharmony_ci#include <linux/dma-map-ops.h> /* for dma_default_coherent */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#include <asm/mipsregs.h>
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#include <au1000.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciextern void __init board_setup(void);
3862306a36Sopenharmony_ciextern void __init alchemy_set_lpj(void);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_cistatic bool alchemy_dma_coherent(void)
4162306a36Sopenharmony_ci{
4262306a36Sopenharmony_ci	switch (alchemy_get_cputype()) {
4362306a36Sopenharmony_ci	case ALCHEMY_CPU_AU1000:
4462306a36Sopenharmony_ci	case ALCHEMY_CPU_AU1500:
4562306a36Sopenharmony_ci	case ALCHEMY_CPU_AU1100:
4662306a36Sopenharmony_ci		return false;
4762306a36Sopenharmony_ci	case ALCHEMY_CPU_AU1200:
4862306a36Sopenharmony_ci		/* Au1200 AB USB does not support coherent memory */
4962306a36Sopenharmony_ci		if ((read_c0_prid() & PRID_REV_MASK) == 0)
5062306a36Sopenharmony_ci			return false;
5162306a36Sopenharmony_ci		return true;
5262306a36Sopenharmony_ci	default:
5362306a36Sopenharmony_ci		return true;
5462306a36Sopenharmony_ci	}
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_civoid __init plat_mem_setup(void)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci	alchemy_set_lpj();
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci	if (au1xxx_cpu_needs_config_od())
6262306a36Sopenharmony_ci		/* Various early Au1xx0 errata corrected by this */
6362306a36Sopenharmony_ci		set_c0_config(1 << 19); /* Set Config[OD] */
6462306a36Sopenharmony_ci	else
6562306a36Sopenharmony_ci		/* Clear to obtain best system bus performance */
6662306a36Sopenharmony_ci		clear_c0_config(1 << 19); /* Clear Config[OD] */
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	dma_default_coherent = alchemy_dma_coherent();
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci	board_setup();	/* board specific setup */
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* IO/MEM resources. */
7362306a36Sopenharmony_ci	set_io_port_base(0);
7462306a36Sopenharmony_ci	ioport_resource.start = IOPORT_RESOURCE_START;
7562306a36Sopenharmony_ci	ioport_resource.end = IOPORT_RESOURCE_END;
7662306a36Sopenharmony_ci	iomem_resource.start = IOMEM_RESOURCE_START;
7762306a36Sopenharmony_ci	iomem_resource.end = IOMEM_RESOURCE_END;
7862306a36Sopenharmony_ci}
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#ifdef CONFIG_MIPS_FIXUP_BIGPHYS_ADDR
8162306a36Sopenharmony_ci/* This routine should be valid for all Au1x based boards */
8262306a36Sopenharmony_ciphys_addr_t fixup_bigphys_addr(phys_addr_t phys_addr, phys_addr_t size)
8362306a36Sopenharmony_ci{
8462306a36Sopenharmony_ci	unsigned long start = ALCHEMY_PCI_MEMWIN_START;
8562306a36Sopenharmony_ci	unsigned long end = ALCHEMY_PCI_MEMWIN_END;
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci	/* Don't fixup 36-bit addresses */
8862306a36Sopenharmony_ci	if ((phys_addr >> 32) != 0)
8962306a36Sopenharmony_ci		return phys_addr;
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci	/* Check for PCI memory window */
9262306a36Sopenharmony_ci	if (phys_addr >= start && (phys_addr + size - 1) <= end)
9362306a36Sopenharmony_ci		return (phys_addr_t)(AU1500_PCI_MEM_PHYS_ADDR + phys_addr);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	/* default nop */
9662306a36Sopenharmony_ci	return phys_addr;
9762306a36Sopenharmony_ci}
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciint io_remap_pfn_range(struct vm_area_struct *vma, unsigned long vaddr,
10062306a36Sopenharmony_ci		unsigned long pfn, unsigned long size, pgprot_t prot)
10162306a36Sopenharmony_ci{
10262306a36Sopenharmony_ci	phys_addr_t phys_addr = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci	return remap_pfn_range(vma, vaddr, phys_addr >> PAGE_SHIFT, size, prot);
10562306a36Sopenharmony_ci}
10662306a36Sopenharmony_ciEXPORT_SYMBOL(io_remap_pfn_range);
10762306a36Sopenharmony_ci#endif /* CONFIG_MIPS_FIXUP_BIGPHYS_ADDR */
108