msm: footswitch-8x60: Move SoC-specific data to device files

The number of footswitch-related differences between SoCs (such as clocks
and bus ports) is large enough that it no longer makes sense to treat
them as exceptions in footswitch_probe().

Instead of using cpu_is_xxx() to manage these differences, move all
SoC-specific data to the SoC-specific device files and pass it to the
footswitch driver through platform data.

Change-Id: I30e2ec885e0340e4efec2bc5adc3fdd255cc7bb0
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
diff --git a/arch/arm/mach-msm/footswitch-8x60.c b/arch/arm/mach-msm/footswitch-8x60.c
index eb334b9..72361a6 100644
--- a/arch/arm/mach-msm/footswitch-8x60.c
+++ b/arch/arm/mach-msm/footswitch-8x60.c
@@ -21,10 +21,8 @@
 #include <linux/regulator/machine.h>
 #include <linux/clk.h>
 #include <mach/msm_iomap.h>
-#include <mach/msm_bus_board.h>
 #include <mach/msm_bus.h>
 #include <mach/scm-io.h>
-#include <mach/socinfo.h>
 #include "clock.h"
 #include "footswitch.h"
 
@@ -51,6 +49,8 @@
 #define ENABLE_BIT		BIT(8)
 #define RETENTION_BIT		BIT(9)
 
+#define GFS_DELAY_CNT		31
+
 #define RESET_DELAY_US		1
 /* Clock rate to use if one has not previously been set. */
 #define DEFAULT_RATE		27000000
@@ -62,14 +62,6 @@
  */
 static DEFINE_MUTEX(claim_lock);
 
-struct clk_data {
-	const char *name;
-	struct clk *clk;
-	unsigned long rate;
-	unsigned long reset_rate;
-	bool enabled;
-};
-
 struct footswitch {
 	struct regulator_dev	*rdev;
 	struct regulator_desc	desc;
@@ -77,15 +69,14 @@
 	int			bus_port0, bus_port1;
 	bool			is_enabled;
 	bool			is_claimed;
-	struct clk_data		*clk_data;
+	struct fs_clk_data	*clk_data;
 	struct clk		*core_clk;
-	unsigned int		gfs_delay_cnt:5;
 };
 
 static int setup_clocks(struct footswitch *fs)
 {
 	int rc = 0;
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 	long rate;
 
 	/*
@@ -124,7 +115,7 @@
 
 static void restore_clocks(struct footswitch *fs)
 {
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 
 	/* Restore clocks to their orignal states before setup_clocks(). */
 	for (clock = fs->clk_data; clock->clk; clock++) {
@@ -146,7 +137,7 @@
 static int footswitch_enable(struct regulator_dev *rdev)
 {
 	struct footswitch *fs = rdev_get_drvdata(rdev);
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 	uint32_t regval, rc = 0;
 
 	mutex_lock(&claim_lock);
@@ -232,7 +223,7 @@
 static int footswitch_disable(struct regulator_dev *rdev)
 {
 	struct footswitch *fs = rdev_get_drvdata(rdev);
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 	uint32_t regval, rc = 0;
 
 	/* Return early if already disabled. */
@@ -308,7 +299,7 @@
 static int gfx2d_footswitch_enable(struct regulator_dev *rdev)
 {
 	struct footswitch *fs = rdev_get_drvdata(rdev);
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 	uint32_t regval, rc = 0;
 
 	mutex_lock(&claim_lock);
@@ -384,7 +375,7 @@
 static int gfx2d_footswitch_disable(struct regulator_dev *rdev)
 {
 	struct footswitch *fs = rdev_get_drvdata(rdev);
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 	uint32_t regval, rc = 0;
 
 	/* Return early if already disabled. */
@@ -461,108 +452,7 @@
 	.disable = gfx2d_footswitch_disable,
 };
 
-/*
- * Lists of required clocks for the collapse and restore sequences.
- *
- * Order matters here. Clocks are listed in the same order as their
- * resets will be de-asserted when the core is restored. Also, rate-
- * settable clocks must be listed before any of the branches that
- * are derived from them. Otherwise, the branches may fail to enable
- * if their parent's rate is not yet set.
- */
-
-static struct clk_data gfx2d0_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ 0 }
-};
-
-static struct clk_data gfx2d1_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ 0 }
-};
-
-static struct clk_data gfx3d_8660_clks[] = {
-	{ .name = "core_clk", .reset_rate = 27000000 },
-	{ .name = "iface_clk" },
-	{ 0 }
-};
-
-static struct clk_data gfx3d_8064_clks[] = {
-	{ .name = "core_clk", .reset_rate = 27000000 },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data ijpeg_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data mdp_8960_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ .name = "vsync_clk" },
-	{ .name = "lut_clk" },
-	{ .name = "tv_src_clk" },
-	{ .name = "tv_clk" },
-	{ 0 }
-};
-
-static struct clk_data mdp_8660_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ .name = "vsync_clk" },
-	{ .name = "tv_src_clk" },
-	{ .name = "tv_clk" },
-	{ .name = "pixel_mdp_clk" },
-	{ .name = "pixel_lcdc_clk" },
-	{ 0 }
-};
-
-static struct clk_data rot_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data ved_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data vfe_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data vpe_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-static struct clk_data vcap_clks[] = {
-	{ .name = "core_clk" },
-	{ .name = "iface_clk" },
-	{ .name = "bus_clk" },
-	{ 0 }
-};
-
-#define FOOTSWITCH(_id, _name, _ops, _gfs_ctl_reg, _dc, _clk_data, \
-		   _bp1, _bp2) \
+#define FOOTSWITCH(_id, _name, _ops, _gfs_ctl_reg) \
 	[(_id)] = { \
 		.desc = { \
 			.id = (_id), \
@@ -572,51 +462,26 @@
 			.owner = THIS_MODULE, \
 		}, \
 		.gfs_ctl_reg = (_gfs_ctl_reg), \
-		.gfs_delay_cnt = (_dc), \
-		.clk_data = (_clk_data), \
-		.bus_port0 = (_bp1), \
-		.bus_port1 = (_bp2), \
 	}
 static struct footswitch footswitches[] = {
-	FOOTSWITCH(FS_GFX2D0, "fs_gfx2d0", &gfx2d_fs_ops,
-		GFX2D0_GFS_CTL_REG, 31, gfx2d0_clks,
-		MSM_BUS_MASTER_GRAPHICS_2D_CORE0, 0),
-	FOOTSWITCH(FS_GFX2D1, "fs_gfx2d1", &gfx2d_fs_ops,
-		GFX2D1_GFS_CTL_REG, 31, gfx2d1_clks,
-		MSM_BUS_MASTER_GRAPHICS_2D_CORE1, 0),
-	FOOTSWITCH(FS_GFX3D, "fs_gfx3d", &standard_fs_ops,
-		GFX3D_GFS_CTL_REG, 31, gfx3d_8660_clks,
-		MSM_BUS_MASTER_GRAPHICS_3D, 0),
-	FOOTSWITCH(FS_IJPEG, "fs_ijpeg", &standard_fs_ops,
-		GEMINI_GFS_CTL_REG, 31, ijpeg_clks,
-		MSM_BUS_MASTER_JPEG_ENC, 0),
-	FOOTSWITCH(FS_MDP, "fs_mdp", &standard_fs_ops,
-		MDP_GFS_CTL_REG, 31, NULL,
-		MSM_BUS_MASTER_MDP_PORT0,
-		MSM_BUS_MASTER_MDP_PORT1),
-	FOOTSWITCH(FS_ROT, "fs_rot", &standard_fs_ops,
-		ROT_GFS_CTL_REG, 31, rot_clks,
-		MSM_BUS_MASTER_ROTATOR, 0),
-	FOOTSWITCH(FS_VED, "fs_ved", &standard_fs_ops,
-		VED_GFS_CTL_REG, 31, ved_clks,
-		MSM_BUS_MASTER_HD_CODEC_PORT0,
-		MSM_BUS_MASTER_HD_CODEC_PORT1),
-	FOOTSWITCH(FS_VFE, "fs_vfe", &standard_fs_ops,
-		VFE_GFS_CTL_REG, 31, vfe_clks,
-		MSM_BUS_MASTER_VFE, 0),
-	FOOTSWITCH(FS_VPE, "fs_vpe", &standard_fs_ops,
-		VPE_GFS_CTL_REG, 31, vpe_clks,
-		MSM_BUS_MASTER_VPE, 0),
-	FOOTSWITCH(FS_VCAP, "fs_vcap", &standard_fs_ops,
-		VCAP_GFS_CTL_REG, 31, vcap_clks,
-		MSM_BUS_MASTER_VIDEO_CAP, 0),
+	FOOTSWITCH(FS_GFX2D0, "fs_gfx2d0", &gfx2d_fs_ops, GFX2D0_GFS_CTL_REG),
+	FOOTSWITCH(FS_GFX2D1, "fs_gfx2d1", &gfx2d_fs_ops, GFX2D1_GFS_CTL_REG),
+	FOOTSWITCH(FS_GFX3D,  "fs_gfx3d", &standard_fs_ops, GFX3D_GFS_CTL_REG),
+	FOOTSWITCH(FS_IJPEG,  "fs_ijpeg", &standard_fs_ops, GEMINI_GFS_CTL_REG),
+	FOOTSWITCH(FS_MDP,    "fs_mdp",   &standard_fs_ops, MDP_GFS_CTL_REG),
+	FOOTSWITCH(FS_ROT,    "fs_rot",   &standard_fs_ops, ROT_GFS_CTL_REG),
+	FOOTSWITCH(FS_VED,    "fs_ved",   &standard_fs_ops, VED_GFS_CTL_REG),
+	FOOTSWITCH(FS_VFE,    "fs_vfe",   &standard_fs_ops, VFE_GFS_CTL_REG),
+	FOOTSWITCH(FS_VPE,    "fs_vpe",   &standard_fs_ops, VPE_GFS_CTL_REG),
+	FOOTSWITCH(FS_VCAP,   "fs_vcap",  &standard_fs_ops, VCAP_GFS_CTL_REG),
 };
 
 static int footswitch_probe(struct platform_device *pdev)
 {
 	struct footswitch *fs;
 	struct regulator_init_data *init_data;
-	struct clk_data *clock;
+	struct fs_driver_data *driver_data;
+	struct fs_clk_data *clock;
 	uint32_t regval, rc = 0;
 
 	if (pdev == NULL)
@@ -625,29 +490,12 @@
 	if (pdev->id >= MAX_FS)
 		return -ENODEV;
 
-	fs = &footswitches[pdev->id];
 	init_data = pdev->dev.platform_data;
-
-	if (pdev->id == FS_MDP) {
-		if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064())
-			fs->clk_data = mdp_8960_clks;
-		else
-			fs->clk_data = mdp_8660_clks;
-	} else if (pdev->id == FS_GFX3D) {
-		if (cpu_is_apq8064()) {
-			fs->clk_data = gfx3d_8064_clks;
-			fs->bus_port1 = MSM_BUS_MASTER_GRAPHICS_3D_PORT1;
-		} else if (cpu_is_msm8930()) {
-			fs->clk_data = gfx3d_8064_clks;
-		} else {
-			fs->clk_data = gfx3d_8660_clks;
-		}
-	} else if (pdev->id == FS_VED) {
-		if (cpu_is_apq8064()) {
-			fs->bus_port0 = MSM_BUS_MASTER_VIDEO_ENC;
-			fs->bus_port1 = MSM_BUS_MASTER_VIDEO_DEC;
-		}
-	}
+	driver_data = init_data->driver_data;
+	fs = &footswitches[pdev->id];
+	fs->clk_data = driver_data->clks;
+	fs->bus_port0 = driver_data->bus_port0;
+	fs->bus_port1 = driver_data->bus_port1;
 
 	for (clock = fs->clk_data; clock->name; clock++) {
 		clock->clk = clk_get(&pdev->dev, clock->name);
@@ -667,7 +515,7 @@
 	 * clear so disabling the footswitch will power-collapse the core.
 	 */
 	regval = readl_relaxed(fs->gfs_ctl_reg);
-	regval |= fs->gfs_delay_cnt;
+	regval |= GFS_DELAY_CNT;
 	regval &= ~RETENTION_BIT;
 	writel_relaxed(regval, fs->gfs_ctl_reg);
 
@@ -692,7 +540,7 @@
 static int __devexit footswitch_remove(struct platform_device *pdev)
 {
 	struct footswitch *fs = &footswitches[pdev->id];
-	struct clk_data *clock;
+	struct fs_clk_data *clock;
 
 	for (clock = fs->clk_data; clock->clk; clock++)
 		clk_put(clock->clk);