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

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/hda.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 ] ~

Diff markup

Differences between /sound/soc/codecs/hda.c (Version linux-6.12-rc7) and /sound/soc/codecs/hda.c (Version linux-3.10.108)


  1 // SPDX-License-Identifier: GPL-2.0                 1 
  2 //                                                
  3 // Copyright(c) 2021-2022 Intel Corporation       
  4 //                                                
  5 // Author: Cezary Rojewski <cezary.rojewski@in    
  6 //                                                
  7                                                   
  8 #include <linux/module.h>                         
  9 #include <linux/pm_runtime.h>                     
 10 #include <sound/soc.h>                            
 11 #include <sound/hdaudio_ext.h>                    
 12 #include <sound/hda_i915.h>                       
 13 #include <sound/hda_codec.h>                      
 14 #include "hda.h"                                  
 15                                                   
 16 static int hda_codec_create_dais(struct hda_co    
 17                                  struct snd_so    
 18 {                                                 
 19         struct device *dev = &codec->core.dev;    
 20         struct snd_soc_dai_driver *drvs;          
 21         struct hda_pcm *pcm;                      
 22         int i;                                    
 23                                                   
 24         drvs = devm_kcalloc(dev, pcm_count, si    
 25         if (!drvs)                                
 26                 return -ENOMEM;                   
 27                                                   
 28         pcm = list_first_entry(&codec->pcm_lis    
 29                                                   
 30         for (i = 0; i < pcm_count; i++, pcm =     
 31                 struct snd_soc_pcm_stream *str    
 32                 int dir;                          
 33                                                   
 34                 dev_info(dev, "creating for %s    
 35                 drvs[i].id = i;                   
 36                 drvs[i].name = pcm->name;         
 37                 drvs[i].ops = &snd_soc_hda_cod    
 38                                                   
 39                 dir = SNDRV_PCM_STREAM_PLAYBAC    
 40                 stream = &drvs[i].playback;       
 41                 if (!pcm->stream[dir].substrea    
 42                         dev_info(dev, "skippin    
 43                         goto capture_dais;        
 44                 }                                 
 45                                                   
 46                 stream->stream_name =             
 47                         devm_kasprintf(dev, GF    
 48                                        snd_pcm    
 49                 if (!stream->stream_name)         
 50                         return -ENOMEM;           
 51                 stream->channels_min = pcm->st    
 52                 stream->channels_max = pcm->st    
 53                 stream->rates = pcm->stream[di    
 54                 stream->formats = pcm->stream[    
 55                 stream->subformats = pcm->stre    
 56                 stream->sig_bits = pcm->stream    
 57                                                   
 58 capture_dais:                                     
 59                 dir = SNDRV_PCM_STREAM_CAPTURE    
 60                 stream = &drvs[i].capture;        
 61                 if (!pcm->stream[dir].substrea    
 62                         dev_info(dev, "skippin    
 63                         continue;                 
 64                 }                                 
 65                                                   
 66                 stream->stream_name =             
 67                         devm_kasprintf(dev, GF    
 68                                        snd_pcm    
 69                 if (!stream->stream_name)         
 70                         return -ENOMEM;           
 71                 stream->channels_min = pcm->st    
 72                 stream->channels_max = pcm->st    
 73                 stream->rates = pcm->stream[di    
 74                 stream->formats = pcm->stream[    
 75                 stream->subformats = pcm->stre    
 76                 stream->sig_bits = pcm->stream    
 77         }                                         
 78                                                   
 79         *drivers = drvs;                          
 80         return 0;                                 
 81 }                                                 
 82                                                   
 83 static int hda_codec_register_dais(struct hda_    
 84 {                                                 
 85         struct snd_soc_dai_driver *drvs = NULL    
 86         struct snd_soc_dapm_context *dapm;        
 87         struct hda_pcm *pcm;                      
 88         int ret, pcm_count = 0;                   
 89                                                   
 90         if (list_empty(&codec->pcm_list_head))    
 91                 return -EINVAL;                   
 92         list_for_each_entry(pcm, &codec->pcm_l    
 93                 pcm_count++;                      
 94                                                   
 95         ret = hda_codec_create_dais(codec, pcm    
 96         if (ret < 0)                              
 97                 return ret;                       
 98                                                   
 99         dapm = snd_soc_component_get_dapm(comp    
100                                                   
101         list_for_each_entry(pcm, &codec->pcm_l    
102                 struct snd_soc_dai *dai;          
103                                                   
104                 dai = snd_soc_register_dai(com    
105                 if (!dai) {                       
106                         dev_err(component->dev    
107                         return -EINVAL;           
108                 }                                 
109                                                   
110                 ret = snd_soc_dapm_new_dai_wid    
111                 if (ret < 0) {                    
112                         dev_err(component->dev    
113                         snd_soc_unregister_dai    
114                         return ret;               
115                 }                                 
116                                                   
117                 snd_soc_dai_init_dma_data(dai,    
118                 drvs++;                           
119         }                                         
120                                                   
121         return 0;                                 
122 }                                                 
123                                                   
124 static void hda_codec_unregister_dais(struct h    
125                                       struct s    
126 {                                                 
127         struct snd_soc_dai *dai, *save;           
128         struct hda_pcm *pcm;                      
129                                                   
130         for_each_component_dais_safe(component    
131                 int stream;                       
132                                                   
133                 list_for_each_entry(pcm, &code    
134                         if (strcmp(dai->driver    
135                                 continue;         
136                                                   
137                         for_each_pcm_streams(s    
138                                 snd_soc_dapm_f    
139                                                   
140                         snd_soc_unregister_dai    
141                         break;                    
142                 }                                 
143         }                                         
144 }                                                 
145                                                   
146 int hda_codec_probe_complete(struct hda_codec     
147 {                                                 
148         struct hdac_device *hdev = &codec->cor    
149         struct hdac_bus *bus = hdev->bus;         
150         int ret;                                  
151                                                   
152         ret = snd_hda_codec_build_controls(cod    
153         if (ret < 0) {                            
154                 dev_err(&hdev->dev, "unable to    
155                 goto out;                         
156         }                                         
157                                                   
158         /* Bus suspended codecs as it does not    
159         pm_runtime_set_active(&hdev->dev);        
160         /* rpm was forbidden in snd_hda_codec_    
161         snd_hda_codec_set_power_save(codec, 20    
162         snd_hda_codec_register(codec);            
163 out:                                              
164         /* Complement pm_runtime_get_sync(bus)    
165         pm_runtime_mark_last_busy(bus->dev);      
166         pm_runtime_put_autosuspend(bus->dev);     
167                                                   
168         return ret;                               
169 }                                                 
170 EXPORT_SYMBOL_GPL(hda_codec_probe_complete);      
171                                                   
172 /* Expects codec with usage_count=1 and status    
173 static int hda_codec_probe(struct snd_soc_comp    
174 {                                                 
175         struct hda_codec *codec = dev_to_hda_c    
176         struct hdac_device *hdev = &codec->cor    
177         struct hdac_bus *bus = hdev->bus;         
178         struct hdac_ext_link *hlink;              
179         hda_codec_patch_t patch;                  
180         int ret;                                  
181                                                   
182 #ifdef CONFIG_PM                                  
183         WARN_ON(atomic_read(&hdev->dev.power.u    
184                 !pm_runtime_status_suspended(&    
185 #endif                                            
186                                                   
187         hlink = snd_hdac_ext_bus_get_hlink_by_    
188         if (!hlink) {                             
189                 dev_err(&hdev->dev, "hdac link    
190                 return -EIO;                      
191         }                                         
192                                                   
193         pm_runtime_get_sync(bus->dev);            
194         if (hda_codec_is_display(codec))          
195                 snd_hdac_display_power(bus, hd    
196         snd_hdac_ext_bus_link_get(bus, hlink);    
197                                                   
198         ret = snd_hda_codec_device_new(codec->    
199                                        false);    
200         if (ret < 0) {                            
201                 dev_err(&hdev->dev, "codec cre    
202                 goto device_new_err;              
203         }                                         
204                                                   
205         ret = snd_hda_codec_set_name(codec, co    
206         if (ret < 0) {                            
207                 dev_err(&hdev->dev, "set name:    
208                 goto err;                         
209         }                                         
210                                                   
211         ret = snd_hdac_regmap_init(&codec->cor    
212         if (ret < 0) {                            
213                 dev_err(&hdev->dev, "regmap in    
214                 goto err;                         
215         }                                         
216                                                   
217         patch = (hda_codec_patch_t)codec->pres    
218         if (!patch) {                             
219                 dev_err(&hdev->dev, "no patch     
220                 ret = -EINVAL;                    
221                 goto err;                         
222         }                                         
223                                                   
224         ret = patch(codec);                       
225         if (ret < 0) {                            
226                 dev_err(&hdev->dev, "codec ini    
227                 goto err;                         
228         }                                         
229                                                   
230         ret = snd_hda_codec_parse_pcms(codec);    
231         if (ret < 0) {                            
232                 dev_err(&hdev->dev, "unable to    
233                 goto parse_pcms_err;              
234         }                                         
235                                                   
236         ret = hda_codec_register_dais(codec, c    
237         if (ret < 0) {                            
238                 dev_err(&hdev->dev, "update da    
239                 goto parse_pcms_err;              
240         }                                         
241                                                   
242         if (!hda_codec_is_display(codec)) {       
243                 ret = hda_codec_probe_complete    
244                 if (ret < 0)                      
245                         goto complete_err;        
246         }                                         
247                                                   
248         codec->core.lazy_cache = true;            
249                                                   
250         return 0;                                 
251                                                   
252 complete_err:                                     
253         hda_codec_unregister_dais(codec, compo    
254 parse_pcms_err:                                   
255         if (codec->patch_ops.free)                
256                 codec->patch_ops.free(codec);     
257 err:                                              
258         snd_hda_codec_cleanup_for_unbind(codec    
259 device_new_err:                                   
260         if (hda_codec_is_display(codec))          
261                 snd_hdac_display_power(bus, hd    
262                                                   
263         snd_hdac_ext_bus_link_put(bus, hlink);    
264                                                   
265         pm_runtime_mark_last_busy(bus->dev);      
266         pm_runtime_put_autosuspend(bus->dev);     
267         return ret;                               
268 }                                                 
269                                                   
270 /* Leaves codec with usage_count=1 and status=    
271 static void hda_codec_remove(struct snd_soc_co    
272 {                                                 
273         struct hda_codec *codec = dev_to_hda_c    
274         struct hdac_device *hdev = &codec->cor    
275         struct hdac_bus *bus = hdev->bus;         
276         struct hdac_ext_link *hlink;              
277         bool was_registered = codec->core.regi    
278                                                   
279         /* Don't allow any more runtime suspen    
280         pm_runtime_forbid(&hdev->dev);            
281                                                   
282         hda_codec_unregister_dais(codec, compo    
283                                                   
284         if (codec->patch_ops.free)                
285                 codec->patch_ops.free(codec);     
286                                                   
287         snd_hda_codec_cleanup_for_unbind(codec    
288         pm_runtime_put_noidle(&hdev->dev);        
289         /* snd_hdac_device_exit() is only call    
290         pm_runtime_set_suspended(&hdev->dev);     
291                                                   
292         if (hda_codec_is_display(codec))          
293                 snd_hdac_display_power(bus, hd    
294                                                   
295         hlink = snd_hdac_ext_bus_get_hlink_by_    
296         if (hlink)                                
297                 snd_hdac_ext_bus_link_put(bus,    
298         /*                                        
299          * HDMI card's hda_codec_probe_complet    
300          * not be called due to early error, l    
301          */                                       
302         if (!was_registered) {                    
303                 pm_runtime_mark_last_busy(bus-    
304                 pm_runtime_put_autosuspend(bus    
305         }                                         
306                                                   
307 #ifdef CONFIG_PM                                  
308         WARN_ON(atomic_read(&hdev->dev.power.u    
309                 !pm_runtime_status_suspended(&    
310 #endif                                            
311 }                                                 
312                                                   
313 static const struct snd_soc_dapm_route hda_dap    
314         {"AIF1TX", NULL, "Codec Input Pin1"},     
315         {"AIF2TX", NULL, "Codec Input Pin2"},     
316         {"AIF3TX", NULL, "Codec Input Pin3"},     
317                                                   
318         {"Codec Output Pin1", NULL, "AIF1RX"},    
319         {"Codec Output Pin2", NULL, "AIF2RX"},    
320         {"Codec Output Pin3", NULL, "AIF3RX"},    
321 };                                                
322                                                   
323 static const struct snd_soc_dapm_widget hda_da    
324         /* Audio Interface */                     
325         SND_SOC_DAPM_AIF_IN("AIF1RX", "Analog     
326         SND_SOC_DAPM_AIF_IN("AIF2RX", "Digital    
327         SND_SOC_DAPM_AIF_IN("AIF3RX", "Alt Ana    
328         SND_SOC_DAPM_AIF_OUT("AIF1TX", "Analog    
329         SND_SOC_DAPM_AIF_OUT("AIF2TX", "Digita    
330         SND_SOC_DAPM_AIF_OUT("AIF3TX", "Alt An    
331                                                   
332         /* Input Pins */                          
333         SND_SOC_DAPM_INPUT("Codec Input Pin1")    
334         SND_SOC_DAPM_INPUT("Codec Input Pin2")    
335         SND_SOC_DAPM_INPUT("Codec Input Pin3")    
336                                                   
337         /* Output Pins */                         
338         SND_SOC_DAPM_OUTPUT("Codec Output Pin1    
339         SND_SOC_DAPM_OUTPUT("Codec Output Pin2    
340         SND_SOC_DAPM_OUTPUT("Codec Output Pin3    
341 };                                                
342                                                   
343 static struct snd_soc_dai_driver card_binder_d    
344         .id = -1,                                 
345         .name = "codec-probing-DAI",              
346 };                                                
347                                                   
348 static int hda_hdev_attach(struct hdac_device     
349 {                                                 
350         struct hda_codec *codec = dev_to_hda_c    
351         struct snd_soc_component_driver *comp_    
352                                                   
353         if (hda_codec_is_display(codec) && !hd    
354                 dev_dbg(&hdev->dev, "no i915,     
355                 return -ENODEV;                   
356         }                                         
357                                                   
358         comp_drv = devm_kzalloc(&hdev->dev, si    
359         if (!comp_drv)                            
360                 return -ENOMEM;                   
361                                                   
362         /*                                        
363          * It's save to rely on dev_name() rat    
364          * driver's lifetime is directly tied     
365          */                                       
366         comp_drv->name = dev_name(&hdev->dev);    
367         comp_drv->probe = hda_codec_probe;        
368         comp_drv->remove = hda_codec_remove;      
369         comp_drv->idle_bias_on = false;           
370         if (!hda_codec_is_display(codec)) {       
371                 comp_drv->dapm_widgets = hda_d    
372                 comp_drv->num_dapm_widgets = A    
373                 comp_drv->dapm_routes = hda_da    
374                 comp_drv->num_dapm_routes = AR    
375         }                                         
376                                                   
377         return snd_soc_register_component(&hde    
378 }                                                 
379                                                   
380 static int hda_hdev_detach(struct hdac_device     
381 {                                                 
382         struct hda_codec *codec = dev_to_hda_c    
383                                                   
384         if (codec->core.registered)               
385                 cancel_delayed_work_sync(&code    
386                                                   
387         snd_soc_unregister_component(&hdev->de    
388                                                   
389         return 0;                                 
390 }                                                 
391                                                   
392 const struct hdac_ext_bus_ops soc_hda_ext_bus_    
393         .hdev_attach = hda_hdev_attach,           
394         .hdev_detach = hda_hdev_detach,           
395 };                                                
396 EXPORT_SYMBOL_GPL(soc_hda_ext_bus_ops);           
397                                                   
398 MODULE_DESCRIPTION("HD-Audio codec driver");      
399 MODULE_AUTHOR("Cezary Rojewski <cezary.rojewsk    
400 MODULE_LICENSE("GPL");                            
401                                                   

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