2019-05-30 07:57:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
2013-03-22 03:56:42 +08:00
|
|
|
else if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA30)
|
2012-04-07 01:15:55 +08:00
|
|
|
new_baseclock = 564480000;
|
2013-03-22 03:56:42 +08:00
|
|
|
else
|
|
|
|
new_baseclock = 282240000;
|
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;
|
2013-03-22 03:56:42 +08:00
|
|
|
else if (data->soc == TEGRA_ASOC_UTILS_SOC_TEGRA30)
|
2012-04-07 01:15:55 +08:00
|
|
|
new_baseclock = 552960000;
|
2013-03-22 03:56:42 +08:00
|
|
|
else
|
|
|
|
new_baseclock = 368640000;
|
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
|
|
|
|
2012-06-05 12:29:42 +08:00
|
|
|
clk_disable_unprepare(data->clk_cdev1);
|
|
|
|
clk_disable_unprepare(data->clk_pll_a_out0);
|
|
|
|
clk_disable_unprepare(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
|
|
|
|
2012-06-05 12:29:42 +08:00
|
|
|
err = clk_prepare_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;
|
|
|
|
}
|
|
|
|
|
2012-06-05 12:29:42 +08:00
|
|
|
err = clk_prepare_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;
|
|
|
|
}
|
|
|
|
|
2012-06-05 12:29:42 +08:00
|
|
|
err = clk_prepare_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
|
|
|
|
2012-12-20 07:17:33 +08:00
|
|
|
int tegra_asoc_utils_set_ac97_rate(struct tegra_asoc_utils_data *data)
|
|
|
|
{
|
|
|
|
const int pll_rate = 73728000;
|
|
|
|
const int ac97_rate = 24576000;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
clk_disable_unprepare(data->clk_cdev1);
|
|
|
|
clk_disable_unprepare(data->clk_pll_a_out0);
|
|
|
|
clk_disable_unprepare(data->clk_pll_a);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AC97 rate is fixed at 24.576MHz and is used for both the host
|
|
|
|
* controller and the external codec
|
|
|
|
*/
|
|
|
|
err = clk_set_rate(data->clk_pll_a, pll_rate);
|
|
|
|
if (err) {
|
|
|
|
dev_err(data->dev, "Can't set pll_a rate: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = clk_set_rate(data->clk_pll_a_out0, ac97_rate);
|
|
|
|
if (err) {
|
|
|
|
dev_err(data->dev, "Can't set pll_a_out0 rate: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
|
|
|
|
|
|
|
|
err = clk_prepare_enable(data->clk_pll_a);
|
|
|
|
if (err) {
|
|
|
|
dev_err(data->dev, "Can't enable pll_a: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = clk_prepare_enable(data->clk_pll_a_out0);
|
|
|
|
if (err) {
|
|
|
|
dev_err(data->dev, "Can't enable pll_a_out0: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = clk_prepare_enable(data->clk_cdev1);
|
|
|
|
if (err) {
|
|
|
|
dev_err(data->dev, "Can't enable cdev1: %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->set_baseclock = pll_rate;
|
|
|
|
data->set_mclk = ac97_rate;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_ac97_rate);
|
|
|
|
|
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-11 03:11:17 +08:00
|
|
|
if (of_machine_is_compatible("nvidia,tegra20"))
|
2012-04-07 01:15:55 +08:00
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA20;
|
|
|
|
else if (of_machine_is_compatible("nvidia,tegra30"))
|
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA30;
|
2013-05-14 03:26:12 +08:00
|
|
|
else if (of_machine_is_compatible("nvidia,tegra114"))
|
2013-03-22 03:56:42 +08:00
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA114;
|
2013-10-12 05:43:17 +08:00
|
|
|
else if (of_machine_is_compatible("nvidia,tegra124"))
|
|
|
|
data->soc = TEGRA_ASOC_UTILS_SOC_TEGRA124;
|
2013-05-14 03:26:12 +08:00
|
|
|
else {
|
2013-03-22 03:56:42 +08:00
|
|
|
dev_err(data->dev, "SoC unknown to Tegra ASoC utils\n");
|
2012-04-07 01:15:55 +08:00
|
|
|
return -EINVAL;
|
2013-03-22 03:56:42 +08:00
|
|
|
}
|
2012-04-07 01:15:55 +08:00
|
|
|
|
2013-05-14 03:26:12 +08:00
|
|
|
data->clk_pll_a = clk_get(dev, "pll_a");
|
2011-01-29 05:26:40 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:26:12 +08:00
|
|
|
data->clk_pll_a_out0 = clk_get(dev, "pll_a_out0");
|
2011-01-29 05:26:40 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-05-14 03:26:12 +08:00
|
|
|
data->clk_cdev1 = clk_get(dev, "mclk");
|
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");
|