#ifndef _MYX_MAP_H_
#define _MYX_MAP_H_

#include <linux/config.h>

#define MYX_FLASH_SECTOR_SIZE	0x20000

#ifdef CONFIG_OOMA_MYX_ALL_MTD_WRITEABLE
	/*
	 * do not write protect any partitons
	 */
#	define MYX_FLASH_MTD_WRITEABLE
#else /* not CONFIG_OOMA_MYX_MTD_ALL_WRITABLE */
#	define MYX_FLASH_MTD_WRITEABLE	MTD_WRITEABLE
#endif /* CONFIG_OOMA_MYX_ALL_MTD_WRITEABLE */

/**********************************************
 *
 *             Myx Flash layout
 *             16M 128x128k sectors
 *
 *                 New                    Old
 *            ------------------     -----------------
 *            |                |     |               |
 *            ~                ~     ~               ~
 *            |                |     |               |
 * 0xbfec0000 | Opt            |     |               |
 *            |                |     |               |
 *            ------------------     | Opt X         | 0xbfe20000
 *            |                |     -----------------
 *            |                |     |               |
 *            |                |     |               |
 *            |                |     |               |
 *            |                |     |               |
 * 0xbfd80000 | Kernel A       |     |               |
 *            ------------------     | Kernel AX     | 0xbfd40000
 *            |                |     -----------------
 *            |                |     |               |
 *            |                |     |               |
 *            |                |     |               |
 *            |                |     |               |
 *            |                |     | Kernel BX     | 0xbfc60000
 *            |                |     -----------------
 * 0xbfc40000 | Kernel B       |     | Stash         | 0xbfc40000
 *            ------------------     -----------------

 *            ------------------
 * 0xbfc20000 | Boot State     |
 *            ------------------
 * 0xbfc00000 | Trapt          |
 *            ------------------
 * 0xbfbe0000 | Config         |
 *            ------------------
 *            |                |
 *            ~                ~
 *            |                |
 * 0xbf700000 | Image A        |
 *            |                |
 *            ------------------
 *            |                |
 *            ~                ~
 *            |                |
 * 0xbf020000 | Image B        |
 *            ------------------
 * 0xbf000000 | Boot Loader    |
 *            ------------------
 *
 **********************************************/

#ifdef CONFIG_OOMA_MYX_FLASH_32MB
#	define MYX_FLASH_BASE		0xbe000000
#endif /* CONFIG_OOMA_MYX_FLASH_32MB */

#ifdef CONFIG_OOMA_MYX_FLASH_16MB
#	define MYX_FLASH_BASE		0xbf000000
#endif /* CONFIG_OOMA_MYX_FLASH_16MB */

#ifdef CONFIG_OOMA_MYX_FLASH_8MB
#	define MYX_FLASH_BASE		0xbf800000
#endif /* CONFIG_OOMA_MYX_FLASH_8MB */

#define MYX_FLASH_OFFSET(n)		((n) & 0x00ffffff)

#ifdef CONFIG_OOMA_MYX_FLASH_32MB

/*
 * Image X file system
 * 0xbe000000 - 0xbf000000 len 0x01000000
 */
#define MYX_FLASH_IMG_X_ADDR		0xbe000000
#define MYX_FLASH_IMG_X_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_IMG_X_ADDR)
#define MYX_FLASH_IMG_X_LEN		0x01000000

#endif /* CONFIG_OOMA_MYX_FLASH_32MB */

/*
 * Boot Loader
 * 0xbf000000 - 0xbf020000 len 0x00020000
 */
#define MYX_FLASH_BOOT_ADDR		0xbf000000
#define MYX_FLASH_BOOT_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_BOOT_ADDR)
#define MYX_FLASH_BOOT_LEN		0x20000

/*
 * Image A file system
 * 0xbf020000 - 0xbf600000 len 0x005e0000
 */
#define MYX_FLASH_JFFS_B_ADDR		(MYX_FLASH_BOOT_ADDR + MYX_FLASH_BOOT_LEN)
#define MYX_FLASH_JFFS_B_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_JFFS_B_ADDR)
#define MYX_FLASH_JFFS_B_LEN		0x005e0000

/*
 * Image B file system
 * 0xbf600000 - 0xbfbe0000 len 0x005e0000
 */
#define MYX_FLASH_JFFS_A_ADDR		(MYX_FLASH_JFFS_B_ADDR + MYX_FLASH_JFFS_B_LEN)
#define MYX_FLASH_JFFS_A_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_JFFS_A_ADDR)
#define MYX_FLASH_JFFS_A_LEN		0x005e0000

/*
 * Config sector
 * 0xbfbe0000 - 0xbfc00000 len 0x00020000
 */
#define MYX_FLASH_CONFIG_ADDR		(0xbfc00000 - 0x20000)
#define MYX_FLASH_CONFIG_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_CONFIG_ADDR)
#define MYX_FLASH_CONFIG_LEN		0x20000

/*
 * Trap sector
 * 0xbfc00000 - 0xbfc20000 len 0x00020000
 */
#define MYX_FLASH_TRAP_ADDR		0xbfc00000
#define MYX_FLASH_TRAP_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_TRAP_ADDR)
#define MYX_FLASH_TRAP_LEN		0x20000

/*
 * Boot State Sector
 * 0xbfc20000 - 0xbfc40000 len 0x00020000
 */
#define MYX_FLASH_BOOTSTATE_ADDR	(MYX_FLASH_TRAP_ADDR + MYX_FLASH_TRAP_LEN)
#define MYX_FLASH_BOOTSTATE_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_BOOTSTATE_ADDR)
#define MYX_FLASH_BOOTSTATE_LEN		0x20000

/*****************************************************************************************
 *
 * NEW flash layout
 *
 *****************************************************************************************/

/*
 * Kernel B
 * 0xbfc40000 - 0xbfd80000 len 0x00140000
 */
#define MYX_FLASH_KERNEL_B_ADDR		(MYX_FLASH_BOOTSTATE_ADDR + MYX_FLASH_BOOTSTATE_LEN)
#define MYX_FLASH_KERNEL_B_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_KERNEL_B_ADDR)
#define MYX_FLASH_KERNEL_B_LEN		0x00140000

/*
 * Kernel A
 * 0xbfd80000 - 0xbfec0000 len 0x00140000
 */
#define MYX_FLASH_KERNEL_A_ADDR		(MYX_FLASH_KERNEL_B_ADDR + MYX_FLASH_KERNEL_B_LEN)
#define MYX_FLASH_KERNEL_A_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_KERNEL_A_ADDR)
#define MYX_FLASH_KERNEL_A_LEN		0x00140000

/*
 * Opt file system
 * 0xbfec0000 - 0xc0000000 len 0x00140000
 */
#define MYX_FLASH_JFFS_OPT_ADDR		(MYX_FLASH_KERNEL_A_ADDR + MYX_FLASH_KERNEL_A_LEN)
#define MYX_FLASH_JFFS_OPT_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_JFFS_OPT_ADDR)
#define MYX_FLASH_JFFS_OPT_LEN		(0xc0000000 - MYX_FLASH_JFFS_OPT_ADDR)

/*****************************************************************************************
 *
 * OLD flash layout
 *
 *****************************************************************************************/

/*
 * Stash Sector
 * 0xbfc40000 - 0xbfc60000 len 0x00020000
 */
#define MYX_FLASH_STASH_ADDR		(MYX_FLASH_BOOTSTATE_ADDR + MYX_FLASH_BOOTSTATE_LEN)
#define MYX_FLASH_STASH_OFFSET		MYX_FLASH_OFFSET(MYX_FLASH_STASH_ADDR)
#define MYX_FLASH_STASH_LEN		0x20000

/*
 * Kernel BX
 * 0xbfc60000 - 0xbfd40000 len 0x000e0000
 */
#define MYX_FLASH_KERNEL_BX_ADDR	(MYX_FLASH_STASH_ADDR + MYX_FLASH_STASH_LEN)
#define MYX_FLASH_KERNEL_BX_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_KERNEL_BX_ADDR)
#define MYX_FLASH_KERNEL_BX_LEN		0x000e0000

/*
 * Kernel AX
 * 0xbfd40000 - 0xbfe20000 len 0x000e0000
 */
#define MYX_FLASH_KERNEL_AX_ADDR	(MYX_FLASH_KERNEL_BX_ADDR + MYX_FLASH_KERNEL_BX_LEN)
#define MYX_FLASH_KERNEL_AX_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_KERNEL_AX_ADDR)
#define MYX_FLASH_KERNEL_AX_LEN		0x000e0000

/*
 * Opt X file system
 * 0xbfe20000 - 0xc0000000 len 0x001e0000
 */
#define MYX_FLASH_JFFS_OPTX_ADDR	(MYX_FLASH_KERNEL_AX_ADDR + MYX_FLASH_KERNEL_AX_LEN)
#define MYX_FLASH_JFFS_OPTX_OFFSET	MYX_FLASH_OFFSET(MYX_FLASH_JFFS_OPTX_ADDR)
#define MYX_FLASH_JFFS_OPTX_LEN		(0xc0000000 - MYX_FLASH_JFFS_OPTX_ADDR)


/**********************************************
 *
 * LEDS
 *
 **********************************************/

#define MYXLED_IOW_SET	_IOW('L', 0, myx_led_t)
#define MYXLED_IOR_GET	_IOR('L', 0, myx_led_t)

#define MYX_LED_GATE_FUSIV	0
#define MYX_LED_GATE_BLACKFIN	1

#define MYX_LED_LINE_1		0
#define MYX_LED_LINE_1_SHIFT	0
#define MYX_LED_LINE_1_MASK	(~(0x1 << MYX_LED_LINE_1_SHIFT))
#define MYX_LED_LINE_1_RED	(0x0 << MYX_LED_LINE_1_SHIFT)
#define MYX_LED_LINE_1_OFF	(0x1 << MYX_LED_LINE_1_SHIFT)
#define MYX_LED_LINE_1_RED_VAL	(~(0x1 << MYX_LED_LINE_1_SHIFT))

#define MYX_LED_LINE_2		1
#define MYX_LED_LINE_2_SHIFT	2
#define MYX_LED_LINE_2_MASK	(~(0x1 << MYX_LED_LINE_2_SHIFT))
#define MYX_LED_LINE_2_RED	(0x0 << MYX_LED_LINE_2_SHIFT)
#define MYX_LED_LINE_2_OFF	(0x1 << MYX_LED_LINE_2_SHIFT)
#define MYX_LED_LINE_2_RED_VAL	(~(0x1 << MYX_LED_LINE_2_SHIFT))

#define MYX_LED_DEL		2
#define MYX_LED_DEL_SHIFT	4
#define MYX_LED_DEL_MASK	(~(0x1 << MYX_LED_DEL_SHIFT))
#define MYX_LED_DEL_RED		(0x0 << MYX_LED_DEL_SHIFT)
#define MYX_LED_DEL_OFF		(0x1 << MYX_LED_DEL_SHIFT)

#define MYX_LED_SAVE		3
#define MYX_LED_SAVE_SHIFT	5
#define MYX_LED_SAVE_MASK	(~(0x1 << MYX_LED_SAVE_SHIFT))
#define MYX_LED_SAVE_RED	(0x0 << MYX_LED_SAVE_SHIFT)
#define MYX_LED_SAVE_OFF	(0x1 << MYX_LED_SAVE_SHIFT)

#define MYX_LED_FF		4
#define MYX_LED_FF_SHIFT	6
#define MYX_LED_FF_MASK		(~(0x1 << MYX_LED_FF_SHIFT))
#define MYX_LED_FF_RED		(0x0 << MYX_LED_FF_SHIFT)
#define MYX_LED_FF_OFF		(0x1 << MYX_LED_FF_SHIFT)

#define MYX_LED_RW		5
#define MYX_LED_RW_SHIFT	7
#define MYX_LED_RW_MASK		(~(0x1 << MYX_LED_RW_SHIFT))
#define MYX_LED_RW_RED		(0x0 << MYX_LED_RW_SHIFT)
#define MYX_LED_RW_OFF		(0x1 << MYX_LED_RW_SHIFT)

#define MYX_LED_STOP		6
#define MYX_LED_STOP_SHIFT	8
#define MYX_LED_STOP_MASK	(~(0x1 << MYX_LED_STOP_SHIFT))
#define MYX_LED_STOP_RED	(0x0 << MYX_LED_STOP_SHIFT)
#define MYX_LED_STOP_OFF	(0x1 << MYX_LED_STOP_SHIFT)

#define MYX_LED_PLAY_BLUE	7
#define MYX_LED_PLAY_BLUE_SHIFT	9
#define MYX_LED_PLAY_BLUE_MASK	(~(0x1 << MYX_LED_PLAY_BLUE_SHIFT))
#define MYX_LED_PLAY_BLUE_ON	(0x0 << MYX_LED_PLAY_BLUE_SHIFT)
#define MYX_LED_PLAY_BLUE_OFF	(0x1 << MYX_LED_PLAY_BLUE_SHIFT)
#define MYX_LED_PLAY_BLUE_VAL	(~(0x1 << MYX_LED_PLAY_BLUE_SHIFT))

#define MYX_LED_PLAY_RED	8
#define MYX_LED_PLAY_RED_SHIFT	10
#define MYX_LED_PLAY_RED_MASK	(~(0x1 << MYX_LED_PLAY_RED_SHIFT))
#define MYX_LED_PLAY_RED_ON	(0x0 << MYX_LED_PLAY_RED_SHIFT)
#define MYX_LED_PLAY_RED_OFF	(0x1 << MYX_LED_PLAY_RED_SHIFT)
#define MYX_LED_PLAY_RED_VAL	(~(0x1 << MYX_LED_PLAY_RED_SHIFT))

#define MYX_LED_OOMA_BLUE	9
#define MYX_LED_OOMA_BLUE_SHIFT	11
#define MYX_LED_OOMA_BLUE_MASK	(~(0x1 << MYX_LED_OOMA_BLUE_SHIFT))
#define MYX_LED_OOMA_BLUE_ON	(0x0 << MYX_LED_OOMA_BLUE_SHIFT)
#define MYX_LED_OOMA_BLUE_OFF	(0x1 << MYX_LED_OOMA_BLUE_SHIFT)
#define MYX_LED_OOMA_BLUE_VAL	(~(0x1 << MYX_LED_OOMA_BLUE_SHIFT))

#define MYX_LED_OOMA_RED	10
#define MYX_LED_OOMA_RED_SHIFT	12
#define MYX_LED_OOMA_RED_MASK	(~(0x1 << MYX_LED_OOMA_RED_SHIFT))
#define MYX_LED_OOMA_RED_ON	(0x0 << MYX_LED_OOMA_RED_SHIFT)
#define MYX_LED_OOMA_RED_OFF	(0x1 << MYX_LED_OOMA_RED_SHIFT)
#define MYX_LED_OOMA_RED_VAL	(~(0x1 << MYX_LED_OOMA_RED_SHIFT))

#define MYX_LED_N		11

/********************************************************************
 *
 * Vocal led defs
 *
 ********************************************************************/

#define MYX_LED_SEGMENT_COUNT	6

typedef struct myx_led_descriptor_s {
	unsigned short	myx_led_descriptor_mask;
	short		myx_led_descriptor_times[MYX_LED_SEGMENT_COUNT];
} myx_led_descriptor_t;

#define MYX_LED_STATE_OFF	0
#define MYX_LED_STATE_ON	1

typedef struct myx_led {
	int			myx_led_id;
	int			myx_led_mask;
	int			myx_led_expires;
	int			myx_led_val_on;
	int			myx_led_val_off;
	int			myx_led_state;
	myx_led_descriptor_t	myx_led_des;
} myx_led_t;

/*
 *	DPBX LED cadence selectors
 *
 *	values are indices into a time on/off table and range from 0 to 15
 *
 */
#define DPBX_LED__MASK				0xf		/* Mask */

#define DPBX_LED__OFF				0		/* Index 0 - fully off for one second */
#define DPBX_LED__ON				1		/* Index 1 - fully on for one second */

/* Symmetric patterns */
#define DPBX_LED__ON_P500_OFF_P500	2		/* Index 2 - .5 seconds on, .5 seconds off */
#define DPBX_LED__ON_P333_OFF_P334	3		/* Index 3 - .333 seconds on, .334 seconds off */
#define DPBX_LED__ON_P250_OFF_P250	4		/* Index 4 - .25 seconds on, .25 seconds off */
#define DPBX_LED__ON_P200_OFF_P200	5		/* Index 5 - .2 seconds on, .2 seconds off */
#define DPBX_LED__ON_P150_OFF_P150	6		/* Index 6 - .15 seconds on, .15 seconds off */
#define DPBX_LED__ON_P125_OFF_P125	7		/* Index 7 - .125 seconds on, .125 seconds off */

/* Asymmetric patterns */
#define DPBX_LED__ON_P875_OFF_P125	8		/* Index 8 - .875 seconds on, .125 seconds off */
#define DPBX_LED__ON_P750_OFF_P250	9		/* Index 9 - .75 seconds on, .25 seconds off */
#define DPBX_LED__ON_P666_OFF_P334	10		/* Index 10 - .666 seconds on, .334 seconds off */
#define DPBX_LED__ON_P600_OFF_P400	11		/* Index 11 - .6 seconds on, .4 seconds off */
#define DPBX_LED__ON_P400_OFF_P600	12		/* Index 12 - .4 seconds on, .6 seconds off */
#define DPBX_LED__ON_P334_OFF_P666	13		/* Index 13 - .334 seconds on, .666 seconds off */
#define DPBX_LED__ON_P250_OFF_P750	14		/* Index 14 - .25 seconds on, .75 seconds off */
#define DPBX_LED__ON_P125_OFF_P875	15		/* Index 15 - .125 seconds on, .875 seconds off */

/* these defines map what the mask is for the lights on the board
relative to the button position. To use an LED a value should
be added to the ooma_light_index_e below so that we can decouple
the bitvalue from the meaning of the lights */

#define OOMA_LIGHT_POSITION_LINE_ONE_RED 0x0001
/* 0x0002 is now the hpna phy reset (styx only) */
//#define OOMA_LIGHT_POSITION_LINE_ONE_GREEN 0x0002 
#define OOMA_LIGHT_POSITION_LINE_TWO_RED 0x0004 
/* 0x0008 is not connected in EVT4/5 myx or styx, it is a green LED
   on the older boards */
//#define OOMA_LIGHT_POSITION_LINE_TWO_GREEN 0x0008
#define OOMA_LIGHT_POSITION_TRASH 0x0010
#define OOMA_LIGHT_POSITION_ENVELOPE 0x0020
#define OOMA_LIGHT_POSITION_FORWARD 0x0040
#define OOMA_LIGHT_POSITION_REWIND 0x0080
#define OOMA_LIGHT_POSITION_STOP_PAUSE 0x0100
#define OOMA_LIGHT_POSITION_PLAY_BLUE 0x0200
#define OOMA_LIGHT_POSITION_PLAY_RED 0x0400
#define OOMA_LIGHT_POSITION_OOMA_MARQUEE_BLUE 0x0800
#define OOMA_LIGHT_POSITION_OOMA_MARQUEE_GREEN 0x0800
#define OOMA_LIGHT_POSITION_OOMA_MARQUEE_RED 0x1000
#define OOMA_LIGHT_POSITION_OOMA_MARQUEE_YELLOW 0x1000
/* orange is styx only, myx controlled via gpio on fusiv */
#define OOMA_LIGHT_POSITION_OOMA_MARQUEE_ORANGE 0x2000
/* styx only, 0x4000 is speaker enable */
/* dimmer control is styx only, myx controlled via gpio on fusiv */
#define OOMA_LIGHT_DIMMER_CONTROL 0x8000

/* Each of these correspond to a position of a light on the board */
typedef enum ooma_light_index_e {
	OOMA_LIGHT_LINE_ONE = OOMA_LIGHT_POSITION_LINE_ONE_RED,
	OOMA_LIGHT_LINE_TWO = OOMA_LIGHT_POSITION_LINE_TWO_RED,
	OOMA_LIGHT_MWI = OOMA_LIGHT_POSITION_PLAY_RED,
	OOMA_LIGHT_DND = OOMA_LIGHT_POSITION_ENVELOPE,
	OOMA_LIGHT_PLAY = OOMA_LIGHT_POSITION_PLAY_RED,
	OOMA_LIGHT_STOP = OOMA_LIGHT_POSITION_STOP_PAUSE,
	OOMA_LIGHT_FWD = OOMA_LIGHT_POSITION_FORWARD,
	OOMA_LIGHT_REW = OOMA_LIGHT_POSITION_REWIND,
	OOMA_LIGHT_TRASH = OOMA_LIGHT_POSITION_TRASH,
	OOMA_LIGHT_OOMA_YELLOW = OOMA_LIGHT_POSITION_OOMA_MARQUEE_YELLOW,
	OOMA_LIGHT_OOMA_GREEN = OOMA_LIGHT_POSITION_OOMA_MARQUEE_GREEN,
    OOMA_LIGHT_ALL = 0x1FFF,
    OOMA_LIGHT_NONE = 0x0000
} ooma_light_index;

/********************************************************************
 *
 * end of Vocal led defs
 *
 ********************************************************************/

/**********************************************
 *
 * GPIO
 *
 **********************************************/

#define MYX_GPIO_N_DSP_RST	(1 << 15)
#define MYX_GPIO_N_PHY_RST	(1 << 14)
#define MYX_GPIO_EBI_ADDR22	(1 << 13)
#define MYX_GPIO_EBI_ADDR23	(1 << 12)
#define MYX_GPIO_CODEC_CSB	(1 << 11)
#define MYX_GPIO_CODEC_CLK	(1 << 10)
#define MYX_GPIO_N_LED_CLR	(1 << 5)
#define MYX_GPIO_LED_OVERRIDE	(1 << 4)
#define MYX_GPIO_CODEC_DAT	(1 << 4)
#define MYX_GPIO_N_CVM_RST	(1 << 0)

/**********************************************
 *
 * Myx Device Nodes
 *
 **********************************************/

#define MYX_FUSIVMAP_MAJOR_DEV		125
#define MYX_FUSIVMAP_MINOR_DEV		0

#define MYX_LEDS_MAJOR_DEV		124
#define MYX_LEDS_MINOR_DEV		0

#define MYX_SFSS_MAJOR_DEV		123
#define MYX_SFSS_MINOR_DEV		0

#define MYX_SPKR_MAJOR_DEV		122
#define MYX_SPKR_DEV_NAME		"/dev/myx_spkr"

#define MYX_MIC_MAJOR_DEV		121
#define MYX_MIC_DEV_NAME		"/dev/myx_mic"

/**********************************************
 *
 * DMA channel assignments
 *
 **********************************************/

#define MYX_DMA_SPORT_TX_CHANNEL	1
#define MYX_DMA_SPORT_RX_CHANNEL	2

/**********************************************
 *
 * fsp driver (fusiv serial port)
 *
 **********************************************/

#define FSP_RESET_CVM	1
#endif /* _MYX_MAP_H_ */
