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 = { ...@@ -28,6 +28,7 @@ static struct rsnd_mod_ops adg_ops = {
struct rsnd_adg { struct rsnd_adg {
struct clk *clk[CLKMAX]; struct clk *clk[CLKMAX];
struct clk *clkout[CLKOUTMAX]; struct clk *clkout[CLKOUTMAX];
struct clk *null_clk;
struct clk_onecell_data onecell; struct clk_onecell_data onecell;
struct rsnd_mod mod; struct rsnd_mod mod;
int clk_rate[CLKMAX]; int clk_rate[CLKMAX];
...@@ -363,76 +364,103 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate) ...@@ -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) void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable)
{ {
struct rsnd_adg *adg = rsnd_priv_to_adg(priv); struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk; struct clk *clk;
int i; int i;
for_each_rsnd_clk(clk, adg, i) { for_each_rsnd_clk(clk, adg, i) {
if (enable) { if (enable) {
int ret = clk_prepare_enable(clk); clk_prepare_enable(clk);
/* /*
* We shouldn't use clk_get_rate() under * We shouldn't use clk_get_rate() under
* atomic context. Let's keep it when * atomic context. Let's keep it when
* rsnd_adg_clk_enable() was called * rsnd_adg_clk_enable() was called
*/ */
adg->clk_rate[i] = 0; adg->clk_rate[i] = clk_get_rate(clk);
if (ret < 0)
dev_warn(dev, "can't use clk %d\n", i);
else
adg->clk_rate[i] = clk_get_rate(clk);
} else { } else {
if (adg->clk_rate[i]) clk_disable_unprepare(clk);
clk_disable_unprepare(clk);
adg->clk_rate[i] = 0;
} }
} }
} }
#define NULL_CLK "rsnd_adg_null" static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv,
static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv) const char * const name,
const char *parent)
{ {
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
if (!priv->null_hw) { clk = clk_register_fixed_rate(dev, name, parent, 0, 0);
struct clk_hw *_hw; if (IS_ERR(clk)) {
int ret; dev_err(dev, "create null clk error\n");
return NULL;
}
_hw = clk_hw_register_fixed_rate_with_accuracy(dev, NULL_CLK, NULL, 0, 0, 0); return clk;
if (IS_ERR(_hw)) }
return NULL;
static struct clk *rsnd_adg_null_clk_get(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, _hw); if (!adg->null_clk) {
if (ret < 0) static const char * const name = "rsnd_adg_null";
clk_hw_unregister_fixed_rate(_hw);
priv->null_hw = _hw; 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_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 void rsnd_adg_get_clkin(struct rsnd_priv *priv, static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
struct rsnd_adg *adg)
{ {
struct rsnd_adg *adg = priv->adg;
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
int i; int i;
for (i = 0; i < CLKMAX; 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)) if (IS_ERR(clk))
clk = rsnd_adg_null_clk_get(priv); clk = rsnd_adg_null_clk_get(priv);
if (IS_ERR(clk)) if (IS_ERR(clk))
dev_err(dev, "no adg clock (%s)\n", clk_name[i]); goto err;
adg->clk[i] = clk; 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_get_clkout(struct rsnd_priv *priv, static void rsnd_adg_unregister_clkout(struct rsnd_priv *priv)
struct rsnd_adg *adg)
{ {
struct rsnd_adg *adg = priv->adg;
struct clk *clk;
int i;
for_each_rsnd_clkout(clk, adg, i)
clk_unregister_fixed_rate(clk);
}
static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
struct clk *clk; struct clk *clk;
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
...@@ -472,9 +500,8 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, ...@@ -472,9 +500,8 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
req_size = prop->length / sizeof(u32); req_size = prop->length / sizeof(u32);
if (req_size > REQ_SIZE) { if (req_size > REQ_SIZE) {
dev_err(dev, dev_err(dev, "too many clock-frequency\n");
"too many clock-frequency, use top %d\n", REQ_SIZE); return -EINVAL;
req_size = REQ_SIZE;
} }
of_property_read_u32_array(np, "clock-frequency", req_rate, req_size); of_property_read_u32_array(np, "clock-frequency", req_rate, req_size);
...@@ -555,10 +582,11 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, ...@@ -555,10 +582,11 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
if (!count) { if (!count) {
clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT],
parent_clk_name, 0, req_rate[0]); parent_clk_name, 0, req_rate[0]);
if (!IS_ERR(clk)) { if (IS_ERR(clk))
adg->clkout[CLKOUT] = clk; goto err;
of_clk_add_provider(np, of_clk_src_simple_get, clk);
} adg->clkout[CLKOUT] = clk;
of_clk_add_provider(np, of_clk_src_simple_get, clk);
} }
/* /*
* for clkout0/1/2/3 * for clkout0/1/2/3
...@@ -568,8 +596,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, ...@@ -568,8 +596,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
clk = clk_register_fixed_rate(dev, clkout_name[i], clk = clk_register_fixed_rate(dev, clkout_name[i],
parent_clk_name, 0, parent_clk_name, 0,
req_rate[0]); req_rate[0]);
if (!IS_ERR(clk)) if (IS_ERR(clk))
adg->clkout[i] = clk; goto err;
adg->clkout[i] = clk;
} }
adg->onecell.clks = adg->clkout; adg->onecell.clks = adg->clkout;
adg->onecell.clk_num = CLKOUTMAX; adg->onecell.clk_num = CLKOUTMAX;
...@@ -581,9 +611,19 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, ...@@ -581,9 +611,19 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
adg->ckr = ckr; adg->ckr = ckr;
adg->rbga = rbga; adg->rbga = rbga;
adg->rbgb = rbgb; 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) #if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
__printf(3, 4)
static void dbg_msg(struct device *dev, struct seq_file *m, static void dbg_msg(struct device *dev, struct seq_file *m,
const char *fmt, ...) const char *fmt, ...)
{ {
...@@ -643,11 +683,16 @@ int rsnd_adg_probe(struct rsnd_priv *priv) ...@@ -643,11 +683,16 @@ int rsnd_adg_probe(struct rsnd_priv *priv)
if (ret) if (ret)
return ret; return ret;
rsnd_adg_get_clkin(priv, adg);
rsnd_adg_get_clkout(priv, adg);
priv->adg = 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_enable(priv);
rsnd_adg_clk_dbg_info(priv, NULL); rsnd_adg_clk_dbg_info(priv, NULL);
...@@ -658,17 +703,13 @@ void rsnd_adg_remove(struct rsnd_priv *priv) ...@@ -658,17 +703,13 @@ void rsnd_adg_remove(struct rsnd_priv *priv)
{ {
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *np = dev->of_node; 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) rsnd_adg_unregister_clkout(priv);
if (adg->clkout[i])
clk_unregister_fixed_rate(adg->clkout[i]);
if (priv->null_hw)
clk_hw_unregister_fixed_rate(priv->null_hw);
of_clk_del_provider(np); of_clk_del_provider(np);
rsnd_adg_clk_disable(priv); 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 { ...@@ -364,19 +364,13 @@ struct rsnd_mod {
/* /*
* status * status
* *
* 0xH0000CB0 * 0xH000DCB0
* *
* B 0: init 1: quit * B 0: init 1: quit
* C 0: start 1: stop * C 0: start 1: stop
* D 0: hw_params 1: hw_free * D 0: hw_params 1: hw_free
* *
* H is always called (see __rsnd_mod_call) * 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_init 4
#define __rsnd_mod_shift_quit 4 #define __rsnd_mod_shift_quit 4
...@@ -412,16 +406,16 @@ struct rsnd_mod { ...@@ -412,16 +406,16 @@ struct rsnd_mod {
#define __rsnd_mod_call_remove 0 #define __rsnd_mod_call_remove 0
#define __rsnd_mod_call_prepare 0 #define __rsnd_mod_call_prepare 0
#define __rsnd_mod_call_cleanup 0 #define __rsnd_mod_call_cleanup 0
#define __rsnd_mod_call_init 0 #define __rsnd_mod_call_init 0 /* needs protect */
#define __rsnd_mod_call_quit 1 #define __rsnd_mod_call_quit 1 /* needs protect */
#define __rsnd_mod_call_start 0 #define __rsnd_mod_call_start 0 /* needs protect */
#define __rsnd_mod_call_stop 1 #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_irq 0
#define __rsnd_mod_call_pcm_new 0 #define __rsnd_mod_call_pcm_new 0
#define __rsnd_mod_call_fallback 0 #define __rsnd_mod_call_fallback 0
#define __rsnd_mod_call_hw_params 0
#define __rsnd_mod_call_pointer 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_to_priv(mod) ((mod)->priv)
#define rsnd_mod_power_on(mod) clk_enable((mod)->clk) #define rsnd_mod_power_on(mod) clk_enable((mod)->clk)
...@@ -646,7 +640,6 @@ struct rsnd_priv { ...@@ -646,7 +640,6 @@ struct rsnd_priv {
* below value will be filled on rsnd_adg_probe() * below value will be filled on rsnd_adg_probe()
*/ */
void *adg; void *adg;
struct clk_hw *null_hw;
/* /*
* below value will be filled on rsnd_dma_probe() * 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