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 CTU_NAME_SIZE 16
13 #define CTU_NAME "ctu"
19 #define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
20 #define for_each_rsnd_ctu(pos, priv, i) \
22 ((i) < rsnd_ctu_nr(priv)) && \
23 ((pos) = (struct rsnd_ctu *)(priv)->ctu + i); \
26 #define rsnd_ctu_get(priv, id) ((struct rsnd_ctu *)(priv->ctu) + id)
27 #define rsnd_ctu_initialize_lock(mod) __rsnd_ctu_initialize_lock(mod, 1)
28 #define rsnd_ctu_initialize_unlock(mod) __rsnd_ctu_initialize_lock(mod, 0)
29 static void __rsnd_ctu_initialize_lock(struct rsnd_mod *mod, u32 enable)
31 rsnd_mod_write(mod, CTU_CTUIR, enable);
34 static int rsnd_ctu_probe_(struct rsnd_mod *mod,
35 struct rsnd_dai_stream *io,
36 struct rsnd_priv *priv)
38 return rsnd_cmd_attach(io, rsnd_mod_id(mod) / 4);
41 static int rsnd_ctu_init(struct rsnd_mod *mod,
42 struct rsnd_dai_stream *io,
43 struct rsnd_priv *priv)
45 rsnd_mod_power_on(mod);
47 rsnd_ctu_initialize_lock(mod);
49 rsnd_mod_write(mod, CTU_ADINR, rsnd_get_adinr_chan(mod, io));
51 rsnd_ctu_initialize_unlock(mod);
56 static int rsnd_ctu_quit(struct rsnd_mod *mod,
57 struct rsnd_dai_stream *io,
58 struct rsnd_priv *priv)
60 rsnd_mod_power_off(mod);
65 static struct rsnd_mod_ops rsnd_ctu_ops = {
67 .probe = rsnd_ctu_probe_,
68 .init = rsnd_ctu_init,
69 .quit = rsnd_ctu_quit,
72 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
74 if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv)))
77 return rsnd_mod_get(rsnd_ctu_get(priv, id));
80 int rsnd_ctu_probe(struct rsnd_priv *priv)
82 struct device_node *node;
83 struct device_node *np;
84 struct device *dev = rsnd_priv_to_dev(priv);
87 char name[CTU_NAME_SIZE];
90 /* This driver doesn't support Gen1 at this point */
91 if (rsnd_is_gen1(priv))
94 node = rsnd_ctu_of_node(priv);
96 return 0; /* not used is not error */
98 nr = of_get_child_count(node);
101 goto rsnd_ctu_probe_done;
104 ctu = devm_kzalloc(dev, sizeof(*ctu) * nr, GFP_KERNEL);
107 goto rsnd_ctu_probe_done;
115 for_each_child_of_node(node, np) {
116 ctu = rsnd_ctu_get(priv, i);
119 * CTU00, CTU01, CTU02, CTU03 => CTU0
120 * CTU10, CTU11, CTU12, CTU13 => CTU1
122 snprintf(name, CTU_NAME_SIZE, "%s.%d",
125 clk = devm_clk_get(dev, name);
128 goto rsnd_ctu_probe_done;
131 ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops,
132 clk, RSND_MOD_CTU, i);
134 goto rsnd_ctu_probe_done;
146 void rsnd_ctu_remove(struct rsnd_priv *priv)
148 struct rsnd_ctu *ctu;
151 for_each_rsnd_ctu(ctu, priv, i) {
152 rsnd_mod_quit(rsnd_mod_get(ctu));