/*
 * linux/arch/arm/mach-iop33x/setup.c
 *
 * Author: Dave Jiang (dave.jiang@intel.com)
 * Copyright (C) 2004 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/platform_device.h>
#include <linux/serial.h>
#include <linux/tty.h>
#include <linux/serial_8250.h>

#include <asm/io.h>
#include <asm/pgtable.h>
#include <asm/page.h>
#include <asm/mach/map.h>
#include <asm/setup.h>
#include <asm/system.h>
#include <asm/memory.h>
#include <asm/hardware.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include <asm/mach/time.h>
#include <asm/hardware/iop3xx.h>

#define IOP331_UART_XTAL 33334000

static struct resource iop33x_uart0_resources[] = {
	[0] = {
		.start = IOP331_UART0_PHYS,
		.end = IOP331_UART0_PHYS + 0x3f,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = IRQ_IOP331_UART0,
		.end = IRQ_IOP331_UART0,
		.flags = IORESOURCE_IRQ
	}
};

static struct resource iop33x_uart1_resources[] = {
	[0] = {
		.start = IOP331_UART1_PHYS,
		.end = IOP331_UART1_PHYS + 0x3f,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = IRQ_IOP331_UART1,
		.end = IRQ_IOP331_UART1,
		.flags = IORESOURCE_IRQ
	}
};

static struct plat_serial8250_port iop33x_uart0_data[] = {
	{
       .membase     = (char*)(IOP331_UART0_VIRT),
       .mapbase     = (IOP331_UART0_PHYS),
       .irq         = IRQ_IOP331_UART0,
       .uartclk     = IOP331_UART_XTAL,
       .regshift    = 2,
       .iotype      = UPIO_MEM,
       .flags       = UPF_SKIP_TEST,
	},
	{  },
};

static struct plat_serial8250_port iop33x_uart1_data[] = {
	{
       .membase     = (char*)(IOP331_UART1_VIRT),
       .mapbase     = (IOP331_UART1_PHYS),
       .irq         = IRQ_IOP331_UART1,
       .uartclk     = IOP331_UART_XTAL,
       .regshift    = 2,
       .iotype      = UPIO_MEM,
       .flags       = UPF_SKIP_TEST,
	},
	{  },
};

static struct platform_device iop33x_uart0 = {
       .name = "serial8250",
       .id = PLAT8250_DEV_PLATFORM,
       .dev.platform_data = iop33x_uart0_data,
       .num_resources = 2,
       .resource = iop33x_uart0_resources,
};

static struct platform_device iop33x_uart1 = {
       .name = "serial8250",
       .id = PLAT8250_DEV_PLATFORM1,
       .dev.platform_data = iop33x_uart1_data,
       .num_resources = 2,
       .resource = iop33x_uart1_resources,
};

static struct platform_device *iop33x_devices[] __initdata = {
	&iop33x_uart0,
	&iop33x_uart1,
};

void __init iop33x_init(void)
{
	if(iop_is_331())
	{
		platform_add_devices(iop33x_devices,
				ARRAY_SIZE(iop33x_devices));
	}
	platform_device_register(&iop3xx_i2c0_device);
	platform_device_register(&iop3xx_i2c1_device);
}

#ifdef CONFIG_ARCH_IOP33X
extern void iop331_init_irq(void);
#endif

static void __init iop3xx_timer_init(void)
{
	iop3xx_init_time(IOP331_TICK_RATE);
}

struct sys_timer iop331_timer = {
	.init		= iop3xx_timer_init,
	.offset		= iop3xx_gettimeoffset,
};

#if defined(CONFIG_ARCH_IQ80331)
MACHINE_START(IQ80331, "Intel IQ80331")
	/* Maintainer: Intel Corp. */
	.phys_io	= 0xfefff000,
	.io_pg_offst	= ((0xfffff000) >> 18) & 0xfffc, // virtual, physical
	.map_io		= iop3xx_map_io,
	.init_irq	= iop331_init_irq,
	.timer		= &iop331_timer,
	.boot_params	= 0x0100,
	.init_machine	= iop33x_init,
MACHINE_END

#elif defined(CONFIG_MACH_IQ80332)
MACHINE_START(IQ80332, "Intel IQ80332")
	/* Maintainer: Intel Corp. */
	.phys_io	= 0xfefff000,
	.io_pg_offst	= ((0xfffff000) >> 18) & 0xfffc, // virtual, physical
	.map_io		= iop3xx_map_io,
	.init_irq	= iop331_init_irq,
	.timer		= &iop331_timer,
	.boot_params	= 0x0100,
	.init_machine	= iop33x_init,
MACHINE_END

#else
#error No machine descriptor defined for this IOP3XX implementation
#endif