/*
 * Copyright (C) 2009 Nokia
 * Copyright (C) 2009 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 _OMAP3_MUXENTRY(M0, g, m0, m1, m2, m3, m4, m5, m6, m7)		\
{									\
	.reg_offset	= (OMAP3_CONTROL_PADCONF_##M0##_OFFSET),	\
	.gpio		= (g),						\
	.muxnames	= { m0, m1, m2, m3, m4, m5, m6, m7 },		\
}

#else

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

#endif

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

/*
 * Superset of all mux modes for omap3
 */
static struct omap_mux __initdata omap3_muxmodes[] = {
	_OMAP3_MUXENTRY(CAM_D0, 99,
		"cam_d0", NULL, NULL, NULL,
		"gpio_99", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D1, 100,
		"cam_d1", NULL, NULL, NULL,
		"gpio_100", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D10, 109,
		"cam_d10", NULL, NULL, NULL,
		"gpio_109", "hw_dbg8", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D11, 110,
		"cam_d11", NULL, NULL, NULL,
		"gpio_110", "hw_dbg9", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D2, 101,
		"cam_d2", NULL, NULL, NULL,
		"gpio_101", "hw_dbg4", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D3, 102,
		"cam_d3", NULL, NULL, NULL,
		"gpio_102", "hw_dbg5", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D4, 103,
		"cam_d4", NULL, NULL, NULL,
		"gpio_103", "hw_dbg6", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D5, 104,
		"cam_d5", NULL, NULL, NULL,
		"gpio_104", "hw_dbg7", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D6, 105,
		"cam_d6", NULL, NULL, NULL,
		"gpio_105", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D7, 106,
		"cam_d7", NULL, NULL, NULL,
		"gpio_106", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D8, 107,
		"cam_d8", NULL, NULL, NULL,
		"gpio_107", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_D9, 108,
		"cam_d9", NULL, NULL, NULL,
		"gpio_108", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_FLD, 98,
		"cam_fld", NULL, "cam_global_reset", NULL,
		"gpio_98", "hw_dbg3", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_HS, 94,
		"cam_hs", NULL, NULL, NULL,
		"gpio_94", "hw_dbg0", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_PCLK, 97,
		"cam_pclk", NULL, NULL, NULL,
		"gpio_97", "hw_dbg2", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_STROBE, 126,
		"cam_strobe", NULL, NULL, NULL,
		"gpio_126", "hw_dbg11", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_VS, 95,
		"cam_vs", NULL, NULL, NULL,
		"gpio_95", "hw_dbg1", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_WEN, 167,
		"cam_wen", NULL, "cam_shutter", NULL,
		"gpio_167", "hw_dbg10", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_XCLKA, 96,
		"cam_xclka", NULL, NULL, NULL,
		"gpio_96", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CAM_XCLKB, 111,
		"cam_xclkb", NULL, NULL, NULL,
		"gpio_111", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CSI2_DX0, 112,
		"csi2_dx0", NULL, NULL, NULL,
		"gpio_112", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CSI2_DX1, 114,
		"csi2_dx1", NULL, NULL, NULL,
		"gpio_114", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CSI2_DY0, 113,
		"csi2_dy0", NULL, NULL, NULL,
		"gpio_113", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(CSI2_DY1, 115,
		"csi2_dy1", NULL, NULL, NULL,
		"gpio_115", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_ACBIAS, 69,
		"dss_acbias", NULL, NULL, NULL,
		"gpio_69", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA0, 70,
		"dss_data0", NULL, "uart1_cts", NULL,
		"gpio_70", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA1, 71,
		"dss_data1", NULL, "uart1_rts", NULL,
		"gpio_71", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA10, 80,
		"dss_data10", NULL, NULL, NULL,
		"gpio_80", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA11, 81,
		"dss_data11", NULL, NULL, NULL,
		"gpio_81", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA12, 82,
		"dss_data12", NULL, NULL, NULL,
		"gpio_82", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA13, 83,
		"dss_data13", NULL, NULL, NULL,
		"gpio_83", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA14, 84,
		"dss_data14", NULL, NULL, NULL,
		"gpio_84", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA15, 85,
		"dss_data15", NULL, NULL, NULL,
		"gpio_85", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA16, 86,
		"dss_data16", NULL, NULL, NULL,
		"gpio_86", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA17, 87,
		"dss_data17", NULL, NULL, NULL,
		"gpio_87", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA18, 88,
		"dss_data18", NULL, "mcspi3_clk", "dss_data0",
		"gpio_88", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA19, 89,
		"dss_data19", NULL, "mcspi3_simo", "dss_data1",
		"gpio_89", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA20, 90,
		"dss_data20", NULL, "mcspi3_somi", "dss_data2",
		"gpio_90", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA21, 91,
		"dss_data21", NULL, "mcspi3_cs0", "dss_data3",
		"gpio_91", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA22, 92,
		"dss_data22", NULL, "mcspi3_cs1", "dss_data4",
		"gpio_92", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA23, 93,
		"dss_data23", NULL, NULL, "dss_data5",
		"gpio_93", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA2, 72,
		"dss_data2", NULL, NULL, NULL,
		"gpio_72", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA3, 73,
		"dss_data3", NULL, NULL, NULL,
		"gpio_73", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA4, 74,
		"dss_data4", NULL, "uart3_rx_irrx", NULL,
		"gpio_74", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA5, 75,
		"dss_data5", NULL, "uart3_tx_irtx", NULL,
		"gpio_75", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA6, 76,
		"dss_data6", NULL, "uart1_tx", NULL,
		"gpio_76", "hw_dbg14", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA7, 77,
		"dss_data7", NULL, "uart1_rx", NULL,
		"gpio_77", "hw_dbg15", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA8, 78,
		"dss_data8", NULL, NULL, NULL,
		"gpio_78", "hw_dbg16", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_DATA9, 79,
		"dss_data9", NULL, NULL, NULL,
		"gpio_79", "hw_dbg17", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_HSYNC, 67,
		"dss_hsync", NULL, NULL, NULL,
		"gpio_67", "hw_dbg13", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_PCLK, 66,
		"dss_pclk", NULL, NULL, NULL,
		"gpio_66", "hw_dbg12", NULL, "safe_mode"),
	_OMAP3_MUXENTRY(DSS_VSYNC, 68,
		"dss_vsync", NULL, NULL, NULL,
		"gpio_68", NULL, NULL, "safe_mode"),
	_OMAP3_MUXENTRY(ETK_CLK, 12,
		"etk_clk", "mcbsp5_clkx", "sdmmc3_clk", "hsusb1_stp",
		"gpio_12", "mm1_rxdp", "hsusb1_tll_stp", "hw_dbg0"),
	_OMAP3_MUXENTRY(ETK_CTL, 13,
		"etk_ctl", NULL, "sdmmc3_cmd", "hsusb1_clk",
		"gpio_13", NULL, "hsusb1_tll_clk", "hw_dbg1"),
	_OMAP3_MUXENTRY(ETK_D0, 14,
		"etk_d0", "mcspi3_simo", "sdmmc3_dat4", "hsusb1_data0",
		"gpio_14", "mm1_rxrcv", "hsusb1_tll_data0", "hw_dbg2"),
	_OMAP3_MUXENTRY(ETK_D1, 15,
		"etk_d1", "mcspi3_somi", NULL, "hsusb1_data1",
		"gpio_15", "mm1_txse0", "hsusb1_tll_data1", "hw_dbg3"),
	_OMAP3_MUXENTRY(ETK_D10, 24,
		"etk_d10", NULL, "uart1_rx", "hsusb2_clk",
		"gpio_24", NULL, "hsusb2_tll_clk", "hw_dbg12"),
	_OMAP3_MUXENTRY(ETK_D11, 25,
		"etk_d11", NULL, NULL, "hsusb2_stp",
		"gpio_25", "mm2_rxdp", "hsusb2_tll_stp", "hw_dbg13"),
	_OMAP3_MUXENTRY(ETK_D12, 26,
