Commit efaab615 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: rsnd: use clkin/out_size

Current adg.c is assuming number of clkin/clkout are fixed, but it is
not correct on Gen4. This patch uses clkin/out_size to handling it.

This is prepare for R-Car Gen4 support.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87v8km5em7.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent da2f9e85
...@@ -32,6 +32,8 @@ struct rsnd_adg { ...@@ -32,6 +32,8 @@ struct rsnd_adg {
struct clk_onecell_data onecell; struct clk_onecell_data onecell;
struct rsnd_mod mod; struct rsnd_mod mod;
int clkin_rate[CLKINMAX]; int clkin_rate[CLKINMAX];
int clkin_size;
int clkout_size;
u32 ckr; u32 ckr;
u32 rbga; u32 rbga;
u32 rbgb; u32 rbgb;
...@@ -42,24 +44,24 @@ struct rsnd_adg { ...@@ -42,24 +44,24 @@ struct rsnd_adg {
#define for_each_rsnd_clkin(pos, adg, i) \ #define for_each_rsnd_clkin(pos, adg, i) \
for (i = 0; \ for (i = 0; \
(i < CLKINMAX) && \ (i < adg->clkin_size) && \
((pos) = adg->clkin[i]); \ ((pos) = adg->clkin[i]); \
i++) i++)
#define for_each_rsnd_clkout(pos, adg, i) \ #define for_each_rsnd_clkout(pos, adg, i) \
for (i = 0; \ for (i = 0; \
(i < CLKOUTMAX) && \ (i < adg->clkout_size) && \
((pos) = adg->clkout[i]); \ ((pos) = adg->clkout[i]); \
i++) i++)
#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg) #define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
static const char * const clkin_name[] = { static const char * const clkin_name_gen2[] = {
[CLKA] = "clk_a", [CLKA] = "clk_a",
[CLKB] = "clk_b", [CLKB] = "clk_b",
[CLKC] = "clk_c", [CLKC] = "clk_c",
[CLKI] = "clk_i", [CLKI] = "clk_i",
}; };
static const char * const clkout_name[] = { static const char * const clkout_name_gen2[] = {
[CLKOUT] = "audio_clkout", [CLKOUT] = "audio_clkout",
[CLKOUT1] = "audio_clkout1", [CLKOUT1] = "audio_clkout1",
[CLKOUT2] = "audio_clkout2", [CLKOUT2] = "audio_clkout2",
...@@ -424,9 +426,14 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv) ...@@ -424,9 +426,14 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
struct rsnd_adg *adg = priv->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; struct clk *clk;
const char * const *clkin_name;
int clkin_size;
int i; int i;
for (i = 0; i < CLKINMAX; i++) { clkin_name = clkin_name_gen2;
clkin_size = ARRAY_SIZE(clkin_name_gen2);
for (i = 0; i < clkin_size; i++) {
clk = devm_clk_get(dev, clkin_name[i]); clk = devm_clk_get(dev, clkin_name[i]);
if (IS_ERR_OR_NULL(clk)) if (IS_ERR_OR_NULL(clk))
...@@ -437,6 +444,8 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv) ...@@ -437,6 +444,8 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
adg->clkin[i] = clk; adg->clkin[i] = clk;
} }
adg->clkin_size = clkin_size;
return 0; return 0;
err: err:
...@@ -470,8 +479,10 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -470,8 +479,10 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
u32 req_rate[REQ_SIZE] = {}; u32 req_rate[REQ_SIZE] = {};
uint32_t count = 0; uint32_t count = 0;
unsigned long req_48kHz_rate, req_441kHz_rate; unsigned long req_48kHz_rate, req_441kHz_rate;
int clkout_size;
int i, req_size; int i, req_size;
const char *parent_clk_name = NULL; const char *parent_clk_name = NULL;
const char * const *clkout_name;
int brg_table[] = { int brg_table[] = {
[CLKA] = 0x0, [CLKA] = 0x0,
[CLKB] = 0x1, [CLKB] = 0x1,
...@@ -555,6 +566,9 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -555,6 +566,9 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
} }
} }
clkout_name = clkout_name_gen2;
clkout_size = ARRAY_SIZE(clkout_name_gen2);
/* /*
* ADG supports BRRA/BRRB output only. * ADG supports BRRA/BRRB output only.
* this means all clkout0/1/2/3 will be * same rate * this means all clkout0/1/2/3 will be * same rate
...@@ -571,13 +585,14 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -571,13 +585,14 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
goto err; goto err;
adg->clkout[CLKOUT] = clk; adg->clkout[CLKOUT] = clk;
adg->clkout_size = 1;
of_clk_add_provider(np, of_clk_src_simple_get, clk); of_clk_add_provider(np, of_clk_src_simple_get, clk);
} }
/* /*
* for clkout0/1/2/3 * for clkout0/1/2/3
*/ */
else { else {
for (i = 0; i < CLKOUTMAX; i++) { for (i = 0; i < clkout_size; i++) {
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]);
...@@ -587,7 +602,8 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -587,7 +602,8 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
adg->clkout[i] = clk; adg->clkout[i] = clk;
} }
adg->onecell.clks = adg->clkout; adg->onecell.clks = adg->clkout;
adg->onecell.clk_num = CLKOUTMAX; adg->onecell.clk_num = clkout_size;
adg->clkout_size = clkout_size;
of_clk_add_provider(np, of_clk_src_onecell_get, of_clk_add_provider(np, of_clk_src_onecell_get,
&adg->onecell); &adg->onecell);
} }
......
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