Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / sound / soc / sh / rcar / mix.c
blob195fc7bb22afb6519fb574af7b28832d2defda6b
1 /*
2 * mix.c
4 * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10 #include "rsnd.h"
12 #define MIX_NAME_SIZE 16
13 #define MIX_NAME "mix"
15 struct rsnd_mix {
16 struct rsnd_mod mod;
19 #define rsnd_mix_get(priv, id) ((struct rsnd_mix *)(priv->mix) + id)
20 #define rsnd_mix_nr(priv) ((priv)->mix_nr)
21 #define for_each_rsnd_mix(pos, priv, i) \
22 for ((i) = 0; \
23 ((i) < rsnd_mix_nr(priv)) && \
24 ((pos) = (struct rsnd_mix *)(priv)->mix + i); \
25 i++)
27 static void rsnd_mix_activation(struct rsnd_mod *mod)
29 rsnd_mod_write(mod, MIX_SWRSR, 0);
30 rsnd_mod_write(mod, MIX_SWRSR, 1);
33 static void rsnd_mix_halt(struct rsnd_mod *mod)
35 rsnd_mod_write(mod, MIX_MIXIR, 1);
36 rsnd_mod_write(mod, MIX_SWRSR, 0);
39 static void rsnd_mix_volume_parameter(struct rsnd_dai_stream *io,
40 struct rsnd_mod *mod)
42 rsnd_mod_write(mod, MIX_MDBAR, 0);
43 rsnd_mod_write(mod, MIX_MDBBR, 0);
44 rsnd_mod_write(mod, MIX_MDBCR, 0);
45 rsnd_mod_write(mod, MIX_MDBDR, 0);
48 static void rsnd_mix_volume_init(struct rsnd_dai_stream *io,
49 struct rsnd_mod *mod)
51 rsnd_mod_write(mod, MIX_MIXIR, 1);
53 /* General Information */
54 rsnd_mod_write(mod, MIX_ADINR, rsnd_runtime_channel_after_ctu(io));
56 /* volume step */
57 rsnd_mod_write(mod, MIX_MIXMR, 0);
58 rsnd_mod_write(mod, MIX_MVPDR, 0);
60 /* common volume parameter */
61 rsnd_mix_volume_parameter(io, mod);
63 rsnd_mod_write(mod, MIX_MIXIR, 0);
66 static void rsnd_mix_volume_update(struct rsnd_dai_stream *io,
67 struct rsnd_mod *mod)
69 /* Disable MIX dB setting */
70 rsnd_mod_write(mod, MIX_MDBER, 0);
72 /* common volume parameter */
73 rsnd_mix_volume_parameter(io, mod);
75 /* Enable MIX dB setting */
76 rsnd_mod_write(mod, MIX_MDBER, 1);
79 static int rsnd_mix_probe_(struct rsnd_mod *mod,
80 struct rsnd_dai_stream *io,
81 struct rsnd_priv *priv)
83 return rsnd_cmd_attach(io, rsnd_mod_id(mod));
86 static int rsnd_mix_init(struct rsnd_mod *mod,
87 struct rsnd_dai_stream *io,
88 struct rsnd_priv *priv)
90 rsnd_mod_power_on(mod);
92 rsnd_mix_activation(mod);
94 rsnd_mix_volume_init(io, mod);
96 rsnd_mix_volume_update(io, mod);
98 return 0;
101 static int rsnd_mix_quit(struct rsnd_mod *mod,
102 struct rsnd_dai_stream *io,
103 struct rsnd_priv *priv)
105 rsnd_mix_halt(mod);
107 rsnd_mod_power_off(mod);
109 return 0;
112 static struct rsnd_mod_ops rsnd_mix_ops = {
113 .name = MIX_NAME,
114 .probe = rsnd_mix_probe_,
115 .init = rsnd_mix_init,
116 .quit = rsnd_mix_quit,
119 struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
121 if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv)))
122 id = 0;
124 return rsnd_mod_get(rsnd_mix_get(priv, id));
127 int rsnd_mix_probe(struct rsnd_priv *priv)
129 struct device_node *node;
130 struct device_node *np;
131 struct device *dev = rsnd_priv_to_dev(priv);
132 struct rsnd_mix *mix;
133 struct clk *clk;
134 char name[MIX_NAME_SIZE];
135 int i, nr, ret;
137 /* This driver doesn't support Gen1 at this point */
138 if (rsnd_is_gen1(priv))
139 return 0;
141 node = rsnd_mix_of_node(priv);
142 if (!node)
143 return 0; /* not used is not error */
145 nr = of_get_child_count(node);
146 if (!nr) {
147 ret = -EINVAL;
148 goto rsnd_mix_probe_done;
151 mix = devm_kzalloc(dev, sizeof(*mix) * nr, GFP_KERNEL);
152 if (!mix) {
153 ret = -ENOMEM;
154 goto rsnd_mix_probe_done;
157 priv->mix_nr = nr;
158 priv->mix = mix;
160 i = 0;
161 ret = 0;
162 for_each_child_of_node(node, np) {
163 mix = rsnd_mix_get(priv, i);
165 snprintf(name, MIX_NAME_SIZE, "%s.%d",
166 MIX_NAME, i);
168 clk = devm_clk_get(dev, name);
169 if (IS_ERR(clk)) {
170 ret = PTR_ERR(clk);
171 goto rsnd_mix_probe_done;
174 ret = rsnd_mod_init(priv, rsnd_mod_get(mix), &rsnd_mix_ops,
175 clk, rsnd_mod_get_status, RSND_MOD_MIX, i);
176 if (ret)
177 goto rsnd_mix_probe_done;
179 i++;
182 rsnd_mix_probe_done:
183 of_node_put(node);
185 return ret;
188 void rsnd_mix_remove(struct rsnd_priv *priv)
190 struct rsnd_mix *mix;
191 int i;
193 for_each_rsnd_mix(mix, priv, i) {
194 rsnd_mod_quit(rsnd_mod_get(mix));