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"
16 struct rsnd_ctu_platform_info *info; /* rcar_snd.h */
20 #define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
21 #define for_each_rsnd_ctu(pos, priv, i) \
23 ((i) < rsnd_ctu_nr(priv)) && \
24 ((pos) = (struct rsnd_ctu *)(priv)->ctu + i); \
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_init(struct rsnd_mod *mod,
35 struct rsnd_dai_stream *io,
36 struct rsnd_priv *priv)
38 rsnd_mod_hw_start(mod);
40 rsnd_ctu_initialize_lock(mod);
42 rsnd_mod_write(mod, CTU_ADINR, rsnd_get_adinr_chan(mod, io));
44 rsnd_ctu_initialize_unlock(mod);
49 static int rsnd_ctu_quit(struct rsnd_mod *mod,
50 struct rsnd_dai_stream *io,
51 struct rsnd_priv *priv)
53 rsnd_mod_hw_stop(mod);
58 static struct rsnd_mod_ops rsnd_ctu_ops = {
60 .init = rsnd_ctu_init,
61 .quit = rsnd_ctu_quit,
64 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
66 if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv)))
69 return rsnd_mod_get((struct rsnd_ctu *)(priv->ctu) + id);
72 static void rsnd_of_parse_ctu(struct platform_device *pdev,
73 const struct rsnd_of_data *of_data,
74 struct rsnd_priv *priv)
76 struct device_node *node;
77 struct rsnd_ctu_platform_info *ctu_info;
78 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
79 struct device *dev = &pdev->dev;
85 node = of_get_child_by_name(dev->of_node, "rcar_sound,ctu");
89 nr = of_get_child_count(node);
91 goto rsnd_of_parse_ctu_end;
93 ctu_info = devm_kzalloc(dev,
94 sizeof(struct rsnd_ctu_platform_info) * nr,
97 dev_err(dev, "ctu info allocation error\n");
98 goto rsnd_of_parse_ctu_end;
101 info->ctu_info = ctu_info;
102 info->ctu_info_nr = nr;
104 rsnd_of_parse_ctu_end:
109 int rsnd_ctu_probe(struct platform_device *pdev,
110 const struct rsnd_of_data *of_data,
111 struct rsnd_priv *priv)
113 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
114 struct device *dev = rsnd_priv_to_dev(priv);
115 struct rsnd_ctu *ctu;
117 char name[CTU_NAME_SIZE];
120 /* This driver doesn't support Gen1 at this point */
121 if (rsnd_is_gen1(priv)) {
122 dev_warn(dev, "CTU is not supported on Gen1\n");
126 rsnd_of_parse_ctu(pdev, of_data, priv);
128 nr = info->ctu_info_nr;
132 ctu = devm_kzalloc(dev, sizeof(*ctu) * nr, GFP_KERNEL);
139 for_each_rsnd_ctu(ctu, priv, i) {
141 * CTU00, CTU01, CTU02, CTU03 => CTU0
142 * CTU10, CTU11, CTU12, CTU13 => CTU1
144 snprintf(name, CTU_NAME_SIZE, "%s.%d",
147 clk = devm_clk_get(dev, name);
151 ctu->info = &info->ctu_info[i];
153 ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops,
154 clk, RSND_MOD_CTU, i);
162 void rsnd_ctu_remove(struct platform_device *pdev,
163 struct rsnd_priv *priv)
165 struct rsnd_ctu *ctu;
168 for_each_rsnd_ctu(ctu, priv, i) {
169 rsnd_mod_quit(rsnd_mod_get(ctu));