From a50a399b8ba169816d8afae66bfd42fbb65b1973 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 7 Jan 2011 22:36:15 -0700 Subject: ASoC: tegra: Machine utility code Many portions of Tegra ASoC machine drivers will be similar or identical. To avoid cut/paste, this file will act as a repository for all that common code. For now, it solely includes code to reprogram the audio PLL for 44.1KHz- vs. 48KHz-based sample rates. Signed-Off-By: Stephen Warren Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- sound/soc/tegra/tegra_asoc_utils.c | 154 +++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 sound/soc/tegra/tegra_asoc_utils.c (limited to 'sound/soc/tegra/tegra_asoc_utils.c') diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c new file mode 100644 index 0000000..711ab7f --- /dev/null +++ b/sound/soc/tegra/tegra_asoc_utils.c @@ -0,0 +1,154 @@ +/* + * tegra_asoc_utils.c - Harmony machine ASoC driver + * + * Author: Stephen Warren + * 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 +#include +#include + +#include "tegra_asoc_utils.h" + +#define PREFIX "ASoC Tegra: " + +static struct clk *clk_pll_a; +static struct clk *clk_pll_a_out0; +static struct clk *clk_cdev1; + +static int set_baseclock, set_mclk; + +int tegra_asoc_utils_set_rate(int srate, int mclk, int *mclk_change) +{ + int new_baseclock; + 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; + } + + *mclk_change = ((new_baseclock != set_baseclock) || + (mclk != set_mclk)); + if (!*mclk_change) + return 0; + + set_baseclock = 0; + set_mclk = 0; + + clk_disable(clk_cdev1); + clk_disable(clk_pll_a_out0); + clk_disable(clk_pll_a); + + err = clk_set_rate(clk_pll_a, new_baseclock); + if (err) { + pr_err(PREFIX "Can't set pll_a rate: %d\n", err); + return err; + } + + err = clk_set_rate(clk_pll_a_out0, mclk); + if (err) { + pr_err(PREFIX "Can't set pll_a_out0 rate: %d\n", err); + return err; + } + + /* Don't set cdev1 rate; its locked to pll_a_out0 */ + + err = clk_enable(clk_pll_a); + if (err) { + pr_err(PREFIX "Can't enable pll_a: %d\n", err); + return err; + } + + err = clk_enable(clk_pll_a_out0); + if (err) { + pr_err(PREFIX "Can't enable pll_a_out0: %d\n", err); + return err; + } + + err = clk_enable(clk_cdev1); + if (err) { + pr_err(PREFIX "Can't enable cdev1: %d\n", err); + return err; + } + + set_baseclock = new_baseclock; + set_mclk = mclk; + + return 0; +} + +int tegra_asoc_utils_init(void) +{ + int ret; + + clk_pll_a = clk_get_sys(NULL, "pll_a"); + if (IS_ERR_OR_NULL(clk_pll_a)) { + pr_err(PREFIX "Can't retrieve clk pll_a\n"); + ret = PTR_ERR(clk_pll_a); + goto err; + } + + clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0"); + if (IS_ERR_OR_NULL(clk_pll_a_out0)) { + pr_err(PREFIX "Can't retrieve clk pll_a_out0\n"); + ret = PTR_ERR(clk_pll_a_out0); + goto err; + } + + clk_cdev1 = clk_get_sys(NULL, "cdev1"); + if (IS_ERR_OR_NULL(clk_cdev1)) { + pr_err(PREFIX "Can't retrieve clk cdev1\n"); + ret = PTR_ERR(clk_cdev1); + goto err; + } + + return 0; + +err: + if (!IS_ERR_OR_NULL(clk_cdev1)) + clk_put(clk_cdev1); + if (!IS_ERR_OR_NULL(clk_pll_a_out0)) + clk_put(clk_pll_a_out0); + if (!IS_ERR_OR_NULL(clk_pll_a)) + clk_put(clk_pll_a); + return ret; +} + +void tegra_asoc_utils_fini(void) +{ + clk_put(clk_cdev1); + clk_put(clk_pll_a_out0); + clk_put(clk_pll_a); +} + -- cgit v1.1 From 422650e65a41a61b2f92396dfa4faa6a4df89913 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 11 Jan 2011 12:48:53 -0700 Subject: ASoC: tegra: s/IS_ERR_OR_NULL/IS_ERR/ for clk_get_sys A recent discussion on linux-arm-kernel noted that the value returned by clk_get_sys is an opaque token, and not strictly a pointer; it is meaningful only to the clock API, clients should not dereference the value, and the clock API must accept any non-IS_ERR value it returned. Hence, only IS_ERR is appropriate to interpret the result, not IS_ERR_OR_NULL. I checked that clk_get_sys in both ASoC's for-next and Tegra's for-next do behave as described; NULL is not returned in the case of error. Signed-off-by: Stephen Warren Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- sound/soc/tegra/tegra_asoc_utils.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'sound/soc/tegra/tegra_asoc_utils.c') diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c index 711ab7f..cfe2ea8 100644 --- a/sound/soc/tegra/tegra_asoc_utils.c +++ b/sound/soc/tegra/tegra_asoc_utils.c @@ -113,35 +113,33 @@ int tegra_asoc_utils_init(void) int ret; clk_pll_a = clk_get_sys(NULL, "pll_a"); - if (IS_ERR_OR_NULL(clk_pll_a)) { + if (IS_ERR(clk_pll_a)) { pr_err(PREFIX "Can't retrieve clk pll_a\n"); ret = PTR_ERR(clk_pll_a); goto err; } clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0"); - if (IS_ERR_OR_NULL(clk_pll_a_out0)) { + if (IS_ERR(clk_pll_a_out0)) { pr_err(PREFIX "Can't retrieve clk pll_a_out0\n"); ret = PTR_ERR(clk_pll_a_out0); - goto err; + goto err_put_pll_a; } clk_cdev1 = clk_get_sys(NULL, "cdev1"); - if (IS_ERR_OR_NULL(clk_cdev1)) { + if (IS_ERR(clk_cdev1)) { pr_err(PREFIX "Can't retrieve clk cdev1\n"); ret = PTR_ERR(clk_cdev1); - goto err; + goto err_put_pll_a_out0; } return 0; +err_put_pll_a_out0: + clk_put(clk_pll_a_out0); +err_put_pll_a: + clk_put(clk_pll_a); err: - if (!IS_ERR_OR_NULL(clk_cdev1)) - clk_put(clk_cdev1); - if (!IS_ERR_OR_NULL(clk_pll_a_out0)) - clk_put(clk_pll_a_out0); - if (!IS_ERR_OR_NULL(clk_pll_a)) - clk_put(clk_pll_a); return ret; } -- cgit v1.1 From d64e57cef0436833cfc9620e350ec6f5b041c9a9 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 28 Jan 2011 14:26:40 -0700 Subject: ASoC: Tegra: utils: Don't use global variables Instead, have the machine driver provide storage for the utility data somehow. For Harmony in particular, store this within struct tegra_harmony, itself referenced by snd_soc_card's drvdata. Signed-off-by: Stephen Warren Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- sound/soc/tegra/tegra_asoc_utils.c | 91 ++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 47 deletions(-) (limited to 'sound/soc/tegra/tegra_asoc_utils.c') diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c index cfe2ea8..cb4fc13 100644 --- a/sound/soc/tegra/tegra_asoc_utils.c +++ b/sound/soc/tegra/tegra_asoc_utils.c @@ -21,20 +21,14 @@ */ #include +#include #include #include #include "tegra_asoc_utils.h" -#define PREFIX "ASoC Tegra: " - -static struct clk *clk_pll_a; -static struct clk *clk_pll_a_out0; -static struct clk *clk_cdev1; - -static int set_baseclock, set_mclk; - -int tegra_asoc_utils_set_rate(int srate, int mclk, int *mclk_change) +int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, + int mclk, int *mclk_change) { int new_baseclock; int err; @@ -58,95 +52,98 @@ int tegra_asoc_utils_set_rate(int srate, int mclk, int *mclk_change) return -EINVAL; } - *mclk_change = ((new_baseclock != set_baseclock) || - (mclk != set_mclk)); + *mclk_change = ((new_baseclock != data->set_baseclock) || + (mclk != data->set_mclk)); if (!*mclk_change) return 0; - set_baseclock = 0; - set_mclk = 0; + data->set_baseclock = 0; + data->set_mclk = 0; - clk_disable(clk_cdev1); - clk_disable(clk_pll_a_out0); - clk_disable(clk_pll_a); + clk_disable(data->clk_cdev1); + clk_disable(data->clk_pll_a_out0); + clk_disable(data->clk_pll_a); - err = clk_set_rate(clk_pll_a, new_baseclock); + err = clk_set_rate(data->clk_pll_a, new_baseclock); if (err) { - pr_err(PREFIX "Can't set pll_a rate: %d\n", err); + dev_err(data->dev, "Can't set pll_a rate: %d\n", err); return err; } - err = clk_set_rate(clk_pll_a_out0, mclk); + err = clk_set_rate(data->clk_pll_a_out0, mclk); if (err) { - pr_err(PREFIX "Can't set pll_a_out0 rate: %d\n", err); + dev_err(data->dev, "Can't set pll_a_out0 rate: %d\n", err); return err; } /* Don't set cdev1 rate; its locked to pll_a_out0 */ - err = clk_enable(clk_pll_a); + err = clk_enable(data->clk_pll_a); if (err) { - pr_err(PREFIX "Can't enable pll_a: %d\n", err); + dev_err(data->dev, "Can't enable pll_a: %d\n", err); return err; } - err = clk_enable(clk_pll_a_out0); + err = clk_enable(data->clk_pll_a_out0); if (err) { - pr_err(PREFIX "Can't enable pll_a_out0: %d\n", err); + dev_err(data->dev, "Can't enable pll_a_out0: %d\n", err); return err; } - err = clk_enable(clk_cdev1); + err = clk_enable(data->clk_cdev1); if (err) { - pr_err(PREFIX "Can't enable cdev1: %d\n", err); + dev_err(data->dev, "Can't enable cdev1: %d\n", err); return err; } - set_baseclock = new_baseclock; - set_mclk = mclk; + data->set_baseclock = new_baseclock; + data->set_mclk = mclk; return 0; } -int tegra_asoc_utils_init(void) +int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, + struct device *dev) { int ret; - clk_pll_a = clk_get_sys(NULL, "pll_a"); - if (IS_ERR(clk_pll_a)) { - pr_err(PREFIX "Can't retrieve clk pll_a\n"); - ret = PTR_ERR(clk_pll_a); + 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); goto err; } - clk_pll_a_out0 = clk_get_sys(NULL, "pll_a_out0"); - if (IS_ERR(clk_pll_a_out0)) { - pr_err(PREFIX "Can't retrieve clk pll_a_out0\n"); - ret = PTR_ERR(clk_pll_a_out0); + 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); goto err_put_pll_a; } - clk_cdev1 = clk_get_sys(NULL, "cdev1"); - if (IS_ERR(clk_cdev1)) { - pr_err(PREFIX "Can't retrieve clk cdev1\n"); - ret = PTR_ERR(clk_cdev1); + 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); goto err_put_pll_a_out0; } return 0; err_put_pll_a_out0: - clk_put(clk_pll_a_out0); + clk_put(data->clk_pll_a_out0); err_put_pll_a: - clk_put(clk_pll_a); + clk_put(data->clk_pll_a); err: return ret; } -void tegra_asoc_utils_fini(void) +void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data) { - clk_put(clk_cdev1); - clk_put(clk_pll_a_out0); - clk_put(clk_pll_a); + clk_put(data->clk_cdev1); + clk_put(data->clk_pll_a_out0); + clk_put(data->clk_pll_a); } -- cgit v1.1 From a3cd50deef7ba7df506af5347764a00b4621d7a7 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 22 Feb 2011 17:23:56 -0700 Subject: ASoC: Tegra: Move utilities to separate module The utilities will be required by every machine driver. Including the utility object directly into every machine driver causes a build failure if the modules are actually built into the kernel, since each will define the symbols exported by the utility file. Solve this by moving the utility object into a separate module. Signed-off-by: Stephen Warren Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- sound/soc/tegra/tegra_asoc_utils.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sound/soc/tegra/tegra_asoc_utils.c') diff --git a/sound/soc/tegra/tegra_asoc_utils.c b/sound/soc/tegra/tegra_asoc_utils.c index cb4fc13..52f0a3f 100644 --- a/sound/soc/tegra/tegra_asoc_utils.c +++ b/sound/soc/tegra/tegra_asoc_utils.c @@ -101,6 +101,7 @@ int tegra_asoc_utils_set_rate(struct tegra_asoc_utils_data *data, int srate, return 0; } +EXPORT_SYMBOL_GPL(tegra_asoc_utils_set_rate); int tegra_asoc_utils_init(struct tegra_asoc_utils_data *data, struct device *dev) @@ -139,6 +140,7 @@ err_put_pll_a: err: return ret; } +EXPORT_SYMBOL_GPL(tegra_asoc_utils_init); void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data) { @@ -146,4 +148,8 @@ void tegra_asoc_utils_fini(struct tegra_asoc_utils_data *data) clk_put(data->clk_pll_a_out0); clk_put(data->clk_pll_a); } +EXPORT_SYMBOL_GPL(tegra_asoc_utils_fini); +MODULE_AUTHOR("Stephen Warren "); +MODULE_DESCRIPTION("Tegra ASoC utility code"); +MODULE_LICENSE("GPL"); -- cgit v1.1