@@ -1116,6 +1116,60 @@ get_hda_cvt_setup(struct hda_codec *codec, hda_nid_t nid)
1116
1116
return p ;
1117
1117
}
1118
1118
1119
+ /*
1120
+ * PCM device
1121
+ */
1122
+ static void release_pcm (struct kref * kref )
1123
+ {
1124
+ struct hda_pcm * pcm = container_of (kref , struct hda_pcm , kref );
1125
+
1126
+ if (pcm -> pcm )
1127
+ snd_device_free (pcm -> codec -> card , pcm -> pcm );
1128
+ clear_bit (pcm -> device , pcm -> codec -> bus -> pcm_dev_bits );
1129
+ kfree (pcm -> name );
1130
+ kfree (pcm );
1131
+ }
1132
+
1133
+ void snd_hda_codec_pcm_put (struct hda_pcm * pcm )
1134
+ {
1135
+ kref_put (& pcm -> kref , release_pcm );
1136
+ }
1137
+ EXPORT_SYMBOL_GPL (snd_hda_codec_pcm_put );
1138
+
1139
+ struct hda_pcm * snd_hda_codec_pcm_new (struct hda_codec * codec ,
1140
+ const char * fmt , ...)
1141
+ {
1142
+ struct hda_pcm * pcm ;
1143
+ va_list args ;
1144
+
1145
+ va_start (args , fmt );
1146
+ pcm = kzalloc (sizeof (* pcm ), GFP_KERNEL );
1147
+ if (!pcm )
1148
+ return NULL ;
1149
+
1150
+ pcm -> codec = codec ;
1151
+ kref_init (& pcm -> kref );
1152
+ pcm -> name = kvasprintf (GFP_KERNEL , fmt , args );
1153
+ if (!pcm -> name ) {
1154
+ kfree (pcm );
1155
+ return NULL ;
1156
+ }
1157
+
1158
+ list_add_tail (& pcm -> list , & codec -> pcm_list_head );
1159
+ return pcm ;
1160
+ }
1161
+ EXPORT_SYMBOL_GPL (snd_hda_codec_pcm_new );
1162
+
1163
+ static void codec_release_pcms (struct hda_codec * codec )
1164
+ {
1165
+ struct hda_pcm * pcm , * n ;
1166
+
1167
+ list_for_each_entry_safe (pcm , n , & codec -> pcm_list_head , list ) {
1168
+ list_del_init (& pcm -> list );
1169
+ snd_hda_codec_pcm_put (pcm );
1170
+ }
1171
+ }
1172
+
1119
1173
/*
1120
1174
* codec destructor
1121
1175
*/
@@ -1124,6 +1178,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1124
1178
if (!codec )
1125
1179
return ;
1126
1180
cancel_delayed_work_sync (& codec -> jackpoll_work );
1181
+ codec_release_pcms (codec );
1127
1182
if (device_is_registered (hda_codec_dev (codec )))
1128
1183
device_del (hda_codec_dev (codec ));
1129
1184
snd_hda_jack_tbl_clear (codec );
@@ -1251,6 +1306,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
1251
1306
snd_array_init (& codec -> jacktbl , sizeof (struct hda_jack_tbl ), 16 );
1252
1307
snd_array_init (& codec -> verbs , sizeof (struct hda_verb * ), 8 );
1253
1308
INIT_LIST_HEAD (& codec -> conn_list );
1309
+ INIT_LIST_HEAD (& codec -> pcm_list_head );
1254
1310
1255
1311
INIT_DELAYED_WORK (& codec -> jackpoll_work , hda_jackpoll_work );
1256
1312
codec -> depop_delay = -1 ;
@@ -2370,9 +2426,8 @@ int snd_hda_lock_devices(struct hda_bus *bus)
2370
2426
goto err_clear ;
2371
2427
2372
2428
list_for_each_entry (codec , & bus -> codec_list , list ) {
2373
- int pcm ;
2374
- for (pcm = 0 ; pcm < codec -> num_pcms ; pcm ++ ) {
2375
- struct hda_pcm * cpcm = & codec -> pcm_info [pcm ];
2429
+ struct hda_pcm * cpcm ;
2430
+ list_for_each_entry (cpcm , & codec -> pcm_list_head , list ) {
2376
2431
if (!cpcm -> pcm )
2377
2432
continue ;
2378
2433
if (cpcm -> pcm -> streams [0 ].substream_opened ||
@@ -2419,8 +2474,6 @@ EXPORT_SYMBOL_GPL(snd_hda_unlock_devices);
2419
2474
int snd_hda_codec_reset (struct hda_codec * codec )
2420
2475
{
2421
2476
struct hda_bus * bus = codec -> bus ;
2422
- struct snd_card * card = codec -> card ;
2423
- int i ;
2424
2477
2425
2478
if (snd_hda_lock_devices (bus ) < 0 )
2426
2479
return - EBUSY ;
@@ -2429,14 +2482,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2429
2482
cancel_delayed_work_sync (& codec -> jackpoll_work );
2430
2483
flush_workqueue (bus -> workq );
2431
2484
snd_hda_ctls_clear (codec );
2432
- /* release PCMs */
2433
- for (i = 0 ; i < codec -> num_pcms ; i ++ ) {
2434
- if (codec -> pcm_info [i ].pcm ) {
2435
- snd_device_free (card , codec -> pcm_info [i ].pcm );
2436
- clear_bit (codec -> pcm_info [i ].device ,
2437
- bus -> pcm_dev_bits );
2438
- }
2439
- }
2485
+ codec_release_pcms (codec );
2440
2486
snd_hda_detach_beep_device (codec );
2441
2487
if (device_is_registered (hda_codec_dev (codec )))
2442
2488
device_del (hda_codec_dev (codec ));
@@ -2454,8 +2500,6 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2454
2500
snd_array_free (& codec -> cvt_setups );
2455
2501
snd_array_free (& codec -> spdif_out );
2456
2502
snd_array_free (& codec -> verbs );
2457
- codec -> num_pcms = 0 ;
2458
- codec -> pcm_info = NULL ;
2459
2503
codec -> preset = NULL ;
2460
2504
codec -> slave_dig_outs = NULL ;
2461
2505
codec -> spdif_status_reset = 0 ;
@@ -3952,12 +3996,12 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3952
3996
static int hda_codec_runtime_suspend (struct device * dev )
3953
3997
{
3954
3998
struct hda_codec * codec = dev_to_hda_codec (dev );
3999
+ struct hda_pcm * pcm ;
3955
4000
unsigned int state ;
3956
- int i ;
3957
4001
3958
4002
cancel_delayed_work_sync (& codec -> jackpoll_work );
3959
- for ( i = 0 ; i < codec -> num_pcms ; i ++ )
3960
- snd_pcm_suspend_all (codec -> pcm_info [ i ]. pcm );
4003
+ list_for_each_entry ( pcm , & codec -> pcm_list_head , list )
4004
+ snd_pcm_suspend_all (pcm -> pcm );
3961
4005
state = hda_call_codec_suspend (codec );
3962
4006
if (codec -> d3_stop_clk && codec -> epss && (state & AC_PWRST_CLK_STOP_OK ))
3963
4007
clear_bit (codec -> addr , & codec -> bus -> codec_powered );
@@ -4018,22 +4062,21 @@ EXPORT_SYMBOL_GPL(snd_hda_build_controls);
4018
4062
*/
4019
4063
static int add_std_chmaps (struct hda_codec * codec )
4020
4064
{
4021
- int i , str , err ;
4065
+ struct hda_pcm * pcm ;
4066
+ int str , err ;
4022
4067
4023
- for ( i = 0 ; i < codec -> num_pcms ; i ++ ) {
4068
+ list_for_each_entry ( pcm , & codec -> pcm_list_head , list ) {
4024
4069
for (str = 0 ; str < 2 ; str ++ ) {
4025
- struct snd_pcm * pcm = codec -> pcm_info [i ].pcm ;
4026
- struct hda_pcm_stream * hinfo =
4027
- & codec -> pcm_info [i ].stream [str ];
4070
+ struct hda_pcm_stream * hinfo = & pcm -> stream [str ];
4028
4071
struct snd_pcm_chmap * chmap ;
4029
4072
const struct snd_pcm_chmap_elem * elem ;
4030
4073
4031
- if (codec -> pcm_info [ i ]. own_chmap )
4074
+ if (pcm -> own_chmap )
4032
4075
continue ;
4033
4076
if (!pcm || !hinfo -> substreams )
4034
4077
continue ;
4035
4078
elem = hinfo -> chmap ? hinfo -> chmap : snd_pcm_std_chmaps ;
4036
- err = snd_pcm_add_chmap_ctls (pcm , str , elem ,
4079
+ err = snd_pcm_add_chmap_ctls (pcm -> pcm , str , elem ,
4037
4080
hinfo -> channels_max ,
4038
4081
0 , & chmap );
4039
4082
if (err < 0 )
@@ -4564,10 +4607,10 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
4564
4607
/* call build_pcms ops of the given codec and set up the default parameters */
4565
4608
int snd_hda_codec_parse_pcms (struct hda_codec * codec )
4566
4609
{
4567
- unsigned int pcm ;
4610
+ struct hda_pcm * cpcm ;
4568
4611
int err ;
4569
4612
4570
- if (codec -> num_pcms )
4613
+ if (! list_empty ( & codec -> pcm_list_head ) )
4571
4614
return 0 ; /* already parsed */
4572
4615
4573
4616
if (!codec -> patch_ops .build_pcms )
@@ -4580,17 +4623,14 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec)
4580
4623
return err ;
4581
4624
}
4582
4625
4583
- for (pcm = 0 ; pcm < codec -> num_pcms ; pcm ++ ) {
4584
- struct hda_pcm * cpcm = & codec -> pcm_info [pcm ];
4626
+ list_for_each_entry (cpcm , & codec -> pcm_list_head , list ) {
4585
4627
int stream ;
4586
4628
4587
4629
for (stream = 0 ; stream < 2 ; stream ++ ) {
4588
4630
struct hda_pcm_stream * info = & cpcm -> stream [stream ];
4589
4631
4590
4632
if (!info -> substreams )
4591
4633
continue ;
4592
- if (snd_BUG_ON (!cpcm -> name ))
4593
- return - EINVAL ;
4594
4634
err = set_pcm_default_values (codec , info );
4595
4635
if (err < 0 ) {
4596
4636
codec_warn (codec ,
@@ -4608,7 +4648,7 @@ int snd_hda_codec_parse_pcms(struct hda_codec *codec)
4608
4648
int snd_hda_codec_build_pcms (struct hda_codec * codec )
4609
4649
{
4610
4650
struct hda_bus * bus = codec -> bus ;
4611
- unsigned int pcm ;
4651
+ struct hda_pcm * cpcm ;
4612
4652
int dev , err ;
4613
4653
4614
4654
if (snd_BUG_ON (!bus -> ops .attach_pcm ))
@@ -4621,9 +4661,7 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
4621
4661
}
4622
4662
4623
4663
/* attach a new PCM streams */
4624
- for (pcm = 0 ; pcm < codec -> num_pcms ; pcm ++ ) {
4625
- struct hda_pcm * cpcm = & codec -> pcm_info [pcm ];
4626
-
4664
+ list_for_each_entry (cpcm , & codec -> pcm_list_head , list ) {
4627
4665
if (cpcm -> pcm )
4628
4666
continue ; /* already attached */
4629
4667
if (!cpcm -> stream [0 ].substreams && !cpcm -> stream [1 ].substreams )
@@ -4651,11 +4689,9 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
4651
4689
*
4652
4690
* Create PCM information for each codec included in the bus.
4653
4691
*
4654
- * The build_pcms codec patch is requested to set up codec->num_pcms and
4655
- * codec->pcm_info properly. The array is referred by the top-level driver
4656
- * to create its PCM instances.
4657
- * The allocated codec->pcm_info should be released in codec->patch_ops.free
4658
- * callback.
4692
+ * The build_pcms codec patch is requested to create and assign new
4693
+ * hda_pcm objects. The codec is responsible to call snd_hda_codec_pcm_new()
4694
+ * and fills the fields. Later they are instantiated by this function.
4659
4695
*
4660
4696
* At least, substreams, channels_min and channels_max must be filled for
4661
4697
* each stream. substreams = 0 indicates that the stream doesn't exist.
0 commit comments