/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#include "lpc-internals.h"

/****************************************************************************/
/*				CPU, FLASH and RAM configurations							*/
/****************************************************************************/

/*
*	FLASH configurations
*/

static const LPC_CHIP_ROM	rom_8K = {

	8, 2,
	{ 4,  4 }
};

static const LPC_CHIP_ROM	rom_16K = {

	16, 4,
	{ 4,  4,  4,  4 }
};

static const LPC_CHIP_ROM	rom_32K = {

	32, 8,
	{ 4,  4,  4,  4,  4,  4,  4,  4 }
};

static const LPC_CHIP_ROM	rom_64K = {

	64, 9,
	{  4,  4,  4,  4,  4,  4,  4,  4, 32 }
};

static const LPC_CHIP_ROM	rom_128K = {

	128, 11,
	{  4,  4,  4,  4,  4,  4,  4,  4, 32, 32, 32 }
};

static const LPC_CHIP_ROM	rom_256K = {

	256, 15,
	{  4,  4,  4,  4,  4,  4,  4,  4, 32, 32, 32, 32, 32, 32, 32 }
};

/*
*	On the 23xx series the 512K FLASH is actually only 504K, because
*	the last 8K is occupied by the bootloader. You can not access that
*	bit of the FLASH (well, you can read it, but that's about it).
*/

static const LPC_CHIP_ROM	rom_504K = {

	504, 28,
	{  4,  4,  4,  4,  4,  4,  4,  4, 32, 32, 32, 32, 32, 32,
	  32, 32, 32, 32, 32, 32, 32, 32,  4,  4,  4,  4,  4,  4 }
};

/*
*	On the 213x series the 512K FLASH is actually only 500K, because
*	the last 12K is occupied by the bootloader. You can not access that
*	bit of the FLASH (well, you can read it, but that's about it).
*/

static const LPC_CHIP_ROM	rom_500K = {

	504, 27,
	{  4,  4,  4,  4,  4,  4,  4,  4, 32, 32, 32, 32, 32, 32,
	  32, 32, 32, 32, 32, 32, 32, 32,  4,  4,  4,  4,  4 }
};

/*
*	Common RAM configuratuions
*/

static const LPC_CHIP_RAM	ram_2K  = { 0x40000000,  2 };
static const LPC_CHIP_RAM	ram_4K  = { 0x40000000,  4 };
static const LPC_CHIP_RAM	ram_8K  = { 0x40000000,  8 };
static const LPC_CHIP_RAM	ram_16K	= { 0x40000000, 16 };
static const LPC_CHIP_RAM	ram_32K = { 0x40000000, 32 };
static const LPC_CHIP_RAM	ram_64K = { 0x40000000, 64 };

/*
*	Common chip control register values
*/

static const LPC_CHIP_CPU	cpu_23xx = {

	14748000,
	64,
	0xe01fc040,
	0x00000000,
	0x00000001
};

static const LPC_CHIP_CPU	cpu_210x = {

	0,
	64,
	0xe01fc040,
	0x00000000,
	0x00000001
};

static const LPC_CHIP_CPU	cpu_213x = {

	0,
	64,
	0xe01fc040,
	0x00000000,
	0x00000001
};

/****************************************************************************/
/*								LPC210x										*/
/****************************************************************************/

// FIXME: The NXP manual does not specify the code for the 2101 and 2102
// and I don't have them. When they fix the manual, I'll add the chips.

static	const	LPC_CHIP lpc2103 = {

	327441,		"lpc2103",		NULL,
	&cpu_210x,	&rom_32K,		&ram_8K
};

/****************************************************************************/
/*								LPC213x										*/
/****************************************************************************/

static	const	LPC_CHIP lpc2131 = {

	196353,		"lpc2131",		NULL,
	&cpu_213x,	&rom_32K,		&ram_8K
};

static	const	LPC_CHIP lpc2132 = {

	196369,		"lpc2132",		NULL,
	&cpu_213x,	&rom_64K,		&ram_16K
};

static	const	LPC_CHIP lpc2134 = {

	196370,		"lpc2134",		NULL,
	&cpu_213x,	&rom_128K,		&ram_16K
};

static	const	LPC_CHIP lpc2136 = {

	196387,		"lpc2136",		NULL,
	&cpu_213x,	&rom_256K,		&ram_32K
};

static	const	LPC_CHIP lpc2138 = {

	196389,		"lpc2138",		NULL,
	&cpu_213x,	&rom_500K,		&ram_32K
};

/****************************************************************************/
/*								LPC23xx										*/
/****************************************************************************/

static	const	LPC_CHIP lpc2361 = {

	369161985,	"lpc2361",		NULL,
	&cpu_23xx,	&rom_64K,		&ram_8K
};

static	const	LPC_CHIP lpc2362 = {

	369164066,	"lpc2362",		NULL,
	&cpu_23xx,	&rom_128K,		&ram_32K
};

static	const	LPC_CHIP lpc2364 = {

	369162498,	"lpc2364",		NULL,
	&cpu_23xx,	&rom_128K,		&ram_8K
};

static	const	LPC_CHIP lpc2365 = {

	369158179,	"lpc2365",		NULL,
	&cpu_23xx,	&rom_256K,		&ram_32K
};

static	const	LPC_CHIP lpc2366 = {

	369162531,	"lpc2366",		NULL,
	&cpu_23xx,	&rom_256K,		&ram_32K
};

static	const	LPC_CHIP lpc2367 = {

	369158181,	"lpc2367",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_32K
};

static	const	LPC_CHIP lpc2368 = {

	369162533,	"lpc2368",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_32K
};

static	const	LPC_CHIP lpc2377 = {

	385935397,	"lpc2377",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_32K
};

static	const	LPC_CHIP lpc2378 = {

	385940773,	"lpc2378",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_32K
};

static	const	LPC_CHIP lpc2387 = {

	385941301,	"lpc2387",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_64K
};

static	const	LPC_CHIP lpc2388 = {

	402718517,	"lpc2388",		NULL,
	&cpu_23xx,	&rom_504K,		&ram_64K
};

/*
*	This is silicon revision 0 (marked '-'), a very buggy chip. Alas,
*	some devboards (in particular, the Olimex one) come with this chip.
*	If you have a devboard with that chip, change to a rev. B silicon
*	as soon as you can.
*/

static	const	LPC_CHIP lpc2378r0 = {

	117702437,	"lpc2378",		"-",
	&cpu_23xx,	&rom_504K,		&ram_32K
};

/****************************************************************************/
/*						List of all known chips								*/
/****************************************************************************/

const	LPC_CHIP	*chips[] = {

	&lpc2103,

	&lpc2131,	&lpc2132,	&lpc2134,	&lpc2136,	&lpc2138,

	&lpc2361,	&lpc2362,	&lpc2364,	&lpc2365,	&lpc2366,
	&lpc2367,	&lpc2368,	&lpc2377,	&lpc2378,	&lpc2387,
	&lpc2388,	&lpc2378r0,
	(void*) 0
};

