/*
 * arch/ppc/kernel/ppc85xx_common.c
 *
 * MPC85xx support routines
 *
 * Maintainer: Kumar Gala <kumar.gala@motorola.com>
 *
 * Copyright 2003 Motorola Inc.
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/config.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/mpc85xx.h>
#include <asm/mmu.h>
#include <asm/ocp.h>

/* ************************************************************************ */
/* Return the value of CCSRBAR for the current board */

phys_addr_t
get_ccsrbar(void)
{
	return BOARD_CCSRBAR;
}

/* ************************************************************************ */
/* Update the 8540 OCP tables paddr field */
void
mpc8540_update_ocp(phys_addr_t ccsrbar)
{
	struct ocp_def *def;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_IIC, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_16550, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_16550, 1);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 1);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 2);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_DMA, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_PERFMON, 0);
	if (def)
		def->paddr += ccsrbar;
}

/* ************************************************************************ */
/* Update the 8560 OCP tables paddr field */
void
mpc8560_update_ocp(phys_addr_t ccsrbar)
{
	struct ocp_def *def;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_IIC, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 1);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_DMA, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_PERFMON, 0);
	if (def)
		def->paddr += ccsrbar;
}

/* ************************************************************************ */
/* Update the 8555 OCP tables paddr field */
void
mpc8555_update_ocp(phys_addr_t ccsrbar)
{
	struct ocp_def *def;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_IIC, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_16550, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_16550, 1);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_GFAR, 1);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_DMA, 0);
	if (def)
		def->paddr += ccsrbar;

	def = ocp_get_one_device(OCP_VENDOR_MOTOROLA, OCP_FUNC_PERFMON, 0);
	if (def)
		def->paddr += ccsrbar;
}

EXPORT_SYMBOL(get_ccsrbar);
