Commit f3b3bceb authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: rsnd: tidyup adg and header" from Kuninori Morimoto...

Merge series "ASoC: rsnd: tidyup adg and header" from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

Hi Mark

I noticed that adg can be more clean code.
And rsnd.h header comment was not so good
because patch has been randomly added.

This patch tidyup these.

Kuninori Morimoto (5):
  ASoC: rsnd: adg: supply __printf(x, y) formatting for dbg_msg()
  ASoC: rsnd: adg: tidyup rsnd_adg_get_clkin/out() parameter
  ASoC: rsnd: adg: use more simple method for null_clk
  ASoC: rsnd: adg: check return value for rsnd_adg_get_clkin/out()
  ASoC: rsnd: tidyup __rsnd_mod_xxx macro comments

 sound/soc/sh/rcar/adg.c  | 139 +++++++++++++++++++++++++--------------
 sound/soc/sh/rcar/rsnd.h |  21 ++----
 2 files changed, 97 insertions(+), 63 deletions(-)

--
2.25.1
parents 81aad472 3f4593fb
......@@ -28,6 +28,7 @@ static struct rsnd_mod_ops adg_ops = {
struct rsnd_adg {
struct clk *clk[CLKMAX];
struct clk *clkout[CLKOUTMAX];
struct clk *null_clk;
struct clk_onecell_data onecell;
struct rsnd_mod mod;
int clk_rate[CLKMAX];
......@@ -363,76 +364,103 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate)
void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable)
{
struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
int i;
for_each_rsnd_clk(clk, adg, i) {
if (enable) {
int ret = clk_prepare_enable(clk);
clk_prepare_enable(clk);
/*
* We shouldn't use clk_get_rate() under
* atomic context. Let's keep it when
* rsnd_adg_clk_enable() was called
*/
adg->clk_rate[i] = 0;
if (ret < 0)
dev_warn(dev, "can't use clk %d\n", i);
else
adg->clk_rate[i] = clk_get_rate(clk);
} else {
if (adg->clk_rate[i])
clk_disable_unprepare(clk);
adg->clk_rate[i] = 0;
}
}
}
#define NULL_CLK "rsnd_adg_null"
static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv)
static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv,
const char * const name,
const char *parent)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
if (!priv->null_hw) {
struct clk_hw *_hw;
int ret;
_hw = clk_hw_register_fixed_rate_with_accuracy(dev, NULL_CLK, NULL, 0, 0, 0);
if (IS_ERR(_hw))
clk = clk_register_fixed_rate(dev, name, parent, 0, 0);
if (IS_ERR(clk)) {
dev_err(dev, "create null clk error\n");
return NULL;
}
ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, _hw);
if (ret < 0)
clk_hw_unregister_fixed_rate(_hw);
return clk;
}
priv->null_hw = _hw;
static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
if (!adg->null_clk) {
static const char * const name = "rsnd_adg_null";
adg->null_clk = rsnd_adg_create_null_clk(priv, name, NULL);
}
return clk_hw_get_clk(priv->null_hw, NULL_CLK);
return adg->null_clk;
}
static void rsnd_adg_get_clkin(struct rsnd_priv *priv,
struct rsnd_adg *adg)
static void rsnd_adg_null_clk_clean(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
if (adg->null_clk)
clk_unregister_fixed_rate(adg->null_clk);
}
static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
int i;
for (i = 0; i < CLKMAX; i++) {
struct clk *clk = devm_clk_get(dev, clk_name[i]);
clk = devm_clk_get(dev, clk_name[i]);
if (IS_ERR(clk))
clk = rsnd_adg_null_clk_get(priv);
if (IS_ERR(clk))
dev_err(dev, "no adg clock (%s)\n", clk_name[i]);
goto err;
adg->clk[i] = clk;
}
return 0;
err:
dev_err(dev, "adg clock IN get failed\n");
rsnd_adg_null_clk_clean(priv);
return -EIO;
}
static void rsnd_adg_unregister_clkout(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
struct clk *clk;
int i;
for_each_rsnd_clkout(clk, adg, i)
clk_unregister_fixed_rate(clk);
}
static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
struct rsnd_adg *adg)
static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
struct clk *clk;
struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *np = dev->of_node;
......@@ -472,9 +500,8 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
req_size = prop->length / sizeof(u32);
if (req_size > REQ_SIZE) {
dev_err(dev,
"too many clock-frequency, use top %d\n", REQ_SIZE);
req_size = REQ_SIZE;
dev_err(dev, "too many clock-frequency\n");
return -EINVAL;
}
of_property_read_u32_array(np, "clock-frequency", req_rate, req_size);
......@@ -555,11 +582,12 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
if (!count) {
clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT],
parent_clk_name, 0, req_rate[0]);
if (!IS_ERR(clk)) {
if (IS_ERR(clk))
goto err;
adg->clkout[CLKOUT] = clk;
of_clk_add_provider(np, of_clk_src_simple_get, clk);
}
}
/*
* for clkout0/1/2/3
*/
......@@ -568,7 +596,9 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
clk = clk_register_fixed_rate(dev, clkout_name[i],
parent_clk_name, 0,
req_rate[0]);
if (!IS_ERR(clk))
if (IS_ERR(clk))
goto err;
adg->clkout[i] = clk;
}
adg->onecell.clks = adg->clkout;
......@@ -581,9 +611,19 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
adg->ckr = ckr;
adg->rbga = rbga;
adg->rbgb = rbgb;
return 0;
err:
dev_err(dev, "adg clock OUT get failed\n");
rsnd_adg_unregister_clkout(priv);
return -EIO;
}
#if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
__printf(3, 4)
static void dbg_msg(struct device *dev, struct seq_file *m,
const char *fmt, ...)
{
......@@ -643,11 +683,16 @@ int rsnd_adg_probe(struct rsnd_priv *priv)
if (ret)
return ret;
rsnd_adg_get_clkin(priv, adg);
rsnd_adg_get_clkout(priv, adg);
priv->adg = adg;
ret = rsnd_adg_get_clkin(priv);
if (ret)
return ret;
ret = rsnd_adg_get_clkout(priv);
if (ret)
return ret;
rsnd_adg_clk_enable(priv);
rsnd_adg_clk_dbg_info(priv, NULL);
......@@ -658,17 +703,13 @@ void rsnd_adg_remove(struct rsnd_priv *priv)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *np = dev->of_node;
struct rsnd_adg *adg = priv->adg;
struct clk *clk;
int i;
for_each_rsnd_clkout(clk, adg, i)
if (adg->clkout[i])
clk_unregister_fixed_rate(adg->clkout[i]);
if (priv->null_hw)
clk_hw_unregister_fixed_rate(priv->null_hw);
rsnd_adg_unregister_clkout(priv);
of_clk_del_provider(np);
rsnd_adg_clk_disable(priv);
/* It should be called after rsnd_adg_clk_disable() */
rsnd_adg_null_clk_clean(priv);
}
......@@ -364,19 +364,13 @@ struct rsnd_mod {
/*
* status
*
* 0xH0000CB0
* 0xH000DCB0
*
* B 0: init 1: quit
* C 0: start 1: stop
* D 0: hw_params 1: hw_free
*
* H is always called (see __rsnd_mod_call)
* H 0: probe 1: remove
* H 0: pcm_new
* H 0: fallback
* H 0: pointer
* H 0: prepare
* H 0: cleanup
*/
#define __rsnd_mod_shift_init 4
#define __rsnd_mod_shift_quit 4
......@@ -412,16 +406,16 @@ struct rsnd_mod {
#define __rsnd_mod_call_remove 0
#define __rsnd_mod_call_prepare 0
#define __rsnd_mod_call_cleanup 0
#define __rsnd_mod_call_init 0
#define __rsnd_mod_call_quit 1
#define __rsnd_mod_call_start 0
#define __rsnd_mod_call_stop 1
#define __rsnd_mod_call_init 0 /* needs protect */
#define __rsnd_mod_call_quit 1 /* needs protect */
#define __rsnd_mod_call_start 0 /* needs protect */
#define __rsnd_mod_call_stop 1 /* needs protect */
#define __rsnd_mod_call_hw_params 0 /* needs protect */
#define __rsnd_mod_call_hw_free 1 /* needs protect */
#define __rsnd_mod_call_irq 0
#define __rsnd_mod_call_pcm_new 0
#define __rsnd_mod_call_fallback 0
#define __rsnd_mod_call_hw_params 0
#define __rsnd_mod_call_pointer 0
#define __rsnd_mod_call_hw_free 1
#define rsnd_mod_to_priv(mod) ((mod)->priv)
#define rsnd_mod_power_on(mod) clk_enable((mod)->clk)
......@@ -646,7 +640,6 @@ struct rsnd_priv {
* below value will be filled on rsnd_adg_probe()
*/
void *adg;
struct clk_hw *null_hw;
/*
* below value will be filled on rsnd_dma_probe()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment