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

TOMOYO Linux Cross Reference
Linux/sound/soc/intel/boards/sof_sdw_rt711.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 // Copyright (c) 2020 Intel Corporation
  3 
  4 /*
  5  *  sof_sdw_rt711 - Helpers to handle RT711 from generic machine driver
  6  */
  7 
  8 #include <linux/device.h>
  9 #include <linux/errno.h>
 10 #include <linux/input.h>
 11 #include <linux/soundwire/sdw.h>
 12 #include <linux/soundwire/sdw_type.h>
 13 #include <sound/control.h>
 14 #include <sound/soc.h>
 15 #include <sound/soc-acpi.h>
 16 #include <sound/soc-dapm.h>
 17 #include <sound/jack.h>
 18 #include "sof_sdw_common.h"
 19 
 20 /*
 21  * Note this MUST be called before snd_soc_register_card(), so that the props
 22  * are in place before the codec component driver's probe function parses them.
 23  */
 24 static int rt711_add_codec_device_props(struct device *sdw_dev)
 25 {
 26         struct property_entry props[MAX_NO_PROPS] = {};
 27         struct fwnode_handle *fwnode;
 28         int ret;
 29 
 30         if (!SOF_JACK_JDSRC(sof_sdw_quirk))
 31                 return 0;
 32         props[0] = PROPERTY_ENTRY_U32("realtek,jd-src", SOF_JACK_JDSRC(sof_sdw_quirk));
 33 
 34         fwnode = fwnode_create_software_node(props, NULL);
 35         if (IS_ERR(fwnode))
 36                 return PTR_ERR(fwnode);
 37 
 38         ret = device_add_software_node(sdw_dev, to_software_node(fwnode));
 39 
 40         fwnode_handle_put(fwnode);
 41 
 42         return ret;
 43 }
 44 
 45 static const struct snd_soc_dapm_route rt711_map[] = {
 46         /* Headphones */
 47         { "Headphone", NULL, "rt711 HP" },
 48         { "rt711 MIC2", NULL, "Headset Mic" },
 49 };
 50 
 51 static struct snd_soc_jack_pin rt711_jack_pins[] = {
 52         {
 53                 .pin    = "Headphone",
 54                 .mask   = SND_JACK_HEADPHONE,
 55         },
 56         {
 57                 .pin    = "Headset Mic",
 58                 .mask   = SND_JACK_MICROPHONE,
 59         },
 60 };
 61 
 62 int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
 63 {
 64         struct snd_soc_card *card = rtd->card;
 65         struct mc_private *ctx = snd_soc_card_get_drvdata(card);
 66         struct snd_soc_component *component;
 67         struct snd_soc_jack *jack;
 68         int ret;
 69 
 70         component = dai->component;
 71         card->components = devm_kasprintf(card->dev, GFP_KERNEL,
 72                                           "%s hs:rt711",
 73                                           card->components);
 74         if (!card->components)
 75                 return -ENOMEM;
 76 
 77         ret = snd_soc_dapm_add_routes(&card->dapm, rt711_map,
 78                                       ARRAY_SIZE(rt711_map));
 79 
 80         if (ret) {
 81                 dev_err(card->dev, "rt711 map addition failed: %d\n", ret);
 82                 return ret;
 83         }
 84 
 85         ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
 86                                          SND_JACK_HEADSET | SND_JACK_BTN_0 |
 87                                          SND_JACK_BTN_1 | SND_JACK_BTN_2 |
 88                                          SND_JACK_BTN_3,
 89                                          &ctx->sdw_headset,
 90                                          rt711_jack_pins,
 91                                          ARRAY_SIZE(rt711_jack_pins));
 92         if (ret) {
 93                 dev_err(rtd->card->dev, "Headset Jack creation failed: %d\n",
 94                         ret);
 95                 return ret;
 96         }
 97 
 98         jack = &ctx->sdw_headset;
 99 
100         snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
101         snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
102         snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
103         snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
104 
105         ret = snd_soc_component_set_jack(component, jack, NULL);
106 
107         if (ret)
108                 dev_err(rtd->card->dev, "Headset Jack call-back failed: %d\n",
109                         ret);
110 
111         return ret;
112 }
113 
114 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
115 {
116         struct mc_private *ctx = snd_soc_card_get_drvdata(card);
117 
118         if (!ctx->headset_codec_dev)
119                 return 0;
120 
121         device_remove_software_node(ctx->headset_codec_dev);
122         put_device(ctx->headset_codec_dev);
123 
124         return 0;
125 }
126 
127 int sof_sdw_rt711_init(struct snd_soc_card *card,
128                        struct snd_soc_dai_link *dai_links,
129                        struct sof_sdw_codec_info *info,
130                        bool playback)
131 {
132         struct mc_private *ctx = snd_soc_card_get_drvdata(card);
133         struct device *sdw_dev;
134         int ret;
135 
136         /*
137          * headset should be initialized once.
138          * Do it with dai link for playback.
139          */
140         if (!playback)
141                 return 0;
142 
143         sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL, dai_links->codecs[0].name);
144         if (!sdw_dev)
145                 return -EPROBE_DEFER;
146 
147         ret = rt711_add_codec_device_props(sdw_dev);
148         if (ret < 0) {
149                 put_device(sdw_dev);
150                 return ret;
151         }
152         ctx->headset_codec_dev = sdw_dev;
153 
154         return 0;
155 }
156 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_BOARD_HELPERS);
157 

~ [ 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