2011-01-08 06:36:15 +01:00
|
|
|
/*
|
|
|
|
* tegra_asoc_utils.c - Harmony machine ASoC driver
|
|
|
|
*
|
|
|
|
* Author: Stephen Warren <swarren@nvidia.com>
|
|
|
|
* Copyright (C) 2010 - NVIDIA, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
2011-01-28 22:26:40 +01:00
|
|
|
#include <linux/device.h>
|
2011-01-08 06:36:15 +01:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
|
|
|
#include "tegra_asoc_utils.h"
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
|
2011-04-19 23:25:09 +02:00
|
|
|
int mclk)
|
2011-01-08 06:36:15 +01:00
|
|
|
{
|
|
|
|
int new_baseclock;
|
2011-04-19 23:25:09 +02:00
|
|
|
bool clk_change;
|
2011-01-08 06:36:15 +01:00
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (srate) {
|
|
|
|
case 11025:
|
|
|
|
case 22050:
|
|
|
|
case 44100:
|
|
|
|
case 88200:
|
|
|
|
new_baseclock = 56448000;
|
|
|
|
break;
|
|
|
|
case 8000:
|
|
|
|
case 16000:
|
|
|
|
case 32000:
|
|
|
|
case 48000:
|
|
|
|
case 64000:
|
|
|
|
case 96000:
|
|
|
|
new_baseclock = 73728000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-04-19 23:25:09 +02:00
|
|
|
clk_change = ((new_baseclock != data->set_baseclock) ||
|
2011-01-28 22:26:40 +01:00
|
|
|
(mclk != data->set_mclk));
|
2011-04-19 23:25:09 +02:00
|
|
|
if (!clk_change)
|
|
|
|
return 0;
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
data->set_baseclock = 0;
|
|
|
|
data->set_mclk = 0;
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
clk_disable(data->clk_cdev1);
|
|
|
|
clk_disable(data->clk_pll_a_out0);
|
|
|
|
clk_disable(data->clk_pll_a);
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
err = clk_set_rate(data->clk_pll_a, new_baseclock);
|
2011-01-08 06:36:15 +01:00
|
|
|
if (err) {
|
2011-01-28 22:26:40 +01:00
|
|
|
dev_err(data->dev, "Can't set pll_a rate: %d\n", err);
|
2011-01-08 06:36:15 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
err = clk_set_rate(data->clk_pll_a_out0, mclk);
|
2011-01-08 06:36:15 +01:00
|
|
|
if (err) {
|
2011-01-28 22:26:40 +01:00
|
|
|
dev_err(data->dev, "Can't set pll_a_out0 rate: %d\n", err);
|
2011-01-08 06:36:15 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't set cdev1 rate; its locked to pll_a_out0 */
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
err = clk_enable(data->clk_pll_a);
|
2011-01-08 06:36:15 +01:00
|
|
|
if (err) {
|
2011-01-28 22:26:40 +01:00
|
|
|
dev_err(data->dev, "Can't enable pll_a: %d\n", err);
|
2011-01-08 06:36:15 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
err = clk_enable(data->clk_pll_a_out0);
|
2011-01-08 06:36:15 +01:00
|
|
|
if (err) {
|
2011-01-28 22:26:40 +01:00
|
|
|
dev_err(data->dev, "Can't enable pll_a_out0: %d\n", err);
|
2011-01-08 06:36:15 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
err = clk_enable(data->clk_cdev1);
|
2011-01-08 06:36:15 +01:00
|
|
|
if (err) {
|
2011-01-28 22:26:40 +01:00
|
|
|
dev_err(data->dev, "Can't enable cdev1: %d\n", err);
|
2011-01-08 06:36:15 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
data->set_baseclock = new_baseclock;
|
|
|
|
data->set_mclk = mclk;
|
2011-01-08 06:36:15 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-23 01:23:56 +01:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate);
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
|
|
|
|
struct device *dev)
|
2011-01-08 06:36:15 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
data->dev = dev;
|
|
|
|
|
|
|
|
data->clk_pll_a = clk_get_sys(NULL, "pll_a");
|
|
|
|
if (IS_ERR(data->clk_pll_a)) {
|
|
|
|
dev_err(data->dev, "Can't retrieve clk pll_a\n");
|
|
|
|
ret = PTR_ERR(data->clk_pll_a);
|
2011-01-08 06:36:15 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
data->clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0");
|
|
|
|
if (IS_ERR(data->clk_pll_a_out0)) {
|
|
|
|
dev_err(data->dev, "Can't retrieve clk pll_a_out0\n");
|
|
|
|
ret = PTR_ERR(data->clk_pll_a_out0);
|
2011-01-11 20:48:53 +01:00
|
|
|
goto err_put_pll_a;
|
2011-01-08 06:36:15 +01:00
|
|
|
}
|
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
data->clk_cdev1 = clk_get_sys(NULL, "cdev1");
|
|
|
|
if (IS_ERR(data->clk_cdev1)) {
|
|
|
|
dev_err(data->dev, "Can't retrieve clk cdev1\n");
|
|
|
|
ret = PTR_ERR(data->clk_cdev1);
|
2011-01-11 20:48:53 +01:00
|
|
|
goto err_put_pll_a_out0;
|
2011-01-08 06:36:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2011-01-11 20:48:53 +01:00
|
|
|
err_put_pll_a_out0:
|
2011-01-28 22:26:40 +01:00
|
|
|
clk_put(data->clk_pll_a_out0);
|
2011-01-11 20:48:53 +01:00
|
|
|
err_put_pll_a:
|
2011-01-28 22:26:40 +01:00
|
|
|
clk_put(data->clk_pll_a);
|
2011-01-08 06:36:15 +01:00
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
2011-02-23 01:23:56 +01:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_init);
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-01-28 22:26:40 +01:00
|
|
|
void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data)
|
2011-01-08 06:36:15 +01:00
|
|
|
{
|
2011-01-28 22:26:40 +01:00
|
|
|
clk_put(data->clk_cdev1);
|
|
|
|
clk_put(data->clk_pll_a_out0);
|
|
|
|
clk_put(data->clk_pll_a);
|
2011-01-08 06:36:15 +01:00
|
|
|
}
|
2011-02-23 01:23:56 +01:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini);
|
2011-01-08 06:36:15 +01:00
|
|
|
|
2011-02-23 01:23:56 +01:00
|
|
|
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
|
|
|
|
MODULE_DESCRIPTION("Tegra ASoC utility code");
|
|
|
|
MODULE_LICENSE("GPL");
|