~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/sdw_utils/soc_sdw_cs42l43.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 // Based on sof_sdw_rt5682.c
  3 // This file incorporates work covered by the following copyright notice:
  4 // Copyright (c) 2023 Intel Corporation
  5 // Copyright (c) 2024 Advanced Micro Devices, Inc.
  6 
  7 /*
  8  *  soc_sdw_cs42l43 - Helpers to handle CS42L43 from generic machine driver
  9  */
 10 #include <linux/device.h>
 11 #include <linux/errno.h>
 12 #include <linux/input.h>
 13 #include <sound/jack.h>
 14 #include <linux/soundwire/sdw.h>
 15 #include <linux/soundwire/sdw_type.h>
 16 #include <sound/cs42l43.h>
 17 #include <sound/control.h>
 18 #include <sound/soc.h>
 19 #include <sound/soc-acpi.h>
 20 #include <sound/soc-dapm.h>
 21 #include <sound/soc_sdw_utils.h>
 22 
 23 static const struct snd_soc_dapm_route cs42l43_hs_map[] = {
 24         { "Headphone", NULL, "cs42l43 AMP3_OUT" },
 25         { "Headphone", NULL, "cs42l43 AMP4_OUT" },
 26         { "cs42l43 ADC1_IN1_P", NULL, "Headset Mic" },
 27         { "cs42l43 ADC1_IN1_N", NULL, "Headset Mic" },
 28 };
 29 
 30 static const struct snd_soc_dapm_route cs42l43_spk_map[] = {
 31         { "Speaker", NULL, "cs42l43 AMP1_OUT_P", },
 32         { "Speaker", NULL, "cs42l43 AMP1_OUT_N", },
 33         { "Speaker", NULL, "cs42l43 AMP2_OUT_P", },
 34         { "Speaker", NULL, "cs42l43 AMP2_OUT_N", },
 35 };
 36 
 37 static const struct snd_soc_dapm_route cs42l43_dmic_map[] = {
 38         { "cs42l43 PDM1_DIN", NULL, "DMIC" },
 39         { "cs42l43 PDM2_DIN", NULL, "DMIC" },
 40 };
 41 
 42 static struct snd_soc_jack_pin soc_jack_pins[] = {
 43         {
 44                 .pin    = "Headphone",
 45                 .mask   = SND_JACK_HEADPHONE,
 46         },
 47         {
 48                 .pin    = "Headset Mic",
 49                 .mask   = SND_JACK_MICROPHONE,
 50         },
 51 };
 52 
 53 int asoc_sdw_cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
 54 {
 55         struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
 56         struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(rtd->card);
 57         struct snd_soc_jack *jack = &ctx->sdw_headset;
 58         struct snd_soc_card *card = rtd->card;
 59         int ret;
 60 
 61         card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s hs:cs42l43",
 62                                           card->components);
 63         if (!card->components)
 64                 return -ENOMEM;
 65 
 66         ret = snd_soc_dapm_add_routes(&card->dapm, cs42l43_hs_map,
 67                                       ARRAY_SIZE(cs42l43_hs_map));
 68         if (ret) {
 69                 dev_err(card->dev, "cs42l43 hs map addition failed: %d\n", ret);
 70                 return ret;
 71         }
 72 
 73         ret = snd_soc_card_jack_new_pins(card, "Jack",
 74                                          SND_JACK_MECHANICAL | SND_JACK_AVOUT |
 75                                          SND_JACK_HEADSET | SND_JACK_LINEOUT |
 76                                          SND_JACK_BTN_0 | SND_JACK_BTN_1 |
 77                                          SND_JACK_BTN_2 | SND_JACK_BTN_3,
 78                                          jack, soc_jack_pins,
 79                                          ARRAY_SIZE(soc_jack_pins));
 80         if (ret) {
 81                 dev_err(card->dev, "Failed to create jack: %d\n", ret);
 82                 return ret;
 83         }
 84 
 85         snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
 86         snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
 87         snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
 88         snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
 89 
 90         ret = snd_soc_component_set_jack(component, jack, NULL);
 91         if (ret) {
 92                 dev_err(card->dev, "Failed to register jack: %d\n", ret);
 93                 return ret;
 94         }
 95 
 96         ret = snd_soc_component_set_sysclk(component, CS42L43_SYSCLK, CS42L43_SYSCLK_SDW,
 97                                            0, SND_SOC_CLOCK_IN);
 98         if (ret)
 99                 dev_err(card->dev, "Failed to set sysclk: %d\n", ret);
100 
101         return ret;
102 }
103 EXPORT_SYMBOL_NS(asoc_sdw_cs42l43_hs_rtd_init, SND_SOC_SDW_UTILS);
104 
105 int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
106 {
107         struct snd_soc_card *card = rtd->card;
108         struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
109         int ret;
110 
111         if (!(ctx->mc_quirk & SOC_SDW_SIDECAR_AMPS)) {
112                 /* Will be set by the bridge code in this case */
113                 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
114                                                   "%s spk:cs42l43-spk",
115                                                   card->components);
116                 if (!card->components)
117                         return -ENOMEM;
118         }
119 
120         ret = snd_soc_dapm_add_routes(&card->dapm, cs42l43_spk_map,
121                                       ARRAY_SIZE(cs42l43_spk_map));
122         if (ret)
123                 dev_err(card->dev, "cs42l43 speaker map addition failed: %d\n", ret);
124 
125         return ret;
126 }
127 EXPORT_SYMBOL_NS(asoc_sdw_cs42l43_spk_rtd_init, SND_SOC_SDW_UTILS);
128 
129 int asoc_sdw_cs42l43_spk_init(struct snd_soc_card *card,
130                               struct snd_soc_dai_link *dai_links,
131                               struct asoc_sdw_codec_info *info,
132                               bool playback)
133 {
134         /* Do init on playback link only. */
135         if (!playback)
136                 return 0;
137 
138         info->amp_num++;
139 
140         return asoc_sdw_bridge_cs35l56_spk_init(card, dai_links, info, playback);
141 }
142 EXPORT_SYMBOL_NS(asoc_sdw_cs42l43_spk_init, SND_SOC_SDW_UTILS);
143 
144 int asoc_sdw_cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
145 {
146         struct snd_soc_card *card = rtd->card;
147         int ret;
148 
149         card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s mic:cs42l43-dmic",
150                                           card->components);
151         if (!card->components)
152                 return -ENOMEM;
153 
154         ret = snd_soc_dapm_add_routes(&card->dapm, cs42l43_dmic_map,
155                                       ARRAY_SIZE(cs42l43_dmic_map));
156         if (ret)
157                 dev_err(card->dev, "cs42l43 dmic map addition failed: %d\n", ret);
158 
159         return ret;
160 }
161 EXPORT_SYMBOL_NS(asoc_sdw_cs42l43_dmic_rtd_init, SND_SOC_SDW_UTILS);
162 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php