2525#include <sound/control.h>
2626#include <sound/asoundef.h>
2727
28+ #define NUM_ATC_SRCS 6
29+ #define NUM_ATC_PCM (2 * 4)
30+
2831#define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */
2932#define MAX_MULTI_CHN 8
3033
@@ -1161,8 +1164,10 @@ static int atc_release_resources(struct ct_atc *atc)
11611164
11621165 if (atc -> daios ) {
11631166 daio_mgr = (struct daio_mgr * )atc -> rsc_mgrs [DAIO ];
1164- for (i = 0 ; i < atc -> n_daio ; i ++ ) {
1167+ for (i = 0 ; i < NUM_DAIOTYP ; i ++ ) {
11651168 daio = atc -> daios [i ];
1169+ if (!daio )
1170+ continue ;
11661171 if (daio -> output ) {
11671172 dao = container_of (daio , struct dao , daio );
11681173 dao -> ops -> clear_left_input (dao );
@@ -1176,25 +1181,29 @@ static int atc_release_resources(struct ct_atc *atc)
11761181
11771182 if (atc -> pcm ) {
11781183 sum_mgr = atc -> rsc_mgrs [SUM ];
1179- for (i = 0 ; i < atc -> n_pcm ; i ++ )
1180- sum_mgr -> put_sum (sum_mgr , atc -> pcm [i ]);
1184+ for (i = 0 ; i < NUM_ATC_PCM ; i ++ )
1185+ if (atc -> pcm [i ])
1186+ sum_mgr -> put_sum (sum_mgr , atc -> pcm [i ]);
11811187
11821188 kfree (atc -> pcm );
11831189 atc -> pcm = NULL ;
11841190 }
11851191
11861192 if (atc -> srcs ) {
11871193 src_mgr = atc -> rsc_mgrs [SRC ];
1188- for (i = 0 ; i < atc -> n_src ; i ++ )
1189- src_mgr -> put_src (src_mgr , atc -> srcs [i ]);
1194+ for (i = 0 ; i < NUM_ATC_SRCS ; i ++ )
1195+ if (atc -> srcs [i ])
1196+ src_mgr -> put_src (src_mgr , atc -> srcs [i ]);
11901197
11911198 kfree (atc -> srcs );
11921199 atc -> srcs = NULL ;
11931200 }
11941201
11951202 if (atc -> srcimps ) {
11961203 srcimp_mgr = atc -> rsc_mgrs [SRCIMP ];
1197- for (i = 0 ; i < atc -> n_srcimp ; i ++ ) {
1204+ for (i = 0 ; i < NUM_ATC_SRCS ; i ++ ) {
1205+ if (!atc -> srcimps [i ])
1206+ continue ;
11981207 srcimp = atc -> srcimps [i ];
11991208 srcimp -> ops -> unmap (srcimp );
12001209 srcimp_mgr -> put_srcimp (srcimp_mgr , atc -> srcimps [i ]);
@@ -1367,30 +1376,32 @@ static int atc_get_resources(struct ct_atc *atc)
13671376 struct srcimp_mgr * srcimp_mgr ;
13681377 struct sum_desc sum_dsc = {0 };
13691378 struct sum_mgr * sum_mgr ;
1370- int err , i , num_srcs , num_daios ;
1379+ struct capabilities cap ;
1380+ int err , i ;
13711381
1372- num_daios = ((atc -> model == CTSB1270 ) ? 8 : 7 );
1373- num_srcs = ((atc -> model == CTSB1270 ) ? 6 : 4 );
1382+ cap = atc -> capabilities (atc );
13741383
1375- atc -> daios = kcalloc (num_daios , sizeof (void * ), GFP_KERNEL );
1384+ atc -> daios = kcalloc (NUM_DAIOTYP , sizeof (void * ), GFP_KERNEL );
13761385 if (!atc -> daios )
13771386 return - ENOMEM ;
13781387
1379- atc -> srcs = kcalloc (num_srcs , sizeof (void * ), GFP_KERNEL );
1388+ atc -> srcs = kcalloc (NUM_ATC_SRCS , sizeof (void * ), GFP_KERNEL );
13801389 if (!atc -> srcs )
13811390 return - ENOMEM ;
13821391
1383- atc -> srcimps = kcalloc (num_srcs , sizeof (void * ), GFP_KERNEL );
1392+ atc -> srcimps = kcalloc (NUM_ATC_SRCS , sizeof (void * ), GFP_KERNEL );
13841393 if (!atc -> srcimps )
13851394 return - ENOMEM ;
13861395
1387- atc -> pcm = kcalloc (2 * 4 , sizeof (void * ), GFP_KERNEL );
1396+ atc -> pcm = kcalloc (NUM_ATC_PCM , sizeof (void * ), GFP_KERNEL );
13881397 if (!atc -> pcm )
13891398 return - ENOMEM ;
13901399
13911400 daio_mgr = (struct daio_mgr * )atc -> rsc_mgrs [DAIO ];
13921401 da_desc .msr = atc -> msr ;
1393- for (i = 0 , atc -> n_daio = 0 ; i < num_daios ; i ++ ) {
1402+ for (i = 0 ; i < NUM_DAIOTYP ; i ++ ) {
1403+ if ((i == MIC ) && !cap .dedicated_mic )
1404+ continue ;
13941405 da_desc .type = (atc -> model != CTSB073X ) ? i :
13951406 ((i == SPDIFIO ) ? SPDIFI1 : i );
13961407 da_desc .output = i < LINEIM ;
@@ -1402,42 +1413,39 @@ static int atc_get_resources(struct ct_atc *atc)
14021413 i );
14031414 return err ;
14041415 }
1405- atc -> n_daio ++ ;
14061416 }
14071417
14081418 src_mgr = atc -> rsc_mgrs [SRC ];
14091419 src_dsc .multi = 1 ;
14101420 src_dsc .msr = atc -> msr ;
14111421 src_dsc .mode = ARCRW ;
1412- for (i = 0 , atc -> n_src = 0 ; i < num_srcs ; i ++ ) {
1422+ for (i = 0 ; i < NUM_ATC_SRCS ; i ++ ) {
1423+ if (((i > 3 ) && !cap .dedicated_mic ))
1424+ continue ;
14131425 err = src_mgr -> get_src (src_mgr , & src_dsc ,
14141426 (struct src * * )& atc -> srcs [i ]);
14151427 if (err )
14161428 return err ;
1417-
1418- atc -> n_src ++ ;
14191429 }
14201430
14211431 srcimp_mgr = atc -> rsc_mgrs [SRCIMP ];
14221432 srcimp_dsc .msr = 8 ;
1423- for (i = 0 , atc -> n_srcimp = 0 ; i < num_srcs ; i ++ ) {
1433+ for (i = 0 ; i < NUM_ATC_SRCS ; i ++ ) {
1434+ if (((i > 3 ) && !cap .dedicated_mic ))
1435+ continue ;
14241436 err = srcimp_mgr -> get_srcimp (srcimp_mgr , & srcimp_dsc ,
14251437 (struct srcimp * * )& atc -> srcimps [i ]);
14261438 if (err )
14271439 return err ;
1428-
1429- atc -> n_srcimp ++ ;
14301440 }
14311441
14321442 sum_mgr = atc -> rsc_mgrs [SUM ];
14331443 sum_dsc .msr = atc -> msr ;
1434- for (i = 0 , atc -> n_pcm = 0 ; i < ( 2 * 4 ) ; i ++ ) {
1444+ for (i = 0 ; i < NUM_ATC_PCM ; i ++ ) {
14351445 err = sum_mgr -> get_sum (sum_mgr , & sum_dsc ,
14361446 (struct sum * * )& atc -> pcm [i ]);
14371447 if (err )
14381448 return err ;
1439-
1440- atc -> n_pcm ++ ;
14411449 }
14421450
14431451 return 0 ;
@@ -1490,9 +1498,11 @@ static void atc_connect_resources(struct ct_atc *atc)
14901498 struct sum * sum ;
14911499 struct ct_mixer * mixer ;
14921500 struct rsc * rscs [2 ] = {NULL };
1501+ struct capabilities cap ;
14931502 int i , j ;
14941503
14951504 mixer = atc -> mixer ;
1505+ cap = atc -> capabilities (atc );
14961506
14971507 for (i = MIX_WAVE_FRONT , j = LINEO1 ; i <= MIX_SPDIF_OUT ; i ++ , j ++ ) {
14981508 mixer -> get_output_ports (mixer , i , & rscs [0 ], & rscs [1 ]);
@@ -1510,7 +1520,7 @@ static void atc_connect_resources(struct ct_atc *atc)
15101520 src = atc -> srcs [3 ];
15111521 mixer -> set_input_right (mixer , MIX_LINE_IN , & src -> rsc );
15121522
1513- if (atc -> model == CTSB1270 ) {
1523+ if (cap . dedicated_mic ) {
15141524 /* Titanium HD has a dedicated ADC for the Mic. */
15151525 dai = container_of (atc -> daios [MIC ], struct dai , daio );
15161526 atc_connect_dai (atc -> rsc_mgrs [SRC ], dai ,
0 commit comments