2020-05-28 10:47:46 +09:00
/* SPDX-License-Identifier: GPL-2.0
*
* soc - card . h
*
* Copyright ( C ) 2019 Renesas Electronics Corp .
* Kuninori Morimoto < kuninori . morimoto . gx @ renesas . com >
*/
# ifndef __SOC_CARD_H
# define __SOC_CARD_H
2020-05-28 10:48:28 +09:00
enum snd_soc_card_subclass {
2023-04-06 00:16:27 +00:00
SND_SOC_CARD_CLASS_ROOT = 0 ,
2020-05-28 10:48:28 +09:00
SND_SOC_CARD_CLASS_RUNTIME = 1 ,
} ;
2023-04-06 00:16:27 +00:00
static inline void snd_soc_card_mutex_lock_root ( struct snd_soc_card * card )
{
mutex_lock_nested ( & card - > mutex , SND_SOC_CARD_CLASS_ROOT ) ;
}
static inline void snd_soc_card_mutex_lock ( struct snd_soc_card * card )
{
mutex_lock_nested ( & card - > mutex , SND_SOC_CARD_CLASS_RUNTIME ) ;
}
static inline void snd_soc_card_mutex_unlock ( struct snd_soc_card * card )
{
mutex_unlock ( & card - > mutex ) ;
}
2020-05-28 10:47:56 +09:00
struct snd_kcontrol * snd_soc_card_get_kcontrol ( struct snd_soc_card * soc_card ,
const char * name ) ;
ASoC: soc-card: Fix missing locking in snd_soc_card_get_kcontrol()
[ Upstream commit eba2eb2495f47690400331c722868902784e59de ]
snd_soc_card_get_kcontrol() must be holding a read lock on
card->controls_rwsem while walking the controls list.
Compare with snd_ctl_find_numid().
The existing function is renamed snd_soc_card_get_kcontrol_locked()
so that it can be called from contexts that are already holding
card->controls_rwsem (for example, control get/put functions).
There are few direct or indirect callers of
snd_soc_card_get_kcontrol(), and most are safe. Three require
changes, which have been included in this patch:
codecs/cs35l45.c:
cs35l45_activate_ctl() is called from a control put() function so
is changed to call snd_soc_card_get_kcontrol_locked().
codecs/cs35l56.c:
cs35l56_sync_asp1_mixer_widgets_with_firmware() is called from
control get()/put() functions so is changed to call
snd_soc_card_get_kcontrol_locked().
fsl/fsl_xcvr.c:
fsl_xcvr_activate_ctl() is called from three places, one of which
already holds card->controls_rwsem:
1. fsl_xcvr_mode_put(), a control put function, which will
already be holding card->controls_rwsem.
2. fsl_xcvr_startup(), a DAI startup function.
3. fsl_xcvr_shutdown(), a DAI shutdown function.
To fix this, fsl_xcvr_activate_ctl() has been changed to call
snd_soc_card_get_kcontrol_locked() so that it is safe to call
directly from fsl_xcvr_mode_put().
The fsl_xcvr_startup() and fsl_xcvr_shutdown() functions have been
changed to take a read lock on card->controls_rsem() around calls
to fsl_xcvr_activate_ctl(). While this is not very elegant, it
keeps the change small, to avoid this patch creating a large
collateral churn in fsl/fsl_xcvr.c.
Analysis of other callers of snd_soc_card_get_kcontrol() is that
they do not need any changes, they are not holding card->controls_rwsem
when they call snd_soc_card_get_kcontrol().
Direct callers of snd_soc_card_get_kcontrol():
fsl/fsl_spdif.c: fsl_spdif_dai_probe() - DAI probe function
fsl/fsl_micfil.c: voice_detected_fn() - IRQ handler
Indirect callers via soc_component_notify_control():
codecs/cs42l43: cs42l43_mic_shutter() - IRQ handler
codecs/cs42l43: cs42l43_spk_shutter() - IRQ handler
codecs/ak4118.c: ak4118_irq_handler() - IRQ handler
codecs/wm_adsp.c: wm_adsp_write_ctl() - not currently used
Indirect callers via snd_soc_limit_volume():
qcom/sc8280xp.c: sc8280xp_snd_init() - DAIlink init function
ti/rx51.c: rx51_aic34_init() - DAI init function
I don't have hardware to test the fsl/*, qcom/sc828xp.c, ti/rx51.c
and ak4118.c changes.
Backport note:
The fsl/, qcom/, cs35l45, cs35l56 and cs42l43 callers were added
since the Fixes commit so won't all be present on older kernels.
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 209c6cdfd283 ("ASoC: soc-card: move snd_soc_card_get_kcontrol() to soc-card")
Link: https://lore.kernel.org/r/20240221123710.690224-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-02-21 12:37:10 +00:00
struct snd_kcontrol * snd_soc_card_get_kcontrol_locked ( struct snd_soc_card * soc_card ,
const char * name ) ;
2020-05-28 10:48:03 +09:00
int snd_soc_card_jack_new ( struct snd_soc_card * card , const char * id , int type ,
2022-04-08 13:11:14 +09:00
struct snd_soc_jack * jack ) ;
int snd_soc_card_jack_new_pins ( struct snd_soc_card * card , const char * id ,
int type , struct snd_soc_jack * jack ,
struct snd_soc_jack_pin * pins ,
unsigned int num_pins ) ;
2020-05-28 10:47:56 +09:00
2020-05-28 10:48:39 +09:00
int snd_soc_card_suspend_pre ( struct snd_soc_card * card ) ;
2020-05-28 10:48:48 +09:00
int snd_soc_card_suspend_post ( struct snd_soc_card * card ) ;
2020-05-28 10:48:55 +09:00
int snd_soc_card_resume_pre ( struct snd_soc_card * card ) ;
2020-05-28 10:49:02 +09:00
int snd_soc_card_resume_post ( struct snd_soc_card * card ) ;
2020-05-28 10:48:39 +09:00
2020-05-28 10:49:11 +09:00
int snd_soc_card_probe ( struct snd_soc_card * card ) ;
2020-05-28 10:49:20 +09:00
int snd_soc_card_late_probe ( struct snd_soc_card * card ) ;
2022-06-06 21:19:09 +02:00
void snd_soc_card_fixup_controls ( struct snd_soc_card * card ) ;
2020-05-28 10:49:26 +09:00
int snd_soc_card_remove ( struct snd_soc_card * card ) ;
2020-05-28 10:49:11 +09:00
2020-05-28 10:49:35 +09:00
int snd_soc_card_set_bias_level ( struct snd_soc_card * card ,
struct snd_soc_dapm_context * dapm ,
enum snd_soc_bias_level level ) ;
2020-05-28 10:50:35 +09:00
int snd_soc_card_set_bias_level_post ( struct snd_soc_card * card ,
struct snd_soc_dapm_context * dapm ,
enum snd_soc_bias_level level ) ;
2020-05-28 10:49:35 +09:00
2020-05-28 10:50:41 +09:00
int snd_soc_card_add_dai_link ( struct snd_soc_card * card ,
struct snd_soc_dai_link * dai_link ) ;
2020-05-28 10:50:46 +09:00
void snd_soc_card_remove_dai_link ( struct snd_soc_card * card ,
struct snd_soc_dai_link * dai_link ) ;
2020-05-28 10:50:41 +09:00
2023-09-12 17:32:04 +01:00
# ifdef CONFIG_PCI
static inline void snd_soc_card_set_pci_ssid ( struct snd_soc_card * card ,
unsigned short vendor ,
unsigned short device )
{
card - > pci_subsystem_vendor = vendor ;
card - > pci_subsystem_device = device ;
card - > pci_subsystem_set = true ;
}
static inline int snd_soc_card_get_pci_ssid ( struct snd_soc_card * card ,
unsigned short * vendor ,
unsigned short * device )
{
if ( ! card - > pci_subsystem_set )
return - ENOENT ;
* vendor = card - > pci_subsystem_vendor ;
* device = card - > pci_subsystem_device ;
return 0 ;
}
# else /* !CONFIG_PCI */
static inline void snd_soc_card_set_pci_ssid ( struct snd_soc_card * card ,
unsigned short vendor ,
unsigned short device )
{
}
static inline int snd_soc_card_get_pci_ssid ( struct snd_soc_card * card ,
unsigned short * vendor ,
unsigned short * device )
{
return - ENOENT ;
}
# endif /* CONFIG_PCI */
2020-05-28 10:48:11 +09:00
/* device driver data */
static inline void snd_soc_card_set_drvdata ( struct snd_soc_card * card ,
void * data )
{
card - > drvdata = data ;
}
static inline void * snd_soc_card_get_drvdata ( struct snd_soc_card * card )
{
return card - > drvdata ;
}
2020-05-28 10:48:20 +09:00
static inline
struct snd_soc_dai * snd_soc_card_get_codec_dai ( struct snd_soc_card * card ,
const char * dai_name )
{
struct snd_soc_pcm_runtime * rtd ;
for_each_card_rtds ( card , rtd ) {
2023-09-11 23:47:02 +00:00
if ( ! strcmp ( snd_soc_rtd_to_codec ( rtd , 0 ) - > name , dai_name ) )
return snd_soc_rtd_to_codec ( rtd , 0 ) ;
2020-05-28 10:48:20 +09:00
}
return NULL ;
}
2020-05-28 10:47:46 +09:00
# endif /* __SOC_CARD_H */