Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / sound / soc / codecs / cs42l43-sdw.c
blob336e88a7a987ce5edbc94590a59bddcf811ff880
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.
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 <linux/soundwire/sdw.h>
13 #include <sound/pcm.h>
14 #include <sound/sdw.h>
15 #include <sound/soc-component.h>
16 #include <sound/soc-dai.h>
17 #include <sound/soc.h>
19 #include "cs42l43.h"
21 int cs42l43_sdw_add_peripheral(struct snd_pcm_substream *substream,
22 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
24 struct cs42l43_codec *priv = snd_soc_component_get_drvdata(dai->component);
25 struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
26 struct sdw_slave *sdw = dev_to_sdw_dev(priv->dev->parent);
27 struct sdw_stream_config sconfig = {0};
28 struct sdw_port_config pconfig = {0};
29 int ret;
31 if (!sdw_stream)
32 return -EINVAL;
34 snd_sdw_params_to_config(substream, params, &sconfig, &pconfig);
35 pconfig.num = dai->id;
37 ret = sdw_stream_add_slave(sdw, &sconfig, &pconfig, 1, sdw_stream);
38 if (ret) {
39 dev_err(priv->dev, "Failed to add sdw stream: %d\n", ret);
40 return ret;
43 return 0;
45 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_add_peripheral, "SND_SOC_CS42L43");
47 int cs42l43_sdw_remove_peripheral(struct snd_pcm_substream *substream,
48 struct snd_soc_dai *dai)
50 struct cs42l43_codec *priv = snd_soc_component_get_drvdata(dai->component);
51 struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
52 struct sdw_slave *sdw = dev_to_sdw_dev(priv->dev->parent);
54 if (!sdw_stream)
55 return -EINVAL;
57 return sdw_stream_remove_slave(sdw, sdw_stream);
59 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_remove_peripheral, "SND_SOC_CS42L43");
61 int cs42l43_sdw_set_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction)
63 snd_soc_dai_dma_data_set(dai, direction, sdw_stream);
65 return 0;
67 EXPORT_SYMBOL_NS_GPL(cs42l43_sdw_set_stream, "SND_SOC_CS42L43");
69 MODULE_DESCRIPTION("CS42L43 CODEC SoundWire Driver");
70 MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.cirrus.com>");
71 MODULE_LICENSE("GPL");