1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car SRU/SCU/SSIU/SSI support
5 // Copyright (C) 2013 Renesas Solutions Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
9 // Kuninori Morimoto <morimoto.kuninori@renesas.com>
12 * Renesas R-Car sound device structure
16 * SRU : Sound Routing Unit
17 * - SRC : Sampling Rate Converter
19 * - CTU : Channel Count Conversion Unit
21 * - DVC : Digital Volume and Mute Function
22 * - SSI : Serial Sound Interface
26 * SCU : Sampling Rate Converter Unit
27 * - SRC : Sampling Rate Converter
29 * - CTU : Channel Count Conversion Unit
31 * - DVC : Digital Volume and Mute Function
32 * SSIU : Serial Sound Interface Unit
33 * - SSI : Serial Sound Interface
41 * | ** this depends on Gen1/Gen2
45 * | ** these depend on data path
46 * | ** gen and platform data control it
50 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
53 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
57 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
60 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
63 * | ** these control ssi
72 * | ** these control src
82 * for_each_rsnd_dai(xx, priv, xx)
83 * rdai[0] => rdai[1] => rdai[2] => ...
85 * for_each_rsnd_mod(xx, rdai, xx)
86 * [mod] => [mod] => [mod] => ...
88 * rsnd_dai_call(xxx, fn )
89 * [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
94 * you can enable below define if you don't need
95 * DAI status debug message when debugging
96 * see rsnd_dbg_dai_call()
98 * #define RSND_DEBUG_NO_DAI_CALL 1
101 #include <linux/pm_runtime.h>
104 #define RSND_RATES SNDRV_PCM_RATE_8000_192000
105 #define RSND_FMTS (SNDRV_PCM_FMTBIT_S8 |\
106 SNDRV_PCM_FMTBIT_S16_LE |\
107 SNDRV_PCM_FMTBIT_S24_LE)
109 static const struct of_device_id rsnd_of_match
[] = {
110 { .compatible
= "renesas,rcar_sound-gen1", .data
= (void *)RSND_GEN1
},
111 { .compatible
= "renesas,rcar_sound-gen2", .data
= (void *)RSND_GEN2
},
112 { .compatible
= "renesas,rcar_sound-gen3", .data
= (void *)RSND_GEN3
},
113 /* Special Handling */
114 { .compatible
= "renesas,rcar_sound-r8a77990", .data
= (void *)(RSND_GEN3
| RSND_SOC_E
) },
117 MODULE_DEVICE_TABLE(of
, rsnd_of_match
);
122 void rsnd_mod_make_sure(struct rsnd_mod
*mod
, enum rsnd_mod_type type
)
124 if (mod
->type
!= type
) {
125 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
126 struct device
*dev
= rsnd_priv_to_dev(priv
);
128 dev_warn(dev
, "%s is not your expected module\n",
133 struct dma_chan
*rsnd_mod_dma_req(struct rsnd_dai_stream
*io
,
134 struct rsnd_mod
*mod
)
136 if (!mod
|| !mod
->ops
|| !mod
->ops
->dma_req
)
139 return mod
->ops
->dma_req(io
, mod
);
142 #define MOD_NAME_NUM 5
143 #define MOD_NAME_SIZE 16
144 char *rsnd_mod_name(struct rsnd_mod
*mod
)
146 static char names
[MOD_NAME_NUM
][MOD_NAME_SIZE
];
148 char *name
= names
[num
];
151 if (num
>= MOD_NAME_NUM
)
155 * Let's use same char to avoid pointlessness memory
156 * Thus, rsnd_mod_name() should be used immediately
159 if ((mod
)->ops
->id_sub
) {
160 snprintf(name
, MOD_NAME_SIZE
, "%s[%d%d]",
163 rsnd_mod_id_sub(mod
));
165 snprintf(name
, MOD_NAME_SIZE
, "%s[%d]",
173 u32
*rsnd_mod_get_status(struct rsnd_mod
*mod
,
174 struct rsnd_dai_stream
*io
,
175 enum rsnd_mod_type type
)
180 int rsnd_mod_id_raw(struct rsnd_mod
*mod
)
185 int rsnd_mod_id(struct rsnd_mod
*mod
)
188 return (mod
)->ops
->id(mod
);
190 return rsnd_mod_id_raw(mod
);
193 int rsnd_mod_id_sub(struct rsnd_mod
*mod
)
195 if ((mod
)->ops
->id_sub
)
196 return (mod
)->ops
->id_sub(mod
);
201 int rsnd_mod_init(struct rsnd_priv
*priv
,
202 struct rsnd_mod
*mod
,
203 struct rsnd_mod_ops
*ops
,
205 enum rsnd_mod_type type
,
208 int ret
= clk_prepare(clk
);
222 void rsnd_mod_quit(struct rsnd_mod
*mod
)
224 clk_unprepare(mod
->clk
);
228 void rsnd_mod_interrupt(struct rsnd_mod
*mod
,
229 void (*callback
)(struct rsnd_mod
*mod
,
230 struct rsnd_dai_stream
*io
))
232 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
233 struct rsnd_dai_stream
*io
;
234 struct rsnd_dai
*rdai
;
237 for_each_rsnd_dai(rdai
, priv
, i
) {
238 io
= &rdai
->playback
;
239 if (mod
== io
->mod
[mod
->type
])
243 if (mod
== io
->mod
[mod
->type
])
248 int rsnd_io_is_working(struct rsnd_dai_stream
*io
)
250 /* see rsnd_dai_stream_init/quit() */
252 return snd_pcm_running(io
->substream
);
257 int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream
*io
,
258 struct snd_pcm_hw_params
*params
)
260 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
263 * params will be added when refine
265 * __rsnd_soc_hw_rule_rate()
266 * __rsnd_soc_hw_rule_channels()
269 return params_channels(params
);
271 return runtime
->channels
;
274 int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream
*io
,
275 struct snd_pcm_hw_params
*params
)
277 int chan
= rsnd_runtime_channel_original_with_params(io
, params
);
278 struct rsnd_mod
*ctu_mod
= rsnd_io_to_mod_ctu(io
);
281 u32 converted_chan
= rsnd_io_converted_chan(io
);
286 * converted_chan will be used for CTU,
288 * User shouldn't use CTU with TDM Split mode.
290 if (rsnd_runtime_is_tdm_split(io
)) {
291 struct device
*dev
= rsnd_priv_to_dev(rsnd_io_to_priv(io
));
293 dev_err(dev
, "CTU and TDM Split should be used\n");
297 return converted_chan
;
303 int rsnd_channel_normalization(int chan
)
305 if (WARN_ON((chan
> 8) || (chan
< 0)))
308 /* TDM Extend Mode needs 8ch */
315 int rsnd_runtime_channel_for_ssi_with_params(struct rsnd_dai_stream
*io
,
316 struct snd_pcm_hw_params
*params
)
318 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
319 int chan
= rsnd_io_is_play(io
) ?
320 rsnd_runtime_channel_after_ctu_with_params(io
, params
) :
321 rsnd_runtime_channel_original_with_params(io
, params
);
324 if (rsnd_runtime_is_multi_ssi(io
))
325 chan
/= rsnd_rdai_ssi_lane_get(rdai
);
327 return rsnd_channel_normalization(chan
);
330 int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream
*io
)
332 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
333 int lane
= rsnd_rdai_ssi_lane_get(rdai
);
334 int chan
= rsnd_io_is_play(io
) ?
335 rsnd_runtime_channel_after_ctu(io
) :
336 rsnd_runtime_channel_original(io
);
338 return (chan
> 2) && (lane
> 1);
341 int rsnd_runtime_is_tdm(struct rsnd_dai_stream
*io
)
343 return rsnd_runtime_channel_for_ssi(io
) >= 6;
346 int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream
*io
)
348 return !!rsnd_flags_has(io
, RSND_STREAM_TDM_SPLIT
);
354 u32
rsnd_get_adinr_bit(struct rsnd_mod
*mod
, struct rsnd_dai_stream
*io
)
356 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
357 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
358 struct device
*dev
= rsnd_priv_to_dev(priv
);
360 switch (snd_pcm_format_width(runtime
->format
)) {
369 dev_warn(dev
, "not supported sample bits\n");
377 u32
rsnd_get_dalign(struct rsnd_mod
*mod
, struct rsnd_dai_stream
*io
)
379 static const u32 dalign_values
[8][2] = {
380 {0x76543210, 0x67452301},
381 {0x00000032, 0x00000023},
382 {0x00007654, 0x00006745},
383 {0x00000076, 0x00000067},
384 {0xfedcba98, 0xefcdab89},
385 {0x000000ba, 0x000000ab},
386 {0x0000fedc, 0x0000efcd},
387 {0x000000fe, 0x000000ef},
390 struct rsnd_mod
*ssiu
= rsnd_io_to_mod_ssiu(io
);
391 struct rsnd_mod
*target
;
392 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
395 * *Hardware* L/R and *Software* L/R are inverted for 16bit data.
399 * We need to care about inversion timing to control
400 * Playback/Capture correctly.
401 * The point is [DVC] needs *Hardware* L/R, [MEM] needs *Software* L/R
403 * sL/R : software L/R
404 * hL/R : hardware L/R
405 * (*) : conversion timing
408 * sL/R (*) hL/R hL/R hL/R hL/R hL/R
409 * [MEM] -> [SRC] -> [DVC] -> [CMD] -> [SSIU] -> [SSI] -> codec
412 * hL/R hL/R hL/R hL/R hL/R (*) sL/R
413 * codec -> [SSI] -> [SSIU] -> [SRC] -> [DVC] -> [CMD] -> [MEM]
415 if (rsnd_io_is_play(io
)) {
416 struct rsnd_mod
*src
= rsnd_io_to_mod_src(io
);
418 target
= src
? src
: ssiu
;
420 struct rsnd_mod
*cmd
= rsnd_io_to_mod_cmd(io
);
422 target
= cmd
? cmd
: ssiu
;
426 id
= rsnd_mod_id_sub(mod
);
428 /* Non target mod or non 16bit needs normal DALIGN */
429 if ((snd_pcm_format_width(runtime
->format
) != 16) ||
432 /* Target mod needs inverted DALIGN when 16bit */
436 return dalign_values
[id
][inv
];
439 u32
rsnd_get_busif_shift(struct rsnd_dai_stream
*io
, struct rsnd_mod
*mod
)
441 enum rsnd_mod_type playback_mods
[] = {
446 enum rsnd_mod_type capture_mods
[] = {
451 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
452 struct rsnd_mod
*tmod
= NULL
;
453 enum rsnd_mod_type
*mods
=
454 rsnd_io_is_play(io
) ?
455 playback_mods
: capture_mods
;
459 * This is needed for 24bit data
460 * We need to shift 8bit
462 * Linux 24bit data is located as 0x00******
463 * HW 24bit data is located as 0x******00
466 if (snd_pcm_format_width(runtime
->format
) != 24)
469 for (i
= 0; i
< ARRAY_SIZE(playback_mods
); i
++) {
470 tmod
= rsnd_io_to_mod(io
, mods
[i
]);
478 if (rsnd_io_is_play(io
))
479 return (0 << 20) | /* shift to Left */
480 (8 << 16); /* 8bit */
482 return (1 << 20) | /* shift to Right */
483 (8 << 16); /* 8bit */
489 struct rsnd_mod
*rsnd_mod_next(int *iterator
,
490 struct rsnd_dai_stream
*io
,
491 enum rsnd_mod_type
*array
,
494 struct rsnd_mod
*mod
;
495 enum rsnd_mod_type type
;
496 int max
= array
? array_size
: RSND_MOD_MAX
;
498 for (; *iterator
< max
; (*iterator
)++) {
499 type
= (array
) ? array
[*iterator
] : *iterator
;
500 mod
= rsnd_io_to_mod(io
, type
);
508 static enum rsnd_mod_type rsnd_mod_sequence
[][RSND_MOD_MAX
] = {
542 static int rsnd_status_update(u32
*status
,
543 int shift
, int add
, int timing
)
545 u32 mask
= 0xF << shift
;
546 u8 val
= (*status
>> shift
) & 0xF;
547 u8 next_val
= (val
+ add
) & 0xF;
548 int func_call
= (val
== timing
);
550 if (next_val
== 0xF) /* underflow case */
553 *status
= (*status
& ~mask
) + (next_val
<< shift
);
558 #define rsnd_dai_call(fn, io, param...) \
560 struct device *dev = rsnd_priv_to_dev(rsnd_io_to_priv(io)); \
561 struct rsnd_mod *mod; \
562 int is_play = rsnd_io_is_play(io); \
564 enum rsnd_mod_type *types = rsnd_mod_sequence[is_play]; \
565 for_each_rsnd_mod_arrays(i, mod, io, types, RSND_MOD_MAX) { \
567 u32 *status = mod->ops->get_status(mod, io, types[i]); \
568 int func_call = rsnd_status_update(status, \
569 __rsnd_mod_shift_##fn, \
570 __rsnd_mod_add_##fn, \
571 __rsnd_mod_call_##fn); \
572 rsnd_dbg_dai_call(dev, "%s\t0x%08x %s\n", \
573 rsnd_mod_name(mod), *status, \
574 (func_call && (mod)->ops->fn) ? #fn : ""); \
575 if (func_call && (mod)->ops->fn) \
576 tmp = (mod)->ops->fn(mod, io, param); \
577 if (tmp && (tmp != -EPROBE_DEFER)) \
578 dev_err(dev, "%s : %s error %d\n", \
579 rsnd_mod_name(mod), #fn, tmp); \
585 int rsnd_dai_connect(struct rsnd_mod
*mod
,
586 struct rsnd_dai_stream
*io
,
587 enum rsnd_mod_type type
)
589 struct rsnd_priv
*priv
;
595 if (io
->mod
[type
] == mod
)
601 priv
= rsnd_mod_to_priv(mod
);
602 dev
= rsnd_priv_to_dev(priv
);
606 dev_dbg(dev
, "%s is connected to io (%s)\n",
608 rsnd_io_is_play(io
) ? "Playback" : "Capture");
613 static void rsnd_dai_disconnect(struct rsnd_mod
*mod
,
614 struct rsnd_dai_stream
*io
,
615 enum rsnd_mod_type type
)
617 io
->mod
[type
] = NULL
;
620 int rsnd_rdai_channels_ctrl(struct rsnd_dai
*rdai
,
623 if (max_channels
> 0)
624 rdai
->max_channels
= max_channels
;
626 return rdai
->max_channels
;
629 int rsnd_rdai_ssi_lane_ctrl(struct rsnd_dai
*rdai
,
633 rdai
->ssi_lane
= ssi_lane
;
635 return rdai
->ssi_lane
;
638 int rsnd_rdai_width_ctrl(struct rsnd_dai
*rdai
, int width
)
641 rdai
->chan_width
= width
;
643 return rdai
->chan_width
;
646 struct rsnd_dai
*rsnd_rdai_get(struct rsnd_priv
*priv
, int id
)
648 if ((id
< 0) || (id
>= rsnd_rdai_nr(priv
)))
651 return priv
->rdai
+ id
;
654 static struct snd_soc_dai_driver
655 *rsnd_daidrv_get(struct rsnd_priv
*priv
, int id
)
657 if ((id
< 0) || (id
>= rsnd_rdai_nr(priv
)))
660 return priv
->daidrv
+ id
;
663 #define rsnd_dai_to_priv(dai) snd_soc_dai_get_drvdata(dai)
664 static struct rsnd_dai
*rsnd_dai_to_rdai(struct snd_soc_dai
*dai
)
666 struct rsnd_priv
*priv
= rsnd_dai_to_priv(dai
);
668 return rsnd_rdai_get(priv
, dai
->id
);
672 * rsnd_soc_dai functions
674 void rsnd_dai_period_elapsed(struct rsnd_dai_stream
*io
)
676 struct snd_pcm_substream
*substream
= io
->substream
;
679 * this function should be called...
681 * - if rsnd_dai_pointer_update() returns true
682 * - without spin lock
685 snd_pcm_period_elapsed(substream
);
688 static void rsnd_dai_stream_init(struct rsnd_dai_stream
*io
,
689 struct snd_pcm_substream
*substream
)
691 io
->substream
= substream
;
694 static void rsnd_dai_stream_quit(struct rsnd_dai_stream
*io
)
696 io
->substream
= NULL
;
700 struct snd_soc_dai
*rsnd_substream_to_dai(struct snd_pcm_substream
*substream
)
702 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
708 struct rsnd_dai_stream
*rsnd_rdai_to_io(struct rsnd_dai
*rdai
,
709 struct snd_pcm_substream
*substream
)
711 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
712 return &rdai
->playback
;
714 return &rdai
->capture
;
717 static int rsnd_soc_dai_trigger(struct snd_pcm_substream
*substream
, int cmd
,
718 struct snd_soc_dai
*dai
)
720 struct rsnd_priv
*priv
= rsnd_dai_to_priv(dai
);
721 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
722 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
726 spin_lock_irqsave(&priv
->lock
, flags
);
729 case SNDRV_PCM_TRIGGER_START
:
730 case SNDRV_PCM_TRIGGER_RESUME
:
731 ret
= rsnd_dai_call(init
, io
, priv
);
733 goto dai_trigger_end
;
735 ret
= rsnd_dai_call(start
, io
, priv
);
737 goto dai_trigger_end
;
739 ret
= rsnd_dai_call(irq
, io
, priv
, 1);
741 goto dai_trigger_end
;
744 case SNDRV_PCM_TRIGGER_STOP
:
745 case SNDRV_PCM_TRIGGER_SUSPEND
:
746 ret
= rsnd_dai_call(irq
, io
, priv
, 0);
748 ret
|= rsnd_dai_call(stop
, io
, priv
);
750 ret
|= rsnd_dai_call(quit
, io
, priv
);
758 spin_unlock_irqrestore(&priv
->lock
, flags
);
763 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
765 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
767 /* set master/slave audio interface */
768 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
769 case SND_SOC_DAIFMT_CBM_CFM
:
770 rdai
->clk_master
= 0;
772 case SND_SOC_DAIFMT_CBS_CFS
:
773 rdai
->clk_master
= 1; /* codec is slave, cpu is master */
780 rdai
->bit_clk_inv
= 0;
781 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
782 case SND_SOC_DAIFMT_I2S
:
784 rdai
->data_alignment
= 0;
785 rdai
->frm_clk_inv
= 0;
787 case SND_SOC_DAIFMT_LEFT_J
:
788 case SND_SOC_DAIFMT_DSP_B
:
790 rdai
->data_alignment
= 0;
791 rdai
->frm_clk_inv
= 1;
793 case SND_SOC_DAIFMT_RIGHT_J
:
795 rdai
->data_alignment
= 1;
796 rdai
->frm_clk_inv
= 1;
798 case SND_SOC_DAIFMT_DSP_A
:
800 rdai
->data_alignment
= 0;
801 rdai
->frm_clk_inv
= 1;
805 /* set clock inversion */
806 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
807 case SND_SOC_DAIFMT_NB_IF
:
808 rdai
->frm_clk_inv
= !rdai
->frm_clk_inv
;
810 case SND_SOC_DAIFMT_IB_NF
:
811 rdai
->bit_clk_inv
= !rdai
->bit_clk_inv
;
813 case SND_SOC_DAIFMT_IB_IF
:
814 rdai
->bit_clk_inv
= !rdai
->bit_clk_inv
;
815 rdai
->frm_clk_inv
= !rdai
->frm_clk_inv
;
817 case SND_SOC_DAIFMT_NB_NF
:
825 static int rsnd_soc_set_dai_tdm_slot(struct snd_soc_dai
*dai
,
826 u32 tx_mask
, u32 rx_mask
,
827 int slots
, int slot_width
)
829 struct rsnd_priv
*priv
= rsnd_dai_to_priv(dai
);
830 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
831 struct device
*dev
= rsnd_priv_to_dev(priv
);
833 switch (slot_width
) {
848 /* TDM Extend Mode */
849 rsnd_rdai_channels_set(rdai
, slots
);
850 rsnd_rdai_ssi_lane_set(rdai
, 1);
851 rsnd_rdai_width_set(rdai
, slot_width
);
854 dev_err(dev
, "unsupported TDM slots (%d)\n", slots
);
861 static unsigned int rsnd_soc_hw_channels_list
[] = {
865 static unsigned int rsnd_soc_hw_rate_list
[] = {
880 static int rsnd_soc_hw_rule(struct rsnd_dai
*rdai
,
881 unsigned int *list
, int list_num
,
882 struct snd_interval
*baseline
, struct snd_interval
*iv
)
884 struct snd_interval p
;
888 snd_interval_any(&p
);
892 for (i
= 0; i
< list_num
; i
++) {
894 if (!snd_interval_test(iv
, list
[i
]))
897 rate
= rsnd_ssi_clk_query(rdai
,
898 baseline
->min
, list
[i
], NULL
);
900 p
.min
= min(p
.min
, list
[i
]);
901 p
.max
= max(p
.max
, list
[i
]);
904 rate
= rsnd_ssi_clk_query(rdai
,
905 baseline
->max
, list
[i
], NULL
);
907 p
.min
= min(p
.min
, list
[i
]);
908 p
.max
= max(p
.max
, list
[i
]);
912 return snd_interval_refine(iv
, &p
);
915 static int rsnd_soc_hw_rule_rate(struct snd_pcm_hw_params
*params
,
916 struct snd_pcm_hw_rule
*rule
)
918 struct snd_interval
*ic_
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
919 struct snd_interval
*ir
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
920 struct snd_interval ic
;
921 struct rsnd_dai_stream
*io
= rule
->private;
922 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
925 * possible sampling rate limitation is same as
926 * 2ch if it supports multi ssi
927 * and same as 8ch if TDM 6ch (see rsnd_ssi_config_init())
931 ic
.max
= rsnd_runtime_channel_for_ssi_with_params(io
, params
);
933 return rsnd_soc_hw_rule(rdai
, rsnd_soc_hw_rate_list
,
934 ARRAY_SIZE(rsnd_soc_hw_rate_list
),
938 static int rsnd_soc_hw_rule_channels(struct snd_pcm_hw_params
*params
,
939 struct snd_pcm_hw_rule
*rule
)
941 struct snd_interval
*ic_
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
942 struct snd_interval
*ir
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
943 struct snd_interval ic
;
944 struct rsnd_dai_stream
*io
= rule
->private;
945 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
948 * possible sampling rate limitation is same as
949 * 2ch if it supports multi ssi
950 * and same as 8ch if TDM 6ch (see rsnd_ssi_config_init())
954 ic
.max
= rsnd_runtime_channel_for_ssi_with_params(io
, params
);
956 return rsnd_soc_hw_rule(rdai
, rsnd_soc_hw_channels_list
,
957 ARRAY_SIZE(rsnd_soc_hw_channels_list
),
961 static const struct snd_pcm_hardware rsnd_pcm_hardware
= {
962 .info
= SNDRV_PCM_INFO_INTERLEAVED
|
963 SNDRV_PCM_INFO_MMAP
|
964 SNDRV_PCM_INFO_MMAP_VALID
,
965 .buffer_bytes_max
= 64 * 1024,
966 .period_bytes_min
= 32,
967 .period_bytes_max
= 8192,
973 static int rsnd_soc_dai_startup(struct snd_pcm_substream
*substream
,
974 struct snd_soc_dai
*dai
)
976 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
977 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
978 struct snd_pcm_hw_constraint_list
*constraint
= &rdai
->constraint
;
979 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
980 unsigned int max_channels
= rsnd_rdai_channels_get(rdai
);
983 rsnd_dai_stream_init(io
, substream
);
987 * It depends on Platform design
989 constraint
->list
= rsnd_soc_hw_channels_list
;
990 constraint
->count
= 0;
991 constraint
->mask
= 0;
993 for (i
= 0; i
< ARRAY_SIZE(rsnd_soc_hw_channels_list
); i
++) {
994 if (rsnd_soc_hw_channels_list
[i
] > max_channels
)
996 constraint
->count
= i
+ 1;
999 snd_soc_set_runtime_hwparams(substream
, &rsnd_pcm_hardware
);
1001 snd_pcm_hw_constraint_list(runtime
, 0,
1002 SNDRV_PCM_HW_PARAM_CHANNELS
, constraint
);
1004 snd_pcm_hw_constraint_integer(runtime
,
1005 SNDRV_PCM_HW_PARAM_PERIODS
);
1008 * Sampling Rate / Channel Limitation
1009 * It depends on Clock Master Mode
1011 if (rsnd_rdai_is_clk_master(rdai
)) {
1012 int is_play
= substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
;
1014 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1015 rsnd_soc_hw_rule_rate
,
1016 is_play
? &rdai
->playback
: &rdai
->capture
,
1017 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1018 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1019 rsnd_soc_hw_rule_channels
,
1020 is_play
? &rdai
->playback
: &rdai
->capture
,
1021 SNDRV_PCM_HW_PARAM_RATE
, -1);
1027 static void rsnd_soc_dai_shutdown(struct snd_pcm_substream
*substream
,
1028 struct snd_soc_dai
*dai
)
1030 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1031 struct rsnd_priv
*priv
= rsnd_rdai_to_priv(rdai
);
1032 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
1035 * call rsnd_dai_call without spinlock
1037 rsnd_dai_call(cleanup
, io
, priv
);
1039 rsnd_dai_stream_quit(io
);
1042 static int rsnd_soc_dai_prepare(struct snd_pcm_substream
*substream
,
1043 struct snd_soc_dai
*dai
)
1045 struct rsnd_priv
*priv
= rsnd_dai_to_priv(dai
);
1046 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1047 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
1049 return rsnd_dai_call(prepare
, io
, priv
);
1052 static const struct snd_soc_dai_ops rsnd_soc_dai_ops
= {
1053 .startup
= rsnd_soc_dai_startup
,
1054 .shutdown
= rsnd_soc_dai_shutdown
,
1055 .trigger
= rsnd_soc_dai_trigger
,
1056 .set_fmt
= rsnd_soc_dai_set_fmt
,
1057 .set_tdm_slot
= rsnd_soc_set_dai_tdm_slot
,
1058 .prepare
= rsnd_soc_dai_prepare
,
1061 static void rsnd_parse_tdm_split_mode(struct rsnd_priv
*priv
,
1062 struct rsnd_dai_stream
*io
,
1063 struct device_node
*dai_np
)
1065 struct device
*dev
= rsnd_priv_to_dev(priv
);
1066 struct device_node
*ssiu_np
= rsnd_ssiu_of_node(priv
);
1067 struct device_node
*np
;
1068 int is_play
= rsnd_io_is_play(io
);
1075 * This driver assumes that it is TDM Split mode
1076 * if it includes ssiu node
1079 struct device_node
*node
= is_play
?
1080 of_parse_phandle(dai_np
, "playback", i
) :
1081 of_parse_phandle(dai_np
, "capture", i
);
1087 for_each_child_of_node(ssiu_np
, np
) {
1089 rsnd_flags_set(io
, RSND_STREAM_TDM_SPLIT
);
1090 dev_dbg(dev
, "%s is part of TDM Split\n", io
->name
);
1098 of_node_put(ssiu_np
);
1101 static void rsnd_parse_connect_simple(struct rsnd_priv
*priv
,
1102 struct rsnd_dai_stream
*io
,
1103 struct device_node
*dai_np
)
1105 if (!rsnd_io_to_mod_ssi(io
))
1108 rsnd_parse_tdm_split_mode(priv
, io
, dai_np
);
1111 static void rsnd_parse_connect_graph(struct rsnd_priv
*priv
,
1112 struct rsnd_dai_stream
*io
,
1113 struct device_node
*endpoint
)
1115 struct device
*dev
= rsnd_priv_to_dev(priv
);
1116 struct device_node
*remote_node
;
1118 if (!rsnd_io_to_mod_ssi(io
))
1121 remote_node
= of_graph_get_remote_port_parent(endpoint
);
1124 if (strstr(remote_node
->full_name
, "hdmi@fead0000")) {
1125 rsnd_flags_set(io
, RSND_STREAM_HDMI0
);
1126 dev_dbg(dev
, "%s connected to HDMI0\n", io
->name
);
1130 if (strstr(remote_node
->full_name
, "hdmi@feae0000")) {
1131 rsnd_flags_set(io
, RSND_STREAM_HDMI1
);
1132 dev_dbg(dev
, "%s connected to HDMI1\n", io
->name
);
1135 rsnd_parse_tdm_split_mode(priv
, io
, endpoint
);
1137 of_node_put(remote_node
);
1140 void rsnd_parse_connect_common(struct rsnd_dai
*rdai
,
1141 struct rsnd_mod
* (*mod_get
)(struct rsnd_priv
*priv
, int id
),
1142 struct device_node
*node
,
1143 struct device_node
*playback
,
1144 struct device_node
*capture
)
1146 struct rsnd_priv
*priv
= rsnd_rdai_to_priv(rdai
);
1147 struct device_node
*np
;
1148 struct rsnd_mod
*mod
;
1155 for_each_child_of_node(node
, np
) {
1156 mod
= mod_get(priv
, i
);
1158 rsnd_dai_connect(mod
, &rdai
->playback
, mod
->type
);
1160 rsnd_dai_connect(mod
, &rdai
->capture
, mod
->type
);
1167 static struct device_node
*rsnd_dai_of_node(struct rsnd_priv
*priv
,
1170 struct device
*dev
= rsnd_priv_to_dev(priv
);
1171 struct device_node
*np
= dev
->of_node
;
1172 struct device_node
*dai_node
;
1173 struct device_node
*ret
;
1178 * parse both previous dai (= rcar_sound,dai), and
1179 * graph dai (= ports/port)
1181 dai_node
= of_get_child_by_name(np
, RSND_NODE_DAI
);
1184 goto of_node_compatible
;
1189 dai_node
= of_graph_get_next_endpoint(np
, NULL
);
1198 of_node_put(dai_node
);
1204 #define PREALLOC_BUFFER (32 * 1024)
1205 #define PREALLOC_BUFFER_MAX (32 * 1024)
1207 static int rsnd_preallocate_pages(struct snd_soc_pcm_runtime
*rtd
,
1208 struct rsnd_dai_stream
*io
,
1211 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
1212 struct device
*dev
= rsnd_priv_to_dev(priv
);
1213 struct snd_pcm_substream
*substream
;
1216 * use Audio-DMAC dev if we can use IPMMU
1218 * rsnd_dmaen_attach()
1223 for (substream
= rtd
->pcm
->streams
[stream
].substream
;
1225 substream
= substream
->next
) {
1226 snd_pcm_lib_preallocate_pages(substream
,
1229 PREALLOC_BUFFER
, PREALLOC_BUFFER_MAX
);
1235 static int rsnd_pcm_new(struct snd_soc_pcm_runtime
*rtd
,
1236 struct snd_soc_dai
*dai
)
1238 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1241 ret
= rsnd_dai_call(pcm_new
, &rdai
->playback
, rtd
);
1245 ret
= rsnd_dai_call(pcm_new
, &rdai
->capture
, rtd
);
1249 ret
= rsnd_preallocate_pages(rtd
, &rdai
->playback
,
1250 SNDRV_PCM_STREAM_PLAYBACK
);
1254 ret
= rsnd_preallocate_pages(rtd
, &rdai
->capture
,
1255 SNDRV_PCM_STREAM_CAPTURE
);
1262 static void __rsnd_dai_probe(struct rsnd_priv
*priv
,
1263 struct device_node
*dai_np
,
1266 struct device_node
*playback
, *capture
;
1267 struct rsnd_dai_stream
*io_playback
;
1268 struct rsnd_dai_stream
*io_capture
;
1269 struct snd_soc_dai_driver
*drv
;
1270 struct rsnd_dai
*rdai
;
1271 struct device
*dev
= rsnd_priv_to_dev(priv
);
1274 rdai
= rsnd_rdai_get(priv
, dai_i
);
1275 drv
= rsnd_daidrv_get(priv
, dai_i
);
1276 io_playback
= &rdai
->playback
;
1277 io_capture
= &rdai
->capture
;
1279 snprintf(rdai
->name
, RSND_DAI_NAME_SIZE
, "rsnd-dai.%d", dai_i
);
1282 drv
->name
= rdai
->name
;
1283 drv
->ops
= &rsnd_soc_dai_ops
;
1284 drv
->pcm_new
= rsnd_pcm_new
;
1286 snprintf(io_playback
->name
, RSND_DAI_NAME_SIZE
,
1287 "DAI%d Playback", dai_i
);
1288 drv
->playback
.rates
= RSND_RATES
;
1289 drv
->playback
.formats
= RSND_FMTS
;
1290 drv
->playback
.channels_min
= 2;
1291 drv
->playback
.channels_max
= 8;
1292 drv
->playback
.stream_name
= io_playback
->name
;
1294 snprintf(io_capture
->name
, RSND_DAI_NAME_SIZE
,
1295 "DAI%d Capture", dai_i
);
1296 drv
->capture
.rates
= RSND_RATES
;
1297 drv
->capture
.formats
= RSND_FMTS
;
1298 drv
->capture
.channels_min
= 2;
1299 drv
->capture
.channels_max
= 8;
1300 drv
->capture
.stream_name
= io_capture
->name
;
1302 io_playback
->rdai
= rdai
;
1303 io_capture
->rdai
= rdai
;
1304 rsnd_rdai_channels_set(rdai
, 2); /* default 2ch */
1305 rsnd_rdai_ssi_lane_set(rdai
, 1); /* default 1lane */
1306 rsnd_rdai_width_set(rdai
, 32); /* default 32bit width */
1308 for (io_i
= 0;; io_i
++) {
1309 playback
= of_parse_phandle(dai_np
, "playback", io_i
);
1310 capture
= of_parse_phandle(dai_np
, "capture", io_i
);
1312 if (!playback
&& !capture
)
1315 rsnd_parse_connect_ssi(rdai
, playback
, capture
);
1316 rsnd_parse_connect_ssiu(rdai
, playback
, capture
);
1317 rsnd_parse_connect_src(rdai
, playback
, capture
);
1318 rsnd_parse_connect_ctu(rdai
, playback
, capture
);
1319 rsnd_parse_connect_mix(rdai
, playback
, capture
);
1320 rsnd_parse_connect_dvc(rdai
, playback
, capture
);
1322 of_node_put(playback
);
1323 of_node_put(capture
);
1326 if (rsnd_ssi_is_pin_sharing(io_capture
) ||
1327 rsnd_ssi_is_pin_sharing(io_playback
)) {
1328 /* should have symmetric_rates if pin sharing */
1329 drv
->symmetric_rates
= 1;
1332 dev_dbg(dev
, "%s (%s/%s)\n", rdai
->name
,
1333 rsnd_io_to_mod_ssi(io_playback
) ? "play" : " -- ",
1334 rsnd_io_to_mod_ssi(io_capture
) ? "capture" : " -- ");
1337 static int rsnd_dai_probe(struct rsnd_priv
*priv
)
1339 struct device_node
*dai_node
;
1340 struct device_node
*dai_np
;
1341 struct snd_soc_dai_driver
*rdrv
;
1342 struct device
*dev
= rsnd_priv_to_dev(priv
);
1343 struct rsnd_dai
*rdai
;
1348 dai_node
= rsnd_dai_of_node(priv
, &is_graph
);
1350 nr
= of_graph_get_endpoint_count(dai_node
);
1352 nr
= of_get_child_count(dai_node
);
1357 rdrv
= devm_kcalloc(dev
, nr
, sizeof(*rdrv
), GFP_KERNEL
);
1358 rdai
= devm_kcalloc(dev
, nr
, sizeof(*rdai
), GFP_KERNEL
);
1363 priv
->daidrv
= rdrv
;
1371 for_each_endpoint_of_node(dai_node
, dai_np
) {
1372 __rsnd_dai_probe(priv
, dai_np
, dai_i
);
1373 if (rsnd_is_gen3(priv
)) {
1374 struct rsnd_dai
*rdai
= rsnd_rdai_get(priv
, dai_i
);
1376 rsnd_parse_connect_graph(priv
, &rdai
->playback
, dai_np
);
1377 rsnd_parse_connect_graph(priv
, &rdai
->capture
, dai_np
);
1382 for_each_child_of_node(dai_node
, dai_np
) {
1383 __rsnd_dai_probe(priv
, dai_np
, dai_i
);
1384 if (rsnd_is_gen3(priv
)) {
1385 struct rsnd_dai
*rdai
= rsnd_rdai_get(priv
, dai_i
);
1387 rsnd_parse_connect_simple(priv
, &rdai
->playback
, dai_np
);
1388 rsnd_parse_connect_simple(priv
, &rdai
->capture
, dai_np
);
1400 static int rsnd_hw_params(struct snd_soc_component
*component
,
1401 struct snd_pcm_substream
*substream
,
1402 struct snd_pcm_hw_params
*hw_params
)
1404 struct snd_soc_dai
*dai
= rsnd_substream_to_dai(substream
);
1405 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1406 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
1407 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
1411 * rsnd assumes that it might be used under DPCM if user want to use
1412 * channel / rate convert. Then, rsnd should be FE.
1413 * And then, this function will be called *after* BE settings.
1414 * this means, each BE already has fixuped hw_params.
1416 * dpcm_fe_dai_hw_params()
1417 * dpcm_be_dai_hw_params()
1419 io
->converted_rate
= 0;
1420 io
->converted_chan
= 0;
1421 if (fe
->dai_link
->dynamic
) {
1422 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
1423 struct device
*dev
= rsnd_priv_to_dev(priv
);
1424 struct snd_soc_dpcm
*dpcm
;
1425 struct snd_pcm_hw_params
*be_params
;
1426 int stream
= substream
->stream
;
1428 for_each_dpcm_be(fe
, stream
, dpcm
) {
1429 be_params
= &dpcm
->hw_params
;
1430 if (params_channels(hw_params
) != params_channels(be_params
))
1431 io
->converted_chan
= params_channels(be_params
);
1432 if (params_rate(hw_params
) != params_rate(be_params
))
1433 io
->converted_rate
= params_rate(be_params
);
1435 if (io
->converted_chan
)
1436 dev_dbg(dev
, "convert channels = %d\n", io
->converted_chan
);
1437 if (io
->converted_rate
)
1438 dev_dbg(dev
, "convert rate = %d\n", io
->converted_rate
);
1441 ret
= rsnd_dai_call(hw_params
, io
, substream
, hw_params
);
1445 return snd_pcm_lib_malloc_pages(substream
,
1446 params_buffer_bytes(hw_params
));
1449 static int rsnd_hw_free(struct snd_soc_component
*component
,
1450 struct snd_pcm_substream
*substream
)
1452 struct snd_soc_dai
*dai
= rsnd_substream_to_dai(substream
);
1453 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1454 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
1457 ret
= rsnd_dai_call(hw_free
, io
, substream
);
1461 return snd_pcm_lib_free_pages(substream
);
1464 static snd_pcm_uframes_t
rsnd_pointer(struct snd_soc_component
*component
,
1465 struct snd_pcm_substream
*substream
)
1467 struct snd_soc_dai
*dai
= rsnd_substream_to_dai(substream
);
1468 struct rsnd_dai
*rdai
= rsnd_dai_to_rdai(dai
);
1469 struct rsnd_dai_stream
*io
= rsnd_rdai_to_io(rdai
, substream
);
1470 snd_pcm_uframes_t pointer
= 0;
1472 rsnd_dai_call(pointer
, io
, &pointer
);
1480 static int rsnd_kctrl_info(struct snd_kcontrol
*kctrl
,
1481 struct snd_ctl_elem_info
*uinfo
)
1483 struct rsnd_kctrl_cfg
*cfg
= snd_kcontrol_chip(kctrl
);
1486 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1487 uinfo
->count
= cfg
->size
;
1488 uinfo
->value
.enumerated
.items
= cfg
->max
;
1489 if (uinfo
->value
.enumerated
.item
>= cfg
->max
)
1490 uinfo
->value
.enumerated
.item
= cfg
->max
- 1;
1491 strlcpy(uinfo
->value
.enumerated
.name
,
1492 cfg
->texts
[uinfo
->value
.enumerated
.item
],
1493 sizeof(uinfo
->value
.enumerated
.name
));
1495 uinfo
->count
= cfg
->size
;
1496 uinfo
->value
.integer
.min
= 0;
1497 uinfo
->value
.integer
.max
= cfg
->max
;
1498 uinfo
->type
= (cfg
->max
== 1) ?
1499 SNDRV_CTL_ELEM_TYPE_BOOLEAN
:
1500 SNDRV_CTL_ELEM_TYPE_INTEGER
;
1506 static int rsnd_kctrl_get(struct snd_kcontrol
*kctrl
,
1507 struct snd_ctl_elem_value
*uc
)
1509 struct rsnd_kctrl_cfg
*cfg
= snd_kcontrol_chip(kctrl
);
1512 for (i
= 0; i
< cfg
->size
; i
++)
1514 uc
->value
.enumerated
.item
[i
] = cfg
->val
[i
];
1516 uc
->value
.integer
.value
[i
] = cfg
->val
[i
];
1521 static int rsnd_kctrl_put(struct snd_kcontrol
*kctrl
,
1522 struct snd_ctl_elem_value
*uc
)
1524 struct rsnd_kctrl_cfg
*cfg
= snd_kcontrol_chip(kctrl
);
1527 if (!cfg
->accept(cfg
->io
))
1530 for (i
= 0; i
< cfg
->size
; i
++) {
1532 change
|= (uc
->value
.enumerated
.item
[i
] != cfg
->val
[i
]);
1533 cfg
->val
[i
] = uc
->value
.enumerated
.item
[i
];
1535 change
|= (uc
->value
.integer
.value
[i
] != cfg
->val
[i
]);
1536 cfg
->val
[i
] = uc
->value
.integer
.value
[i
];
1540 if (change
&& cfg
->update
)
1541 cfg
->update(cfg
->io
, cfg
->mod
);
1546 int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream
*io
)
1551 int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream
*io
)
1553 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
1554 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
1555 struct device
*dev
= rsnd_priv_to_dev(priv
);
1558 dev_warn(dev
, "Can't update kctrl when idle\n");
1565 struct rsnd_kctrl_cfg
*rsnd_kctrl_init_m(struct rsnd_kctrl_cfg_m
*cfg
)
1567 cfg
->cfg
.val
= cfg
->val
;
1572 struct rsnd_kctrl_cfg
*rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s
*cfg
)
1574 cfg
->cfg
.val
= &cfg
->val
;
1579 const char * const volume_ramp_rate
[] = {
1580 "128 dB/1 step", /* 00000 */
1581 "64 dB/1 step", /* 00001 */
1582 "32 dB/1 step", /* 00010 */
1583 "16 dB/1 step", /* 00011 */
1584 "8 dB/1 step", /* 00100 */
1585 "4 dB/1 step", /* 00101 */
1586 "2 dB/1 step", /* 00110 */
1587 "1 dB/1 step", /* 00111 */
1588 "0.5 dB/1 step", /* 01000 */
1589 "0.25 dB/1 step", /* 01001 */
1590 "0.125 dB/1 step", /* 01010 = VOLUME_RAMP_MAX_MIX */
1591 "0.125 dB/2 steps", /* 01011 */
1592 "0.125 dB/4 steps", /* 01100 */
1593 "0.125 dB/8 steps", /* 01101 */
1594 "0.125 dB/16 steps", /* 01110 */
1595 "0.125 dB/32 steps", /* 01111 */
1596 "0.125 dB/64 steps", /* 10000 */
1597 "0.125 dB/128 steps", /* 10001 */
1598 "0.125 dB/256 steps", /* 10010 */
1599 "0.125 dB/512 steps", /* 10011 */
1600 "0.125 dB/1024 steps", /* 10100 */
1601 "0.125 dB/2048 steps", /* 10101 */
1602 "0.125 dB/4096 steps", /* 10110 */
1603 "0.125 dB/8192 steps", /* 10111 = VOLUME_RAMP_MAX_DVC */
1606 int rsnd_kctrl_new(struct rsnd_mod
*mod
,
1607 struct rsnd_dai_stream
*io
,
1608 struct snd_soc_pcm_runtime
*rtd
,
1609 const unsigned char *name
,
1610 int (*accept
)(struct rsnd_dai_stream
*io
),
1611 void (*update
)(struct rsnd_dai_stream
*io
,
1612 struct rsnd_mod
*mod
),
1613 struct rsnd_kctrl_cfg
*cfg
,
1614 const char * const *texts
,
1618 struct snd_card
*card
= rtd
->card
->snd_card
;
1619 struct snd_kcontrol
*kctrl
;
1620 struct snd_kcontrol_new knew
= {
1621 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1623 .info
= rsnd_kctrl_info
,
1625 .get
= rsnd_kctrl_get
,
1626 .put
= rsnd_kctrl_put
,
1631 * 1) Avoid duplicate register for DVC with MIX case
1632 * 2) Allow duplicate register for MIX
1633 * 3) re-register if card was rebinded
1635 list_for_each_entry(kctrl
, &card
->controls
, list
) {
1636 struct rsnd_kctrl_cfg
*c
= kctrl
->private_data
;
1642 if (size
> RSND_MAX_CHANNELS
)
1645 kctrl
= snd_ctl_new1(&knew
, cfg
);
1649 ret
= snd_ctl_add(card
, kctrl
);
1656 cfg
->accept
= accept
;
1657 cfg
->update
= update
;
1669 static const struct snd_soc_component_driver rsnd_soc_component
= {
1671 .ioctl
= snd_soc_pcm_lib_ioctl
,
1672 .hw_params
= rsnd_hw_params
,
1673 .hw_free
= rsnd_hw_free
,
1674 .pointer
= rsnd_pointer
,
1677 static int rsnd_rdai_continuance_probe(struct rsnd_priv
*priv
,
1678 struct rsnd_dai_stream
*io
)
1682 ret
= rsnd_dai_call(probe
, io
, priv
);
1683 if (ret
== -EAGAIN
) {
1684 struct rsnd_mod
*ssi_mod
= rsnd_io_to_mod_ssi(io
);
1685 struct rsnd_mod
*mod
;
1689 * Fallback to PIO mode
1693 * call "remove" for SSI/SRC/DVC
1694 * SSI will be switch to PIO mode if it was DMA mode
1697 * rsnd_ssi_fallback()
1699 rsnd_dai_call(remove
, io
, priv
);
1702 * remove all mod from io
1703 * and, re connect ssi
1705 for_each_rsnd_mod(i
, mod
, io
)
1706 rsnd_dai_disconnect(mod
, io
, i
);
1707 rsnd_dai_connect(ssi_mod
, io
, RSND_MOD_SSI
);
1712 rsnd_dai_call(fallback
, io
, priv
);
1716 * DAI has SSI which is PIO mode only now.
1718 ret
= rsnd_dai_call(probe
, io
, priv
);
1727 static int rsnd_probe(struct platform_device
*pdev
)
1729 struct rsnd_priv
*priv
;
1730 struct device
*dev
= &pdev
->dev
;
1731 struct rsnd_dai
*rdai
;
1732 int (*probe_func
[])(struct rsnd_priv
*priv
) = {
1750 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
1755 priv
->flags
= (unsigned long)of_device_get_match_data(dev
);
1756 spin_lock_init(&priv
->lock
);
1761 for (i
= 0; i
< ARRAY_SIZE(probe_func
); i
++) {
1762 ret
= probe_func
[i
](priv
);
1767 for_each_rsnd_dai(rdai
, priv
, i
) {
1768 ret
= rsnd_rdai_continuance_probe(priv
, &rdai
->playback
);
1770 goto exit_snd_probe
;
1772 ret
= rsnd_rdai_continuance_probe(priv
, &rdai
->capture
);
1774 goto exit_snd_probe
;
1777 dev_set_drvdata(dev
, priv
);
1782 ret
= devm_snd_soc_register_component(dev
, &rsnd_soc_component
,
1783 priv
->daidrv
, rsnd_rdai_nr(priv
));
1785 dev_err(dev
, "cannot snd dai register\n");
1786 goto exit_snd_probe
;
1789 pm_runtime_enable(dev
);
1791 dev_info(dev
, "probed\n");
1795 for_each_rsnd_dai(rdai
, priv
, i
) {
1796 rsnd_dai_call(remove
, &rdai
->playback
, priv
);
1797 rsnd_dai_call(remove
, &rdai
->capture
, priv
);
1801 * adg is very special mod which can't use rsnd_dai_call(remove),
1802 * and it registers ADG clock on probe.
1803 * It should be unregister if probe failed.
1804 * Mainly it is assuming -EPROBE_DEFER case
1806 rsnd_adg_remove(priv
);
1811 static int rsnd_remove(struct platform_device
*pdev
)
1813 struct rsnd_priv
*priv
= dev_get_drvdata(&pdev
->dev
);
1814 struct rsnd_dai
*rdai
;
1815 void (*remove_func
[])(struct rsnd_priv
*priv
) = {
1827 snd_soc_disconnect_sync(&pdev
->dev
);
1829 pm_runtime_disable(&pdev
->dev
);
1831 for_each_rsnd_dai(rdai
, priv
, i
) {
1832 ret
|= rsnd_dai_call(remove
, &rdai
->playback
, priv
);
1833 ret
|= rsnd_dai_call(remove
, &rdai
->capture
, priv
);
1836 for (i
= 0; i
< ARRAY_SIZE(remove_func
); i
++)
1837 remove_func
[i
](priv
);
1842 static int __maybe_unused
rsnd_suspend(struct device
*dev
)
1844 struct rsnd_priv
*priv
= dev_get_drvdata(dev
);
1846 rsnd_adg_clk_disable(priv
);
1851 static int __maybe_unused
rsnd_resume(struct device
*dev
)
1853 struct rsnd_priv
*priv
= dev_get_drvdata(dev
);
1855 rsnd_adg_clk_enable(priv
);
1860 static const struct dev_pm_ops rsnd_pm_ops
= {
1861 SET_SYSTEM_SLEEP_PM_OPS(rsnd_suspend
, rsnd_resume
)
1864 static struct platform_driver rsnd_driver
= {
1866 .name
= "rcar_sound",
1868 .of_match_table
= rsnd_of_match
,
1870 .probe
= rsnd_probe
,
1871 .remove
= rsnd_remove
,
1873 module_platform_driver(rsnd_driver
);
1875 MODULE_LICENSE("GPL v2");
1876 MODULE_DESCRIPTION("Renesas R-Car audio driver");
1877 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1878 MODULE_ALIAS("platform:rcar-pcm-audio");