2011-01-08 13:36:15 +08:00
|
|
|
/*
|
|
|
|
* tegra_asoc_utils.c - Harmony machine ASoC driver
|
|
|
|
*
|
|
|
|
* Author: Stephen Warren <swarren@nvidia.com>
|
2012-04-07 01:15:55 +08:00
|
|
|
* Copyright (C) 2010,2012 - NVIDIA, Inc.
|
2011-01-08 13:36:15 +08:00
|
|
|
*
|
|
|
|
* 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-29 05:26:40 +08:00
|
|
|
#include <linux/device.h>
|
2011-01-08 13:36:15 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/kernel.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2012-04-07 01:15:55 +08:00
|
|
|
#include <linux/of.h>
|
2011-01-08 13:36:15 +08:00
|
|
|
|
|
|
|
#include "tegra_asoc_utils.h"
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate,
|
2011-04-20 05:25:09 +08:00
|
|
|
int mclk)
|
2011-01-08 13:36:15 +08:00
|
|
|
{
|
|
|
|
int new_baseclock;
|
2011-04-20 05:25:09 +08:00
|
|
|
bool clk_change;
|
2011-01-08 13:36:15 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
switch (srate) {
|
|
|
|
case 11025:
|
|
|
|
case 22050:
|
|
|
|
case 44100:
|
|
|
|
case 88200:
|
2012-04-07 01:15:55 +08:00
|
|
|
if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
|
|
|
|
new_baseclock = 56448000;
|
|
|
|
else
|
|
|
|
new_baseclock = 564480000;
|
2011-01-08 13:36:15 +08:00
|
|
|
break;
|
|
|
|
case 8000:
|
|
|
|
case 16000:
|
|
|
|
case 32000:
|
|
|
|
case 48000:
|
|
|
|
case 64000:
|
|
|
|
case 96000:
|
2012-04-07 01:15:55 +08:00
|
|
|
if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
|
|
|
|
new_baseclock = 73728000;
|
|
|
|
else
|
|
|
|
new_baseclock = 552960000;
|
2011-01-08 13:36:15 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-04-20 05:25:09 +08:00
|
|
|
clk_change = ((new_baseclock != data->set_baseclock) ||
|
2011-01-29 05:26:40 +08:00
|
|
|
(mclk != data->set_mclk));
|
2011-04-20 05:25:09 +08:00
|
|
|
if (!clk_change)
|
|
|
|
return 0;
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
data->set_baseclock = 0;
|
|
|
|
data->set_mclk = 0;
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
clk_disable(data->clk_cdev1);
|
|
|
|
clk_disable(data->clk_pll_a_out0);
|
|
|
|
clk_disable(data->clk_pll_a);
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
err = clk_set_rate(data->clk_pll_a, new_baseclock);
|
2011-01-08 13:36:15 +08:00
|
|
|
if (err) {
|
2011-01-29 05:26:40 +08:00
|
|
|
dev_err(data->dev, "Can't set pll_a rate: %d\n", err);
|
2011-01-08 13:36:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
err = clk_set_rate(data->clk_pll_a_out0, mclk);
|
2011-01-08 13:36:15 +08:00
|
|
|
if (err) {
|
2011-01-29 05:26:40 +08:00
|
|
|
dev_err(data->dev, "Can't set pll_a_out0 rate: %d\n", err);
|
2011-01-08 13:36:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-04-07 01:15:55 +08:00
|
|
|
/* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
err = clk_enable(data->clk_pll_a);
|
2011-01-08 13:36:15 +08:00
|
|
|
if (err) {
|
2011-01-29 05:26:40 +08:00
|
|
|
dev_err(data->dev, "Can't enable pll_a: %d\n", err);
|
2011-01-08 13:36:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
err = clk_enable(data->clk_pll_a_out0);
|
2011-01-08 13:36:15 +08:00
|
|
|
if (err) {
|
2011-01-29 05:26:40 +08:00
|
|
|
dev_err(data->dev, "Can't enable pll_a_out0: %d\n", err);
|
2011-01-08 13:36:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
err = clk_enable(data->clk_cdev1);
|
2011-01-08 13:36:15 +08:00
|
|
|
if (err) {
|
2011-01-29 05:26:40 +08:00
|
|
|
dev_err(data->dev, "Can't enable cdev1: %d\n", err);
|
2011-01-08 13:36:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
data->set_baseclock = new_baseclock;
|
|
|
|
data->set_mclk = mclk;
|
2011-01-08 13:36:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-23 08:23:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate);
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data,
|
|
|
|
struct device *dev)
|
2011-01-08 13:36:15 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
data->dev = dev;
|
|
|
|
|
2012-04-07 01:15:55 +08:00
|
|
|
if (!of_have_populated_dt())
|
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20;
|
|
|
|
else if (of_machine_is_compatible("nvidia,tegra20"))
|
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20;
|
|
|
|
else if (of_machine_is_compatible("nvidia,tegra30"))
|
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
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 13:36:15 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2011-01-29 05:26:40 +08: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-12 03:48:53 +08:00
|
|
|
goto err_put_pll_a;
|
2011-01-08 13:36:15 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 01:15:55 +08:00
|
|
|
if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA20)
|
|
|
|
data->clk_cdev1 = clk_get_sys(NULL, "cdev1");
|
|
|
|
else
|
|
|
|
data->clk_cdev1 = clk_get_sys("extern1", NULL);
|
2011-01-29 05:26:40 +08:00
|
|
|
if (IS_ERR(data->clk_cdev1)) {
|
|
|
|
dev_err(data->dev, "Can't retrieve clk cdev1\n");
|
|
|
|
ret = PTR_ERR(data->clk_cdev1);
|
2011-01-12 03:48:53 +08:00
|
|
|
goto err_put_pll_a_out0;
|
2011-01-08 13:36:15 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 01:18:16 +08:00
|
|
|
ret = tegra_asoc_utils_set_rate(data, 44100, 256 * 44100);
|
|
|
|
if (ret)
|
|
|
|
goto err_put_cdev1;
|
|
|
|
|
2011-01-08 13:36:15 +08:00
|
|
|
return 0;
|
|
|
|
|
2012-04-07 01:18:16 +08:00
|
|
|
err_put_cdev1:
|
|
|
|
clk_put(data->clk_cdev1);
|
2011-01-12 03:48:53 +08:00
|
|
|
err_put_pll_a_out0:
|
2011-01-29 05:26:40 +08:00
|
|
|
clk_put(data->clk_pll_a_out0);
|
2011-01-12 03:48:53 +08:00
|
|
|
err_put_pll_a:
|
2011-01-29 05:26:40 +08:00
|
|
|
clk_put(data->clk_pll_a);
|
2011-01-08 13:36:15 +08:00
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
2011-02-23 08:23:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_init);
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-01-29 05:26:40 +08:00
|
|
|
void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data)
|
2011-01-08 13:36:15 +08:00
|
|
|
{
|
2011-01-29 05:26:40 +08:00
|
|
|
clk_put(data->clk_cdev1);
|
|
|
|
clk_put(data->clk_pll_a_out0);
|
|
|
|
clk_put(data->clk_pll_a);
|
2011-01-08 13:36:15 +08:00
|
|
|
}
|
2011-02-23 08:23:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini);
|
2011-01-08 13:36:15 +08:00
|
|
|
|
2011-02-23 08:23:56 +08:00
|
|
|
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
|
|
|
|
MODULE_DESCRIPTION("Tegra ASoC utility code");
|
|
|
|
MODULE_LICENSE("GPL");
|