/*
 * Copyright (C) 2010 Nokia
 * Copyright (C) 2010 Texas Instruments
 *
 * 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/module.h>
#include <linux/init.h>

#include "mux.h"

#ifdef CONFIG_OMAP_MUX

#define _OMAP2420_MUXENTRY(M0, g, m0, m1, m2, m3, m4, m5, m6, m7)		\
{									\
	.reg_offset	= (OMAP2420_CONTROL_PADCONF_##M0##_OFFSET),	\
	.gpio		= (g),						\
	.muxnames	= { m0, m1, m2, m3, m4, m5, m6, m7 },		\
}

#else

#define _OMAP2420_MUXENTRY(M0, g, m0, m1, m2, m3, m4, m5, m6, m7)		\
{									\
	.reg_offset	= (OMAP2420_CONTROL_PADCONF_##M0##_OFFSET),	\
	.gpio		= (g),						\
}

#endif

#define _OMAP2420_BALLENTRY(M0, bb, bt)					\
{									\
	.reg_offset	= (OMAP2420_CONTROL_PADCONF_##M0##_OFFSET),	\
	.balls		= { bb, bt },					\
}

/*
 * Superset of all mux modes for omap2420
 */
static struct omap_mux __initdata omap2420_muxmodes[] = {
	_OMAP2420_MUXENTRY(CAM_D0, 54,
		"cam_d0", "hw_dbg2", "sti_dout", "gpio_54",
		NULL, NULL, "etk_d2", NULL),
	_OMAP2420_MUXENTRY(CAM_D1, 53,
		"cam_d1", "hw_dbg3", "sti_din", "gpio_53",
		NULL, NULL, "etk_d3", NULL),
	_OMAP2420_MUXENTRY(CAM_D2, 52,
		"cam_d2", "hw_dbg4", "mcbsp1_clkx", "gpio_52",
		NULL, NULL, "etk_d4", NULL),
	_OMAP2420_MUXENTRY(CAM_D3, 51,
		"cam_d3", "hw_dbg5", "mcbsp1_dr", "gpio_51",
		NULL, NULL, "etk_d5", NULL),
	_OMAP2420_MUXENTRY(CAM_D4, 50,
		"cam_d4", "hw_dbg6", "mcbsp1_fsr", "gpio_50",
		NULL, NULL, "etk_d6", NULL),
	_OMAP2420_MUXENTRY(CAM_D5, 49,
		"cam_d5", "hw_dbg7", "mcbsp1_clkr", "gpio_49",
		NULL, NULL, "etk_d7", NULL),
	_OMAP2420_MUXENTRY(CAM_D6, 0,
		"cam_d6", "hw_dbg8", NULL, NULL,
		NULL, NULL, "etk_d8", NULL),
	_OMAP2420_MUXENTRY(CAM_D7, 0,
		"cam_d7", "hw_dbg9", NULL, NULL,
		NULL, NULL, "etk_d9", NULL),
	_OMAP2420_MUXENTRY(CAM_D8, 54,
		"cam_d8", "hw_dbg10", NULL, "gpio_54",
		NULL, NULL, "etk_d10", NULL),
	_OMAP2420_MUXENTRY(CAM_D9, 53,
		"cam_d9", "hw_dbg11", NULL, "gpio_53",
		NULL, NULL, "etk_d11", NULL),
	_OMAP2420_MUXENTRY(CAM_HS, 55,
		"cam_hs", "hw_dbg1", "mcbsp1_dx", "gpio_55",
		NULL, NULL, "etk_d1", NULL),
	_OMAP2420_MUXENTRY(CAM_LCLK, 57,
		"cam_lclk", NULL, "mcbsp_clks", "gpio_57",
		NULL, NULL, "etk_c1", NULL),
	_OMAP2420_MUXENTRY(CAM_VS, 56,
		"cam_vs", "hw_dbg0", "mcbsp1_fsx", "gpio_56",
		NULL, NULL, "etk_d0", NULL),
	_OMAP2420_MUXENTRY(CAM_XCLK, 0,
		"cam_xclk", NULL, "sti_clk", NULL,
		NULL, NULL, "etk_c2", NULL),
	_OMAP2420_MUXENTRY(DSS_ACBIAS, 48,
		"dss_acbias", NULL, "mcbsp2_fsx", "gpio_48",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA10, 40,
		"dss_data10", NULL, NULL, "gpio_40",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA11, 41,
		"dss_data11", NULL, NULL, "gpio_41",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA12, 42,
		"dss_data12", NULL, NULL, "gpio_42",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA13, 43,
		"dss_data13", NULL, NULL, "gpio_43",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA14, 44,
		"dss_data14", NULL, NULL, "gpio_44",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA15, 45,
		"dss_data15", NULL, NULL, "gpio_45",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA16, 46,
		"dss_data16", NULL, NULL, "gpio_46",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA17, 47,
		"dss_data17", NULL, NULL, "gpio_47",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA8, 38,
		"dss_data8", NULL, NULL, "gpio_38",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(DSS_DATA9, 39,
		"dss_data9", NULL, NULL, "gpio_39",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_DIN, 115,
		"eac_ac_din", "mcbsp2_dr", NULL, "gpio_115",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_DOUT, 116,
		"eac_ac_dout", "mcbsp2_dx", NULL, "gpio_116",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_FS, 114,
		"eac_ac_fs", "mcbsp2_fsx", NULL, "gpio_114",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_MCLK, 117,
		"eac_ac_mclk", NULL, NULL, "gpio_117",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_RST, 118,
		"eac_ac_rst", "eac_bt_din", NULL, "gpio_118",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_AC_SCLK, 113,
		"eac_ac_sclk", "mcbsp2_clkx", NULL, "gpio_113",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(EAC_BT_DIN, 73,
		"eac_bt_din", NULL, NULL, "gpio_73",
		NULL, NULL, "etk_d9", NULL),
	_OMAP2420_MUXENTRY(EAC_BT_DOUT, 74,
		"eac_bt_dout", NULL, "sti_clk", "gpio_74",
		NULL, NULL, "etk_d8", NULL),
	_OMAP2420_MUXENTRY(EAC_BT_FS, 72,
		"eac_bt_fs", NULL, NULL, "gpio_72",
		NULL, NULL, "etk_d10", NULL),
	_OMAP2420_MUXENTRY(EAC_BT_SCLK, 71,
		"eac_bt_sclk", NULL, NULL, "gpio_71",
		NULL, NULL, "etk_d11", NULL),
	_OMAP2420_MUXENTRY(GPIO_119, 119,
		"gpio_119", NULL, "sti_din", "gpio_119",
		NULL, "sys_boot0", "etk_d12", NULL),
	_OMAP2420_MUXENTRY(GPIO_120, 120,
		"gpio_120", NULL, "sti_dout", "gpio_120",
		"cam_d9", "sys_boot1", "etk_d13", NULL),
	_OMAP2420_MUXENTRY(GPIO_121, 121,
		"gpio_121", NULL, NULL, "gpio_121",
		"jtag_emu2", "sys_boot2", "etk_d14", NULL),
	_OMAP2420_MUXENTRY(GPIO_122, 122,
		"gpio_122", NULL, NULL, "gpio_122",
		"jtag_emu3", "sys_boot3", "etk_d15", NULL),
	_OMAP2420_MUXENTRY(GPIO_124, 124,
		"gpio_124", NULL, NULL, "gpio_124",
		NULL, "sys_boot5", NULL, NULL),
	_OMAP2420_MUXENTRY(GPIO_125, 125,
		"gpio_125", "sys_jtagsel1", "sys_jtagsel2", "gpio_125",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPIO_36, 36,
		"gpio_36", NULL, NULL, "gpio_36",
		NULL, "sys_boot4", NULL, NULL),
	_OMAP2420_MUXENTRY(GPIO_62, 62,
		"gpio_62", "uart1_rx", "usb1_dat", "gpio_62",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPIO_6, 6,
		"gpio_6", "tv_detpulse", NULL, "gpio_6",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A10, 3,
		"gpmc_a10", NULL, "sys_ndmareq5", "gpio_3",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A1, 12,
		"gpmc_a1", "dss_data18", NULL, "gpio_12",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A2, 11,
		"gpmc_a2", "dss_data19", NULL, "gpio_11",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A3, 10,
		"gpmc_a3", "dss_data20", NULL, "gpio_10",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A4, 9,
		"gpmc_a4", "dss_data21", NULL, "gpio_9",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A5, 8,
		"gpmc_a5", "dss_data22", NULL, "gpio_8",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A6, 7,
		"gpmc_a6", "dss_data23", NULL, "gpio_7",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A7, 6,
		"gpmc_a7", NULL, "sys_ndmareq2", "gpio_6",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A8, 5,
		"gpmc_a8", NULL, "sys_ndmareq3", "gpio_5",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_A9, 4,
		"gpmc_a9", NULL, "sys_ndmareq4", "gpio_4",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_CLK, 21,
		"gpmc_clk", NULL, NULL, "gpio_21",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_D10, 18,
		"gpmc_d10", "ssi2_rdy_rx", NULL, "gpio_18",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_D11, 17,
		"gpmc_d11", "ssi2_flag_rx", NULL, "gpio_17",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_D12, 16,
		"gpmc_d12", "ssi2_dat_rx", NULL, "gpio_16",
		NULL, NULL, NULL, NULL),
	_OMAP2420_MUXENTRY(GPMC_D13, 15,
		"gpmc_d13", "ssi2_rdy_tx", NULL, "gpio_15",
