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.
12 #define MIX_NAME_SIZE 16
13 #define MIX_NAME "mix"
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) \
23 ((i) < rsnd_mix_nr(priv)) && \
24 ((pos) = (struct rsnd_mix *)(priv)->mix + 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
,
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
,
51 rsnd_mod_write(mod
, MIX_MIXIR
, 1);
53 /* General Information */
54 rsnd_mod_write(mod
, MIX_ADINR
, rsnd_runtime_channel_after_ctu(io
));
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
,
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
);
101 static int rsnd_mix_quit(struct rsnd_mod
*mod
,
102 struct rsnd_dai_stream
*io
,
103 struct rsnd_priv
*priv
)
107 rsnd_mod_power_off(mod
);
112 static struct rsnd_mod_ops rsnd_mix_ops
= {
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
)))
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
;
134 char name
[MIX_NAME_SIZE
];
137 /* This driver doesn't support Gen1 at this point */
138 if (rsnd_is_gen1(priv
))
141 node
= rsnd_mix_of_node(priv
);
143 return 0; /* not used is not error */
145 nr
= of_get_child_count(node
);
148 goto rsnd_mix_probe_done
;
151 mix
= devm_kzalloc(dev
, sizeof(*mix
) * nr
, GFP_KERNEL
);
154 goto rsnd_mix_probe_done
;
162 for_each_child_of_node(node
, np
) {
163 mix
= rsnd_mix_get(priv
, i
);
165 snprintf(name
, MIX_NAME_SIZE
, "%s.%d",
168 clk
= devm_clk_get(dev
, name
);
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
);
177 goto rsnd_mix_probe_done
;
188 void rsnd_mix_remove(struct rsnd_priv
*priv
)
190 struct rsnd_mix
*mix
;
193 for_each_rsnd_mix(mix
, priv
, i
) {
194 rsnd_mod_quit(rsnd_mod_get(mix
));