/*
 *  linux/arch/arm/mach-scma11/scma11evb.c
 *
 *  Copyright (C) 2000 Deep Blue Solutions Ltd
 *  Copyright (C) 2002 Shane Nay (shane@minirl.com)
 *  Copyright 2004 Freescale Semiconductor, Inc. All Rights Reserved.
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/config.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/serial_8250.h>
#include <linux/kgdb.h>

#include <asm/hardware.h>
#include <asm/irq.h>
#include <asm/setup.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/arch/memory.h>
#include <asm/arch/gpio.h>
#include <asm/arch/board.h>

#include "dsp_bringup.h"

/*!
 * @file scma11evb.c
 * 
 * @brief This file contains the board specific initialization routines. 
 * 
 * @ingroup System
 */

extern void scma11_map_io(void);
extern void scma11_init_irq(void);
extern void scma11_cpu_init(void) __init;
extern void scma11evb_gpio_init(void) __init;
extern struct sys_timer mxc_timer;

static char command_line[COMMAND_LINE_SIZE];

/*!
 * The serial port definition structure. The fields contain:
 * {UART, CLK, PORT, IRQ, FLAGS}
 */
static struct plat_serial8250_port serial_platform_data[] = {
	{
		/* REVISIT: Should make this memory mapped */
		.iobase	= (unsigned long)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTA),
		.irq		= INT_EXT_INT6,
		.uartclk	= 14745600,
		.regshift	= 0,
		.iotype		= UPIO_PORT,
		/* REVISIT: Use proper shared IRQ "flags" since
		 * both serial ports share common interrupt line.
		 */
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
	}, {
		/* REVISIT: Should make this memory mapped */
		.iobase	= (unsigned long)(PBC_BASE_ADDRESS + PBC_SC16C652_UARTB),
		.irq		= INT_GPIO3,
		.uartclk	= 14745600,
		.regshift	= 0,
		.iotype		= UPIO_PORT,
		/* REVISIT: Use proper shared IRQ "flags" since
		 * both serial ports share common interrupt line.
		 */
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
	},
};

/*!
 * REVISIT: document me
 */
static struct platform_device serial_device = {
	.name			= "serial8250",
	.id			= 0,
	.dev			= {
		.platform_data	= serial_platform_data,
	},
};

/*!
 * REVISIT: document me
 */
static int __init scma11evb_init(void)
{
	return platform_device_register(&serial_device);
}

arch_initcall(scma11evb_init);

/*!
 * SCM-A11 EVB specific fixup function. It is called by \b setup_arch() in 
 * setup.c file very early on during kernel starts. It allows the user to 
 * statically fill in the proper values for the passed-in parameters. None of 
 * the parameters is used currently.
 * 
 * @param  desc         pointer to \b struct \b machine_desc
 * @param  tags         pointer to \b struct \b tag
 * @param  cmdline      pointer to the command line
 * @param  mi           pointer to \b struct \b meminfo
 */
static void __init fixup_scma11evb(struct machine_desc *desc, 
                                      struct tag *tags, char **cmdline, 
                                      struct meminfo *mi)
{
#ifdef CONFIG_KGDB_8250
	int i;
	for (i=0;
	     i < (sizeof(serial_platform_data)/sizeof(serial_platform_data[0]));
	     i += 1)
		kgdb8250_add_platform_port(i, &serial_platform_data[i]);
#endif

        scma11_cpu_init();
        
        /*store command line for use on mxc_board_init*/
        strcpy(command_line, *cmdline);
}

/*!
 * Board specific initialization.
 */
static void __init mxc_board_init(void)
{
        scma11evb_gpio_init();
        
        /*search for dsp specific parameters from kernel's command line*/
        if(dsp_parse_cmdline((const char*)command_line) != 0)
        dsp_startapp_request();
}

/*
 * The following uses standard kernel macros define in arch.h in order to 
 * initialize __mach_desc_SCMA11EVB data structure.
 */
MACHINE_START(SCMA11EVB, "Freescale SCM-A11 EVB")
        MAINTAINER("Freescale Semiconductor")
        
#ifdef CONFIG_SERIAL_8250_CONSOLE
        /*       physical memory    physical IO        virtual IO     */
        BOOT_MEM(PHYS_OFFSET_ASM, CS4_BASE_ADDR, CS4_BASE_ADDR_VIRT)
#else
        /*       physical memory    physical IO        virtual IO     */
        BOOT_MEM(PHYS_OFFSET_ASM, AIPS1_BASE_ADDR, AIPS1_BASE_ADDR_VIRT)
#endif
	BOOT_PARAMS(PHYS_OFFSET_ASM + 0x100)
        FIXUP(fixup_scma11evb)
        MAPIO(scma11_map_io)
        INITIRQ(scma11_init_irq)
        INIT_MACHINE(mxc_board_init)
        .timer		= &mxc_timer,
MACHINE_END
