msm: pil-q6v4: Migrate to clk APIs for XO voting

Use the clock APIs instead of the msm_xo APIs to vote on CXO and
PXO. This removes one more msm specific api from this driver and
will allow us to move XO control into the rpm clock driver.

Change-Id: I57cece3891eef8a8dace1a8465dbe3737ccd0e27
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
diff --git a/arch/arm/mach-msm/clock-8960.c b/arch/arm/mach-msm/clock-8960.c
index e16cac5..a2abb25 100644
--- a/arch/arm/mach-msm/clock-8960.c
+++ b/arch/arm/mach-msm/clock-8960.c
@@ -4812,13 +4812,16 @@
 };
 
 static struct clk_lookup msm_clocks_8064[] = {
-	CLK_LOOKUP("cxo",		cxo_clk.c,		NULL),
-	CLK_LOOKUP("cxo",		cxo_clk.c,		"wcnss_wlan.0"),
-	CLK_LOOKUP("cxo",		cxo_clk.c,		"pil_riva"),
-	CLK_LOOKUP("pll2",		pll2_clk.c,		NULL),
-	CLK_LOOKUP("pll8",		pll8_clk.c,		NULL),
-	CLK_LOOKUP("pll4",		pll4_clk.c,		NULL),
-	CLK_LOOKUP("measure",		measure_clk.c,		"debug"),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	NULL),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	"wcnss_wlan.0"),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	"pil_riva"),
+	CLK_LOOKUP("xo",		pxo_clk.c,	"pil_qdsp6v4.0"),
+	CLK_LOOKUP("xo",		cxo_clk.c,	"pil_qdsp6v4.1"),
+	CLK_LOOKUP("xo",		cxo_clk.c,	"pil_qdsp6v4.2"),
+	CLK_LOOKUP("pll2",		pll2_clk.c,	NULL),
+	CLK_LOOKUP("pll8",		pll8_clk.c,	NULL),
+	CLK_LOOKUP("pll4",		pll4_clk.c,	NULL),
+	CLK_LOOKUP("measure",		measure_clk.c,	"debug"),
 
 	CLK_DUMMY("bus_clk",		AFAB_CLK,	"msm_apps_fab", 0),
 	CLK_DUMMY("bus_a_clk",		AFAB_A_CLK,	"msm_apps_fab", 0),
@@ -5051,13 +5054,16 @@
 };
 
 static struct clk_lookup msm_clocks_8960_v1[] __initdata = {
-	CLK_LOOKUP("cxo",		cxo_clk.c,		NULL),
-	CLK_LOOKUP("cxo",		cxo_clk.c,		"wcnss_wlan.0"),
-	CLK_LOOKUP("cxo",		cxo_clk.c,		"pil_riva"),
-	CLK_LOOKUP("pll2",		pll2_clk.c,		NULL),
-	CLK_LOOKUP("pll8",		pll8_clk.c,		NULL),
-	CLK_LOOKUP("pll4",		pll4_clk.c,		NULL),
-	CLK_LOOKUP("measure",		measure_clk.c,		"debug"),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	NULL),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	"wcnss_wlan.0"),
+	CLK_LOOKUP("cxo",		cxo_clk.c,	"pil_riva"),
+	CLK_LOOKUP("xo",		pxo_clk.c,	"pil_qdsp6v4.0"),
+	CLK_LOOKUP("xo",		cxo_clk.c,	"pil_qdsp6v4.1"),
+	CLK_LOOKUP("xo",		cxo_clk.c,	"pil_qdsp6v4.2"),
+	CLK_LOOKUP("pll2",		pll2_clk.c,	NULL),
+	CLK_LOOKUP("pll8",		pll8_clk.c,	NULL),
+	CLK_LOOKUP("pll4",		pll4_clk.c,	NULL),
+	CLK_LOOKUP("measure",		measure_clk.c,	"debug"),
 
 	CLK_LOOKUP("bus_clk",		afab_clk.c,		"msm_apps_fab"),
 	CLK_LOOKUP("bus_a_clk",		afab_a_clk.c,		"msm_apps_fab"),
diff --git a/arch/arm/mach-msm/devices-8960.c b/arch/arm/mach-msm/devices-8960.c
index 0ced722..872d9d4 100644
--- a/arch/arm/mach-msm/devices-8960.c
+++ b/arch/arm/mach-msm/devices-8960.c
@@ -30,7 +30,6 @@
 #include <mach/rpm.h>
 #include <mach/msm_bus_board.h>
 #include <mach/msm_memtypes.h>
-#include <mach/msm_xo.h>
 #include <sound/msm-dai-q6.h>
 #include <sound/apr_audio.h>
 #include "clock.h"
@@ -843,7 +842,6 @@
 	.strap_ahb_upper = 0x00290000,
 	.strap_ahb_lower = 0x00000280,
 	.aclk_reg = SFAB_LPASS_Q6_ACLK_CTL,
-	.xo_id = MSM_XO_PXO,
 	.name = "q6",
 	.pas_id = PAS_Q6,
 	.bus_port = MSM_BUS_MASTER_LPASS_PROC,
@@ -881,7 +879,6 @@
 	.strap_ahb_lower = 0x00000080,
 	.aclk_reg = SFAB_MSS_Q6_FW_ACLK_CTL,
 	.jtag_clk_reg = MSS_Q6FW_JTAG_CLK_CTL,
-	.xo_id = MSM_XO_CXO,
 	.name = "modem_fw",
 	.depends = "q6",
 	.pas_id = PAS_MODEM_FW,
@@ -919,7 +916,6 @@
 	.strap_ahb_lower = 0x00000080,
 	.aclk_reg = SFAB_MSS_Q6_SW_ACLK_CTL,
 	.jtag_clk_reg = MSS_Q6SW_JTAG_CLK_CTL,
-	.xo_id = MSM_XO_CXO,
 	.name = "modem",
 	.depends = "modem_fw",
 	.pas_id = PAS_MODEM_SW,
diff --git a/arch/arm/mach-msm/pil-q6v4.c b/arch/arm/mach-msm/pil-q6v4.c
index 75606be..511377d 100644
--- a/arch/arm/mach-msm/pil-q6v4.c
+++ b/arch/arm/mach-msm/pil-q6v4.c
@@ -20,10 +20,10 @@
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/workqueue.h>
+#include <linux/clk.h>
 
 #include <mach/msm_bus.h>
 #include <mach/msm_iomap.h>
-#include <mach/msm_xo.h>
 
 #include "peripheral-loader.h"
 #include "pil-q6v4.h"
@@ -71,7 +71,7 @@
 	struct regulator *vreg;
 	struct regulator *pll_supply;
 	bool vreg_enabled;
-	struct msm_xo_voter *xo;
+	struct clk *xo;
 	struct delayed_work work;
 };
 
@@ -89,18 +89,29 @@
 	return 0;
 }
 
-static void pil_q6v4_make_proxy_votes(struct device *dev)
+static int pil_q6v4_make_proxy_votes(struct device *dev)
 {
 	struct q6v4_data *drv = dev_get_drvdata(dev);
 	int ret;
 
-	msm_xo_mode_vote(drv->xo, MSM_XO_MODE_ON);
+	ret = clk_prepare_enable(drv->xo);
+	if (ret) {
+		dev_err(dev, "Failed to enable XO\n");
+		goto err;
+	}
 	if (drv->pll_supply) {
 		ret = regulator_enable(drv->pll_supply);
-		if (ret)
-			dev_err(dev, "failed to enable pll supply\n");
+		if (ret) {
+			dev_err(dev, "Failed to enable pll supply\n");
+			goto err_regulator;
+		}
 	}
 	schedule_delayed_work(&drv->work, msecs_to_jiffies(PROXY_VOTE_TIMEOUT));
+	return 0;
+err_regulator:
+	clk_disable_unprepare(drv->xo);
+err:
+	return ret;
 }
 
 static void pil_q6v4_remove_proxy_votes(struct work_struct *work)
@@ -108,7 +119,7 @@
 	struct q6v4_data *drv = container_of(work, struct q6v4_data, work.work);
 	if (drv->pll_supply)
 		regulator_disable(drv->pll_supply);
-	msm_xo_mode_vote(drv->xo, MSM_XO_MODE_OFF);
+	clk_disable_unprepare(drv->xo);
 }
 
 static void pil_q6v4_remove_proxy_votes_now(struct device *dev)
@@ -191,7 +202,9 @@
 	const struct q6v4_data *drv = dev_get_drvdata(pil->dev);
 	const struct pil_q6v4_pdata *pdata = pil->dev->platform_data;
 
-	pil_q6v4_make_proxy_votes(pil->dev);
+	err = pil_q6v4_make_proxy_votes(pil->dev);
+	if (err)
+		return err;
 
 	err = pil_q6v4_power_up(pil->dev);
 	if (err)
@@ -331,7 +344,9 @@
 	const struct pil_q6v4_pdata *pdata = pil->dev->platform_data;
 	int err;
 
-	pil_q6v4_make_proxy_votes(pil->dev);
+	err = pil_q6v4_make_proxy_votes(pil->dev);
+	if (err)
+		return err;
 
 	err = pil_q6v4_power_up(pil->dev);
 	if (err)
@@ -442,7 +457,7 @@
 		goto err;
 	}
 
-	drv->xo = msm_xo_get(pdata->xo_id, pdata->name);
+	drv->xo = clk_get(&pdev->dev, "xo");
 	if (IS_ERR(drv->xo)) {
 		ret = PTR_ERR(drv->xo);
 		goto err_xo;
@@ -455,7 +470,7 @@
 	return 0;
 err_pil:
 	flush_delayed_work_sync(&drv->work);
-	msm_xo_put(drv->xo);
+	clk_put(drv->xo);
 err_xo:
 	regulator_put(drv->vreg);
 err:
@@ -467,7 +482,7 @@
 {
 	struct q6v4_data *drv = platform_get_drvdata(pdev);
 	flush_delayed_work_sync(&drv->work);
-	msm_xo_put(drv->xo);
+	clk_put(drv->xo);
 	regulator_put(drv->vreg);
 	regulator_put(drv->pll_supply);
 	return 0;
diff --git a/arch/arm/mach-msm/pil-q6v4.h b/arch/arm/mach-msm/pil-q6v4.h
index 54bdf88..b0b97d0 100644
--- a/arch/arm/mach-msm/pil-q6v4.h
+++ b/arch/arm/mach-msm/pil-q6v4.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -18,7 +18,6 @@
 	const unsigned long strap_ahb_lower;
 	void __iomem *aclk_reg;
 	void __iomem *jtag_clk_reg;
-	const int xo_id;
 	const char *name;
 	const char *depends;
 	const unsigned pas_id;