2 * Renesas R-Car SSIU support
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 SSIU_NAME "ssiu"
18 #define rsnd_ssiu_nr(priv) ((priv)->ssiu_nr)
19 #define for_each_rsnd_ssiu(pos, priv, i) \
21 (i < rsnd_ssiu_nr(priv)) && \
22 ((pos) = ((struct rsnd_ssiu *)(priv)->ssiu + i)); \
25 static int rsnd_ssiu_init(struct rsnd_mod
*mod
,
26 struct rsnd_dai_stream
*io
,
27 struct rsnd_priv
*priv
)
29 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
30 u32 multi_ssi_slaves
= rsnd_ssi_multi_slaves_runtime(io
);
31 int use_busif
= rsnd_ssi_use_busif(io
);
32 int id
= rsnd_mod_id(mod
);
43 rsnd_mod_write(mod
, SSI_SYS_STATUS0
, 0xf << (id
* 4));
44 rsnd_mod_write(mod
, SSI_SYS_STATUS2
, 0xf << (id
* 4));
45 rsnd_mod_write(mod
, SSI_SYS_STATUS4
, 0xf << (id
* 4));
46 rsnd_mod_write(mod
, SSI_SYS_STATUS6
, 0xf << (id
* 4));
49 rsnd_mod_write(mod
, SSI_SYS_STATUS1
, 0xf << 4);
50 rsnd_mod_write(mod
, SSI_SYS_STATUS3
, 0xf << 4);
51 rsnd_mod_write(mod
, SSI_SYS_STATUS5
, 0xf << 4);
52 rsnd_mod_write(mod
, SSI_SYS_STATUS7
, 0xf << 4);
59 rsnd_mod_bset(mod
, SSI_MODE0
, (1 << id
), !use_busif
<< id
);
64 mask1
= (1 << 4) | (1 << 20); /* mask sync bit */
65 mask2
= (1 << 4); /* mask sync bit */
67 if (rsnd_ssi_is_pin_sharing(io
)) {
84 mask1
|= 0x3 << shift
;
85 val1
= rsnd_rdai_is_clk_master(rdai
) ?
86 0x2 << shift
: 0x1 << shift
;
88 } else if (multi_ssi_slaves
) {
93 switch (multi_ssi_slaves
) {
94 case 0x0206: /* SSI0/1/2/9 */
95 val2
= (1 << 4) | /* SSI0129 sync */
96 (rsnd_rdai_is_clk_master(rdai
) ? 0x2 : 0x1);
98 case 0x0006: /* SSI0/1/2 */
99 val1
= rsnd_rdai_is_clk_master(rdai
) ?
102 if (!val2
) /* SSI012 sync */
107 rsnd_mod_bset(mod
, SSI_MODE1
, mask1
, val1
);
108 rsnd_mod_bset(mod
, SSI_MODE2
, mask2
, val2
);
113 static struct rsnd_mod_ops rsnd_ssiu_ops_gen1
= {
115 .init
= rsnd_ssiu_init
,
118 static int rsnd_ssiu_init_gen2(struct rsnd_mod
*mod
,
119 struct rsnd_dai_stream
*io
,
120 struct rsnd_priv
*priv
)
124 ret
= rsnd_ssiu_init(mod
, io
, priv
);
128 if (rsnd_runtime_is_ssi_tdm(io
)) {
132 * rsnd_ssi_config_init()
134 rsnd_mod_write(mod
, SSI_MODE
, 0x1);
137 if (rsnd_ssi_use_busif(io
)) {
138 rsnd_mod_write(mod
, SSI_BUSIF_ADINR
,
139 rsnd_get_adinr_bit(mod
, io
) |
140 (rsnd_io_is_play(io
) ?
141 rsnd_runtime_channel_after_ctu(io
) :
142 rsnd_runtime_channel_original(io
)));
143 rsnd_mod_write(mod
, SSI_BUSIF_MODE
, 1);
144 rsnd_mod_write(mod
, SSI_BUSIF_DALIGN
,
145 rsnd_get_dalign(mod
, io
));
151 static int rsnd_ssiu_start_gen2(struct rsnd_mod
*mod
,
152 struct rsnd_dai_stream
*io
,
153 struct rsnd_priv
*priv
)
155 if (!rsnd_ssi_use_busif(io
))
158 rsnd_mod_write(mod
, SSI_CTRL
, 0x1);
160 if (rsnd_ssi_multi_slaves_runtime(io
))
161 rsnd_mod_write(mod
, SSI_CONTROL
, 0x1);
166 static int rsnd_ssiu_stop_gen2(struct rsnd_mod
*mod
,
167 struct rsnd_dai_stream
*io
,
168 struct rsnd_priv
*priv
)
170 if (!rsnd_ssi_use_busif(io
))
173 rsnd_mod_write(mod
, SSI_CTRL
, 0);
175 if (rsnd_ssi_multi_slaves_runtime(io
))
176 rsnd_mod_write(mod
, SSI_CONTROL
, 0);
181 static struct rsnd_mod_ops rsnd_ssiu_ops_gen2
= {
183 .init
= rsnd_ssiu_init_gen2
,
184 .start
= rsnd_ssiu_start_gen2
,
185 .stop
= rsnd_ssiu_stop_gen2
,
188 static struct rsnd_mod
*rsnd_ssiu_mod_get(struct rsnd_priv
*priv
, int id
)
190 if (WARN_ON(id
< 0 || id
>= rsnd_ssiu_nr(priv
)))
193 return rsnd_mod_get((struct rsnd_ssiu
*)(priv
->ssiu
) + id
);
196 int rsnd_ssiu_attach(struct rsnd_dai_stream
*io
,
197 struct rsnd_mod
*ssi_mod
)
199 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
200 struct rsnd_mod
*mod
= rsnd_ssiu_mod_get(priv
, rsnd_mod_id(ssi_mod
));
202 rsnd_mod_confirm_ssi(ssi_mod
);
204 return rsnd_dai_connect(mod
, io
, mod
->type
);
207 int rsnd_ssiu_probe(struct rsnd_priv
*priv
)
209 struct device
*dev
= rsnd_priv_to_dev(priv
);
210 struct rsnd_ssiu
*ssiu
;
211 static struct rsnd_mod_ops
*ops
;
214 /* same number to SSI */
216 ssiu
= devm_kzalloc(dev
, sizeof(*ssiu
) * nr
, GFP_KERNEL
);
223 if (rsnd_is_gen1(priv
))
224 ops
= &rsnd_ssiu_ops_gen1
;
226 ops
= &rsnd_ssiu_ops_gen2
;
228 for_each_rsnd_ssiu(ssiu
, priv
, i
) {
229 ret
= rsnd_mod_init(priv
, rsnd_mod_get(ssiu
),
230 ops
, NULL
, rsnd_mod_get_status
,
239 void rsnd_ssiu_remove(struct rsnd_priv
*priv
)
241 struct rsnd_ssiu
*ssiu
;
244 for_each_rsnd_ssiu(ssiu
, priv
, i
) {
245 rsnd_mod_quit(rsnd_mod_get(ssiu
));