Commit graph

116 commits

Author SHA1 Message Date
Kuninori Morimoto
ffe4c0f0bf
ASoC: soc-compress.c: fixup private_data on snd_soc_new_compress()
commit d3268a40d4 ("ASoC: soc-compress.c: fix NULL dereference")
enables DPCM capture, but it should independent from playback.
This patch fixup it.

Fixes: d3268a40d4 ("ASoC: soc-compress.c: fix NULL dereference")
Link: https://lore.kernel.org/r/87tu0i6j7j.wl-kuninori.morimoto.gx@renesas.com
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/871qnkvo1s.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2023-01-28 10:51:06 +00:00
강신형
aa9ff6a495
ASoC: soc-compress: Reposition and add pcm_mutex
If panic_on_warn is set and compress stream(DPCM) is started,
then kernel panic occurred because card->pcm_mutex isn't held appropriately.
In the following functions, warning were issued at this line
"snd_soc_dpcm_mutex_assert_held".

static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
		struct snd_soc_pcm_runtime *be, int stream)
{
	...
	snd_soc_dpcm_mutex_assert_held(fe);
	...
}

void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
{
	...
	snd_soc_dpcm_mutex_assert_held(fe);
	...
}

void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
			    int stream, int action)
{
	...
	snd_soc_dpcm_mutex_assert_held(rtd);
	...
}

int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
	int event)
{
	...
	snd_soc_dpcm_mutex_assert_held(fe);
	...
}

These functions are called by soc_compr_set_params_fe, soc_compr_open_fe
and soc_compr_free_fe
without pcm_mutex locking. And this is call stack.

[  414.527841][ T2179] pc : dpcm_process_paths+0x5a4/0x750
[  414.527848][ T2179] lr : dpcm_process_paths+0x37c/0x750
[  414.527945][ T2179] Call trace:
[  414.527949][ T2179]  dpcm_process_paths+0x5a4/0x750
[  414.527955][ T2179]  soc_compr_open_fe+0xb0/0x2cc
[  414.527972][ T2179]  snd_compr_open+0x180/0x248
[  414.527981][ T2179]  snd_open+0x15c/0x194
[  414.528003][ T2179]  chrdev_open+0x1b0/0x220
[  414.528023][ T2179]  do_dentry_open+0x30c/0x594
[  414.528045][ T2179]  vfs_open+0x34/0x44
[  414.528053][ T2179]  path_openat+0x914/0xb08
[  414.528062][ T2179]  do_filp_open+0xc0/0x170
[  414.528068][ T2179]  do_sys_openat2+0x94/0x18c
[  414.528076][ T2179]  __arm64_sys_openat+0x78/0xa4
[  414.528084][ T2179]  invoke_syscall+0x48/0x10c
[  414.528094][ T2179]  el0_svc_common+0xbc/0x104
[  414.528099][ T2179]  do_el0_svc+0x34/0xd8
[  414.528103][ T2179]  el0_svc+0x34/0xc4
[  414.528125][ T2179]  el0t_64_sync_handler+0x8c/0xfc
[  414.528133][ T2179]  el0t_64_sync+0x1a0/0x1a4
[  414.528142][ T2179] Kernel panic - not syncing: panic_on_warn set ...

So, I reposition and add pcm_mutex to resolve lockdep error.

Signed-off-by: Shinhyung Kang <s47.kang@samsung.com>
Link: https://lore.kernel.org/r/016401d90ac4$7b6848c0$7238da40$@samsung.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2023-01-27 00:55:07 +00:00
Kuninori Morimoto
3989ade2d1
ASoC: soc.h: remove num_cpus/codecs
Current rtd has both dai_link pointer (A) and num_cpus/codecs (B).

(A)	rtd->dai_link	= dai_link;
(B)	rtd->num_cpus	= dai_link->num_cpus;
(B)	rtd->num_codecs	= dai_link->num_codecs;

But, we can get num_cpus/codecs (B) via dai_link (A).
This means we don't need to keep num_cpus/codecs on rtd.
This patch removes these.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87sfkmv9n3.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-09-20 12:19:30 +01:00
Jiasheng Jiang
ccb4214f7f
ASoC: soc-compress: Change the check for codec_dai
It should be better to reverse the check on codec_dai
and returned early in order to be easier to understand.

Fixes: de2c6f9881 ("ASoC: soc-compress: prevent the potentially use of null pointer")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220310030041.1556323-1-jiasheng@iscas.ac.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-03-14 08:29:11 +00:00
Jiasheng Jiang
de2c6f9881
ASoC: soc-compress: prevent the potentially use of null pointer
There is one call trace that snd_soc_register_card()
->snd_soc_bind_card()->soc_init_pcm_runtime()
->snd_soc_dai_compress_new()->snd_soc_new_compress().
In the trace the 'codec_dai' transfers from card->dai_link,
and we can see from the snd_soc_add_pcm_runtime() in
snd_soc_bind_card() that, if value of card->dai_link->num_codecs
is 0, then 'codec_dai' could be null pointer caused
by index out of bound in 'asoc_rtd_to_codec(rtd, 0)'.
And snd_soc_register_card() is called by various platforms.
Therefore, it is better to add the check in the case of misusing.
And because 'cpu_dai' has already checked in soc_init_pcm_runtime(),
there is no need to check again.
Adding the check as follow, then if 'codec_dai' is null,
snd_soc_new_compress() will not pass through the check
'if (playback + capture != 1)', avoiding the leftover use of
'codec_dai'.

Fixes: 467fece ("ASoC: soc-dai: move snd_soc_dai_stream_valid() to soc-dai.c")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/1634285633-529368-1-git-send-email-jiasheng@iscas.ac.cn
Signed-off-by: Mark Brown <broonie@kernel.org>
2022-03-02 13:45:26 +00:00
Peter Ujfalusi
cd46f38244
ASoC: compress/component: Use module_get_when_open/put_when_close for cstream
Currently the try_module_get() and module_put() is not possible for
compressed streams if the module_get_upon_open is set to 1 which means that\
the components are not protected in a same way as components when normal
audio is used.

SOF is setting module_get_upon_open to 1 for component drivers which works
correctly for audio stream but when compressed stream is used then the
module is not protected.

Convert the compress open and free operation to mimic the steps of it's
pcm counterpart to fix this issue.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20210901095255.3617-3-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-09-20 13:30:18 +01:00
Takashi Iwai
2c4e315457 ALSA: compress: Initialize mutex in snd_compress_new()
Currently the snd_compr.lock mutex isn't initialized in the API
functions although the lock is used many places in other code in
compress offload API.  It's because the object was expected to be
initialized via snd_compress_register(), but this was never used by
ASoC, which is the only user.  Instead, ASoC initializes the mutex by
itself, and this is error-prone.

This patch moves the mutex initialization into the more appropriate
place, snd_compress_new(), for avoiding the missing init.

Reviewed-by: Mark Brown <broonie@kernel.org>
Acked-by: Vinod Koul <vkoul@kernel.org>
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20210714162424.4412-3-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-07-15 10:22:38 +02:00
Gyeongtaek Lee
45475bf60c
ASoC: soc-compress: lock pcm_mutex to resolve lockdep error
If panic_on_warn=1 is added in bootargs and compress offload playback with
DPCM is started, kernel panic would be occurred because rtd->card->pcm_mutex
isn't held in soc_compr_open_fe() and soc_compr_free_fe() and it generates
lockdep warning in the following code.

void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
			    int stream, int action)
{
	struct snd_soc_dai *dai;
	int i;

	lockdep_assert_held(&rtd->card->pcm_mutex);

To prevent lockdep warning but minimize side effect by adding mutex,
pcm_mutex is held just before snd_soc_runtime_activate() and
snd_soc_runtime_deactivate() and is released right after them.

Signed-off-by: Gyeongtaek Lee <gt82.lee@samsung.com>
Link: https://lore.kernel.org/r/1891546521.01617772502282.JavaMail.epsvc@epcpadp3
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-04-09 13:39:44 +01:00
Kuninori Morimoto
f52366e683
ASoC: soc-pcm: don't indicate error message for dpcm_be_dai_hw_free()
dpcm_be_dai_hw_free() never fail, error message is not needed.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87blblutaf.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-19 12:24:03 +00:00
Kuninori Morimoto
d479f00b79
ASoC: soc-pcm: indicate error message at dpcm_path_get()
Indicating error message when failed case is very useful for debuging.
In many case, its style is like below.

	int function(...)
	{
		...
		return ret;
	}

	int caller(...)
	{
		...
		ret = function(...);
		if (ret < 0)
			dev_err(...)
		...
	}

This is not so bad, but in this style *each caller* needs to indicate
duplicate same error message, and some caller is forgetting to do it.
And caller can't indicate detail function() error information.

If function() indicates error message, we can get same and
detail information without forgot.

	int function(...)
	{
		...
		if (ret < 0)
			dev_err(...)

		return ret;
	}

	int caller(...)
	{
		...
		ret = function(...);
		...
	}

Now, many place uses dpcm_path_get() like below

	ret = dpcm_path_get(...);
	if (ret < 0)
		goto error;
(A)	else if (ret == 0)
		dev_dbg(...)

But here, (A) part can be indicated at dpcm_path_get() not caller.
It is simple and readable code.

This patch do it.
Small detail behaviors will be exchanged by this patch.

	1) indicates debug info (= path numbers) if path > 0 case only
	   (It was *always* indicated).
	2) soc_dpcm_fe_runtime_update() is indicating error message
	   for paths < 0 case, but it is already done at dpcm_path_get().
	   Thus just remove it. but dev_dbg() vs dev_warn() is exchanged.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87mtv5utbj.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-19 12:23:55 +00:00
Kuninori Morimoto
531590bb40
ASoC: soc-pcm: share DPCM BE DAI stop operation
soc-pcm has very similar but different DPCM BE DAI stop operation at
	1) dpcm_be_dai_startup() error case rollback
	2) dpcm_be_dai_startup_unwind()
	3) dpcm_be_dai_shutdown()

The differences are
	1) for rollback
	2) Doesn't check by snd_soc_dpcm_be_can_update() (Is this bug ?)
	3) Do soc_pcm_hw_free() if it was not !OPENed and !HW_FREEed,
	   and call soc_pcm_close().

We can share same code by
	1) hw_free is not needed. Needs last dpcm as rollback.
	2) hw_free is not needed.
	3) hw_free is     needed.

This patch adds new dpcm_be_dai_stop() and share these 3.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87a6rduoam.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-12 14:26:32 +00:00
Kuninori Morimoto
453d32c2f7
ASoC: soc-compress: add soc_compr_clean() and call it from soc_compr_open/free()
soc_compr_open() does rollback when failed (A),
but, it is almost same as soc_compr_free().

	static int soc_compr_open(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return 0;

 ^	machine_err:
 |		...
 |	out:
(A)		...
 |	pm_err:
 |		...
 v		return ret;
	}

The difference is
soc_compr_free()  is for all dai/component/substream,
rollback          is for succeeded part only.

This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_compr_free() and rollback.

Now, soc_compr_open/free() are handling
	1) snd_soc_dai_compr_startup/shutdown()
	2) snd_soc_component_compr_open/free()
	3) snd_soc_link_compr_startup/shutdown()

Now, 1) to 3) are handled.
This patch adds new soc_compr_clean() and call it from
soc_compr_open() as rollback, and from soc_compr_free_free() as
normal close handler.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87ima25iwa.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-26 13:09:37 +00:00
Kuninori Morimoto
cd7c7d10e8
ASoC: soc-component: add mark for snd_soc_link_compr_startup/shutdown()
soc_compr_open() does rollback when failed (A),
but, it is almost same as soc_compr_free().

	static int soc_compr_open(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return 0;

 ^	machine_err:
 |		...
 |	out:
(A)		...
 |	pm_err:
 |		...
 v		return ret;
	}

The difference is
soc_compr_free()  is for all dai/component/substream,
rollback          is for succeeded part only.

This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_compr_free() and rollback.
	1) snd_soc_dai_compr_startup/shutdown()
	2) snd_soc_component_compr_open/free()
=>	3) snd_soc_link_compr_startup/shutdown()

This patch is for 3) snd_soc_link_compr_startup/shutdown()
and adds new cstream mark.
It will mark cstream when startup() was suceeded.
If rollback happen *after* that, it will check rollback flag
and marked cstream.

It cares *previous* startup() only now,
but we might want to check *whole* marked cstream in the future.
This patch is using macro so that it can be easily adjust to it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87k0ui5iwf.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-26 13:09:36 +00:00
Kuninori Morimoto
f94ba9ac20
ASoC: soc-component: add mark for snd_soc_component_compr_open/free()
soc_compr_open() does rollback when failed (A),
but, it is almost same as soc_compr_free().

	static int soc_compr_open(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return 0;

 ^	machine_err:
 |		...
 |	out:
(A)		...
 |	pm_err:
 |		...
 v		return ret;
	}

The difference is
soc_compr_free()  is for all dai/component/substream,
rollback          is for succeeded part only.

This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_compr_free() and rollback.
	1) snd_soc_dai_compr_startup/shutdown()
=>	2) snd_soc_component_compr_open/free()
	3) snd_soc_link_compr_startup/shutdown()

This patch is for 2) snd_soc_component_compr_open/free(),
and adds new cstream mark.
It will mark cstream when startup() was suceeded.
If rollback happen *after* that, it will check rollback flag
and marked cstream.

It cares *previous* startup() only now,
but we might want to check *whole* marked cstream in the future.
This patch is using macro so that it can be easily adjust to it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87lfey5iwk.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-26 13:09:35 +00:00
Kuninori Morimoto
1e6a93cf74
ASoC: soc-dai: add mark for snd_soc_dai_compr_startup/shutdown()
soc_compr_open() does rollback when failed (A),
but, it is almost same as soc_compr_free().

	static int soc_compr_open(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return 0;

 ^	machine_err:
 |		...
 |	out:
(A)		...
 |	pm_err:
 |		...
 v		return ret;
	}

The difference is
soc_compr_free()  is for all dai/component/substream,
rollback          is for succeeded part only.

This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_compr_free() and rollback.
=>	1) snd_soc_dai_compr_startup/shutdown()
	2) snd_soc_component_compr_open/free()
	3) snd_soc_link_compr_startup/shutdown()

This patch is for 1) snd_soc_dai_compr_startup/shutdown(),
and adds new cstream mark.
It will mark cstream when startup() was suceeded.
If rollback happen *after* that, it will check rollback flag
and marked cstream.

It cares *previous* startup() only now,
but we might want to check *whole* marked cstream in the future.
This patch is using macro so that it can be easily adjust to it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87mtze5iwp.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-26 13:09:34 +00:00
Kuninori Morimoto
15a7b8c136
ASoC: soc-compress: move soc_compr_free() next to soc_compr_open()
This patch moves soc_compr_free() next to soc_compr_open().
This is prepare for soc_compr_open() cleanup.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87o8ju5iwv.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-26 13:09:33 +00:00
Kuninori Morimoto
bab78c2380
ASoC: soc-component: add snd_soc_component_compr_get_metadata()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_get_metadata().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87zh3l6gl8.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:17 +00:00
Kuninori Morimoto
1b308fb138
ASoC: soc-component: add snd_soc_component_compr_set_metadata()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_set_metadata().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/871rgx7v5t.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:16 +00:00
Kuninori Morimoto
b5852e66b1
ASoC: soc-component: add snd_soc_component_compr_copy()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_copy().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87361d7v5z.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:15 +00:00
Kuninori Morimoto
03ecea64e0
ASoC: soc-component: add snd_soc_component_compr_pointer()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_pointer().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/874klt7v65.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:14 +00:00
Kuninori Morimoto
0506b88503
ASoC: soc-component: add snd_soc_component_compr_ack()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_ack().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/875z697v6c.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:13 +00:00
Kuninori Morimoto
0f6fe09720
ASoC: soc-component: add snd_soc_component_compr_get_codec_caps()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_get_codec_caps().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/877dqp7v6i.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:13 +00:00
Kuninori Morimoto
d67fcb2d8f
ASoC: soc-component: add snd_soc_component_compr_get_caps()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_get_caps().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/878sb57v6q.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:12 +00:00
Kuninori Morimoto
77c221ecfe
ASoC: soc-component: add snd_soc_component_compr_get_params()
component related function should be implemented at
soc-component.c.
This patch adds snd_soc_component_compr_get_params().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87a6vl7v6x.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:11 +00:00
Kuninori Morimoto
ff08cf80ad
ASoC: soc-component: add snd_soc_component_compr_set_params()
component related function should be implemented at
soc-component.c.
This patch moves soc-compress soc_compr_components_set_params()
to soc-component as snd_soc_component_compr_set_params().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87blg17v74.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:10 +00:00
Kuninori Morimoto
08aee25114
ASoC: soc-component: add snd_soc_component_compr_trigger()
component related function should be implemented at
soc-component.c.
This patch moves soc-compress soc_compr_components_trigger()
to soc-component as snd_soc_component_compr_trigger().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87d00h7v7k.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:09 +00:00
Kuninori Morimoto
dbde5e2114
ASoC: soc-component: add snd_soc_component_compr_free()
component related function should be implemented at
soc-component.c.
This patch moves soc-compress soc_compr_components_free()
to soc-component as snd_soc_component_compr_free().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87eekx7v7r.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:08 +00:00
Kuninori Morimoto
a4e427c59a
ASoC: soc-component: add snd_soc_component_compr_open()
component related function should be implemented at
soc-component.c.
This patch moves soc-compress soc_compr_components_open()
to soc-component as snd_soc_component_compr_open().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87ft5d7v7x.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 18:00:07 +00:00
Kuninori Morimoto
7428d8c8bd
ASoC: soc-compress: assume SNDRV_PCM_STREAM_xxx and SND_COMPRESS_xxx are same
soc-compress.c is using both SND_COMPRESS_xxx and SND_PCM_STREAM_xxx.
These are defined as UAPI, and has same value.

	enum {
		SNDRV_PCM_STREAM_PLAYBACK = 0,
		SNDRV_PCM_STREAM_CAPTURE,
		...
	};

	enum snd_compr_direction {
		SND_COMPRESS_PLAYBACK = 0,
		SND_COMPRESS_CAPTURE
	};

Essentially both COMPRESS and PCM_STREAM definitions are identical,
and can be never different because of ABI compatibility,
which means it's safe to mix both variants in the code.

This patch checks it by BUILD_BUG_ON(), and merge to use.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87361wmsyg.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-10 14:26:00 +00:00
Kuninori Morimoto
eb84959ab8
ASoC: soc-compress: tidyup STREAM vs COMPRESS
snd_soc_runtime_activate() and
snd_soc_dai_digital_mute() need SNDRV_PCM_STREAM_xxx
instead of SND_COMPRESS_xxx.

These are bug but nothing happen because these are same value.

	enum {
		SNDRV_PCM_STREAM_PLAYBACK = 0,
		SNDRV_PCM_STREAM_CAPTURE,
		...
	};

	enum snd_compr_direction {
		SND_COMPRESS_PLAYBACK = 0,
		SND_COMPRESS_CAPTURE
	};

This patch tidyup it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/874kmcmsyn.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-10 14:25:59 +00:00
Kuninori Morimoto
939a5cfb2a
ASoC: soc-component: add mark for snd_soc_pcm_component_pm_runtime_get/put()
soc_pcm_open() does rollback when failed (A),
but, it is almost same as soc_pcm_close().

	static int soc_pcm_open(xxx)
	{
		...
		if (ret < 0)
			goto xxx_err;
		...
		return 0;

 ^	config_err:
 |		...
 |	rtd_startup_err:
(A)		...
 |	component_err:
 |		...
 v		return ret;
	}

The difference is
soc_pcm_close() is for all dai/component/substream,
rollback        is for succeeded part only.

This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_pcm_close() and rollback.

Now, soc_pcm_open/close() are handling
	1) snd_soc_dai_startup/shutdown()
	2) snd_soc_link_startup/shutdown()
	3) snd_soc_component_module_get/put()
	4) snd_soc_component_open/close()
=>	5) pm_runtime_put/get()

This patch is for 5) pm_runtime_put/get().

The idea of having bit-flag or counter is not enough for this purpose.
For example if one DAI is used for 2xPlaybacks for some reasons,
and if 1st Playback was succeeded but 2nd Playback was failed,
2nd Playback rollback doesn't need to call shutdown.
But it has succeeded bit-flag or counter via 1st Playback,
thus, 2nd Playback rollback will call unneeded shutdown.
And 1st Playback's necessary shutdown will not be called,
because bit-flag or counter was cleared by wrong 2nd Playback rollback.

To avoid such case, this patch marks substream pointer when get() was
succeeded. If rollback needed, it will check rollback flag and marked
substream pointer.

One note here is that it cares *current* get() only now.
but we might want to check *whole* marked substream in the future.
This patch is using macro named "push/pop", so that it can be easily
update.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87h7ribwnb.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-09-28 17:01:44 +01:00
Pierre-Louis Bossart
1d5cd5254f
ASoC: soc-pcm/compress: reduce verbosity on mapping ok messages
With dynamic debug not enabled, we still get these messages:

[   48.133586] sof_sdw sof_sdw: rt711-aif1 <-> SDW0 Pin2 mapping ok
[   48.133595] sof_sdw sof_sdw: rt711-aif1 <-> SDW0 Pin3 mapping ok
[   48.133650] sof_sdw sof_sdw: sdw:1:25d:1308:0 <-> SDW1 Pin2 mapping ok
[   48.133658] sof_sdw sof_sdw: rt715-aif2 <-> SDW3 Pin2 mapping ok
[   48.133666] sof_sdw sof_sdw: intel-hdmi-hifi1 <-> iDisp1 Pin mapping ok
[   48.133672] sof_sdw sof_sdw: intel-hdmi-hifi2 <-> iDisp2 Pin mapping ok
[   48.133677] sof_sdw sof_sdw: intel-hdmi-hifi3 <-> iDisp3 Pin mapping ok
[   48.133712] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Headphone 0 mapping ok
[   48.133733] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Headset mic 1 mapping ok
[   48.133746] sof_sdw sof_sdw: snd-soc-dummy-dai <-> SDW1-speakers 2 mapping ok
[   48.133762] sof_sdw sof_sdw: snd-soc-dummy-dai <-> Microphones 4 mapping ok
[   48.133774] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI1 5 mapping ok
[   48.133798] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI2 6 mapping ok
[   48.133809] sof_sdw sof_sdw: snd-soc-dummy-dai <-> HDMI3 7 mapping ok

This is not really useful for most users, demote to dev_dbg()

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20200612204050.25901-4-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-06-15 17:12:11 +01:00
Kuninori Morimoto
eab810f37f
ASoC: soc-link: add snd_soc_link_compr_set_params()
dai_link related function should be implemented at soc-link.c.
This patch adds snd_soc_link_compr_set_params().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/87sgfo3k6q.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-25 14:22:14 +01:00
Kuninori Morimoto
0e532c99b4
ASoC: soc-link: add snd_soc_link_compr_shutdown()
dai_link related function should be implemented at soc-link.c.
This patch adds snd_soc_link_compr_shutdown().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/87tv043k6u.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-25 14:22:13 +01:00
Kuninori Morimoto
9ab711cb84
ASoC: soc-link: add snd_soc_link_compr_startup()
dai_link related function should be implemented at soc-link.c.
This patch adds snd_soc_link_compr_startup().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/87v9kk3k6y.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-25 14:22:12 +01:00
Kuninori Morimoto
b3dea624b5
ASoC: use snd_soc_xxx_active()
We have snd_soc_dai/dai_stream/component_active() macro
This patch uses it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/8736826n44.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-18 16:15:03 +01:00
Kuninori Morimoto
94d7281993
ASoC: soc-dai: add snd_soc_dai_compr_get_metadata()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_get_metadata().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87eesdssi8.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:50 +01:00
Kuninori Morimoto
88b3a7dfe9
ASoC: soc-dai: add snd_soc_dai_compr_set_metadata()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_set_metadata().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87ftctssid.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:49 +01:00
Kuninori Morimoto
ed38cc5909
ASoC: soc-dai: add snd_soc_dai_compr_pointer()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_pointer().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87h7x9ssii.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:48 +01:00
Kuninori Morimoto
53294353a0
ASoC: soc-dai: add snd_soc_dai_compr_ack()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_ack().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87imhpssim.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:47 +01:00
Kuninori Morimoto
adbef54326
ASoC: soc-dai: add snd_soc_dai_compr_get_params()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_get_params().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87k125ssir.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:46 +01:00
Kuninori Morimoto
8dfedafb5c
ASoC: soc-dai: add snd_soc_dai_compr_set_params()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_set_params().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87lfmlssiv.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:45 +01:00
Kuninori Morimoto
eb08411bdf
ASoC: soc-dai: add snd_soc_dai_compr_trigger()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_trigger().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87mu71ssiz.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:44 +01:00
Kuninori Morimoto
2b25f81d43
ASoC: soc-dai: add snd_soc_dai_compr_shutdown()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_shutdown().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87o8rhssj3.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:43 +01:00
Kuninori Morimoto
b5ae4ccea5
ASoC: soc-dai: add snd_soc_dai_compr_start()
dai related function should be implemented at soc-dai.c.
This patch adds snd_soc_dai_compr_start().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87pnbxssj7.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-29 13:27:42 +01:00
Rong Chen
3e645a4add
ASoC: soc-compress: avoid false-positive Wuninitialized warning
gcc-6.5 and earlier show a new warning:

sound/soc/soc-compress.c: In function ‘soc_compr_open’:
sound/soc/soc-compress.c:75:28: warning: ‘component’ is used uninitialized in this function [-Wuninitialized]
  struct snd_soc_component *component, *save = NULL;
                              ^~~~~~~~~

Simplest fix is to initialize it to avoid the warning.

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Rong Chen <rong.a.chen@intel.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/lkml/202004201540.vYPhhYMs%25lkp@intel.com
Link: https://lore.kernel.org/r/20200424005437.3941-1-rong.a.chen@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-24 13:19:12 +01:00
Kuninori Morimoto
e7cbe52839
ASoC: soc-compress: remove snd_compr_ops
snd_compr_ops couldn't care called component,
but now we can care it via snd_compress_ops.
All drivers switched to it.
This patch removes snd_compr_ops.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87lfmqvdig.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-21 19:02:00 +01:00
Kuninori Morimoto
c6cb522c14
ASoC: soc-compress: add snd_compress_ops
Current snd_soc_component_driver has compr_ops, and each driver can
have callback via it. But, it is mainly created for ALSA, thus, it
doesn't have "component" as parameter.
Thus, each callback can't know it is called for which component.
Each callback currently is getting "component" by using
snd_soc_rtdcom_lookup() with driver name.

	--- ALSA SoC  ---
	...
	if (component->driver->compr_ops &&
	    component->driver->compr_ops->open)
=>		return component->driver->compr_ops->open(stream);
	...

	--- driver ---
	static int xxx_open(struct snd_compr_stream *stream)
	{
		struct snd_soc_pcm_runtime *rtd = stream->private_data;
=>		struct snd_soc_component *component = snd_soc_rtdcom_lookup(..);
		...
	}

It works today, but, will not work in the future if we support multi
CPU/Codec/Platform, because 1 rtd might have multiple same driver
name component.

To solve this issue, each callback need to be called with component.
We already have many component driver callbacks.
This patch adds new snd_compress_ops, and call it with "component".

	--- ALSA SoC  ---
	...
	if (component->driver->compress_ops->open)
=>		return component->driver->compress_ops->open(
			component, substream);
			~~~~~~~~~
	...

	--- driver ---
	static int xxx_open(struct snd_soc_component *component,
			    struct snd_compr_stream *stream)
	{
=>		/* it don't need to use snd_soc_rtdcom_lookup() */
		...
	}

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87v9luvdmh.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-21 19:01:54 +01:00
Kuninori Morimoto
c2233a2661
ASoC: soc: use asoc_rtd_to_cpu() / asoc_rtd_to_codec() macro for DAI pointer
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/87imimboli.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-04-14 14:00:44 +01:00
Bard Liao
6e1276a5e6
ASoC: Return error if the function does not support multi-cpu
Multi cpu is not supported by all functions yet. Add an error message
and return.

Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20200225133917.21314-6-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-02-26 17:35:04 +00:00