1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // CS42L43 CODEC driver SoundWire handling 4 // 5 // Copyright (C) 2022-2023 Cirrus Logic, Inc. and 6 // Cirrus Logic International Semiconductor Ltd. 7 8 #include <linux/errno.h> 9 #include <linux/mfd/cs42l43.h> 10 #include <linux/mfd/cs42l43-regs.h> 11 #include <linux/module.h> 12 #include <sound/pcm.h> 13 #include <sound/sdw.h> 14 #include <sound/soc-component.h> 15 #include <sound/soc-dai.h> 16 #include <sound/soc.h> 17 18 #include "cs42l43.h" 19 20 int cs42l43_sdw_add_peripheral(struct snd_pcm_substream *substream, 21 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 22 { 23 struct cs42l43_codec *priv = snd_soc_component_get_drvdata(dai->component); 24 struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 25 struct sdw_slave *sdw = dev_to_sdw_dev(priv->dev->parent); 26 struct sdw_stream_config sconfig = {0}; 27 struct sdw_port_config pconfig = {0}; 28 int ret; 29 30 if (!sdw_stream) 31 return -EINVAL; 32 33 snd_sdw_params_to_config(substream, params, &sconfig, &pconfig); 34 pconfig.num = dai->id; 35 36 ret = sdw_stream_add_slave(sdw, &sconfig, &pconfig, 1, sdw_stream); 37 if (ret) { 38 dev_err(priv->dev, "Failed to add sdw stream: %d\n", ret); 39 return ret; 40 } 41 42 return 0; 43 } 44 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_add_peripheral, SND_SOC_CS42L43); 45 46 int cs42l43_sdw_remove_peripheral(struct snd_pcm_substream *substream, 47 struct snd_soc_dai *dai) 48 { 49 struct cs42l43_codec *priv = snd_soc_component_get_drvdata(dai->component); 50 struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); 51 struct sdw_slave *sdw = dev_to_sdw_dev(priv->dev->parent); 52 53 if (!sdw_stream) 54 return -EINVAL; 55 56 return sdw_stream_remove_slave(sdw, sdw_stream); 57 } 58 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_remove_peripheral, SND_SOC_CS42L43); 59 60 int cs42l43_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) 61 { 62 snd_soc_dai_dma_data_set(dai, direction, sdw_stream); 63 64 return 0; 65 } 66 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_set_stream, SND_SOC_CS42L43); 67 68 MODULE_DESCRIPTION("CS42L43 CODEC SoundWire Driver"); 69 MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.cirrus.com>"); 70 MODULE_LICENSE("GPL"); 71