Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: ctxfi: Refactor resource alloc for sparse mappings

Refactor atc_get_resources(), atc_connect_resources(), and
atc_release_resources() to allocate resources based on maximum type
definitions.

This allows specific resources to be conditionally skipped based on
capabilities. This is necessary for hardware variants where resource
allocations do not follow a sequential order.

Signed-off-by: Harin Lee <me@harin.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20251124180501.2760421-5-me@harin.net

authored by

Harin Lee and committed by
Takashi Iwai
a2dbaeb5 9bb003a1

+35 -29
+35 -25
sound/pci/ctxfi/ctatc.c
··· 25 25 #include <sound/control.h> 26 26 #include <sound/asoundef.h> 27 27 28 + #define NUM_ATC_SRCS 6 29 + #define NUM_ATC_PCM (2 * 4) 30 + 28 31 #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */ 29 32 #define MAX_MULTI_CHN 8 30 33 ··· 1164 1161 1165 1162 if (atc->daios) { 1166 1163 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; 1167 - for (i = 0; i < atc->n_daio; i++) { 1164 + for (i = 0; i < NUM_DAIOTYP; i++) { 1168 1165 daio = atc->daios[i]; 1166 + if (!daio) 1167 + continue; 1169 1168 if (daio->output) { 1170 1169 dao = container_of(daio, struct dao, daio); 1171 1170 dao->ops->clear_left_input(dao); ··· 1181 1176 1182 1177 if (atc->pcm) { 1183 1178 sum_mgr = atc->rsc_mgrs[SUM]; 1184 - for (i = 0; i < atc->n_pcm; i++) 1185 - sum_mgr->put_sum(sum_mgr, atc->pcm[i]); 1179 + for (i = 0; i < NUM_ATC_PCM; i++) 1180 + if (atc->pcm[i]) 1181 + sum_mgr->put_sum(sum_mgr, atc->pcm[i]); 1186 1182 1187 1183 kfree(atc->pcm); 1188 1184 atc->pcm = NULL; ··· 1191 1185 1192 1186 if (atc->srcs) { 1193 1187 src_mgr = atc->rsc_mgrs[SRC]; 1194 - for (i = 0; i < atc->n_src; i++) 1195 - src_mgr->put_src(src_mgr, atc->srcs[i]); 1188 + for (i = 0; i < NUM_ATC_SRCS; i++) 1189 + if (atc->srcs[i]) 1190 + src_mgr->put_src(src_mgr, atc->srcs[i]); 1196 1191 1197 1192 kfree(atc->srcs); 1198 1193 atc->srcs = NULL; ··· 1201 1194 1202 1195 if (atc->srcimps) { 1203 1196 srcimp_mgr = atc->rsc_mgrs[SRCIMP]; 1204 - for (i = 0; i < atc->n_srcimp; i++) { 1197 + for (i = 0; i < NUM_ATC_SRCS; i++) { 1198 + if (!atc->srcimps[i]) 1199 + continue; 1205 1200 srcimp = atc->srcimps[i]; 1206 1201 srcimp->ops->unmap(srcimp); 1207 1202 srcimp_mgr->put_srcimp(srcimp_mgr, atc->srcimps[i]); ··· 1376 1367 struct srcimp_mgr *srcimp_mgr; 1377 1368 struct sum_desc sum_dsc = {0}; 1378 1369 struct sum_mgr *sum_mgr; 1379 - int err, i, num_srcs, num_daios; 1370 + struct capabilities cap; 1371 + int err, i; 1380 1372 1381 - num_daios = ((atc->model == CTSB1270) ? 8 : 7); 1382 - num_srcs = ((atc->model == CTSB1270) ? 6 : 4); 1373 + cap = atc->capabilities(atc); 1383 1374 1384 - atc->daios = kcalloc(num_daios, sizeof(void *), GFP_KERNEL); 1375 + atc->daios = kcalloc(NUM_DAIOTYP, sizeof(void *), GFP_KERNEL); 1385 1376 if (!atc->daios) 1386 1377 return -ENOMEM; 1387 1378 1388 - atc->srcs = kcalloc(num_srcs, sizeof(void *), GFP_KERNEL); 1379 + atc->srcs = kcalloc(NUM_ATC_SRCS, sizeof(void *), GFP_KERNEL); 1389 1380 if (!atc->srcs) 1390 1381 return -ENOMEM; 1391 1382 1392 - atc->srcimps = kcalloc(num_srcs, sizeof(void *), GFP_KERNEL); 1383 + atc->srcimps = kcalloc(NUM_ATC_SRCS, sizeof(void *), GFP_KERNEL); 1393 1384 if (!atc->srcimps) 1394 1385 return -ENOMEM; 1395 1386 1396 - atc->pcm = kcalloc(2 * 4, sizeof(void *), GFP_KERNEL); 1387 + atc->pcm = kcalloc(NUM_ATC_PCM, sizeof(void *), GFP_KERNEL); 1397 1388 if (!atc->pcm) 1398 1389 return -ENOMEM; 1399 1390 1400 1391 daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; 1401 1392 da_desc.msr = atc->msr; 1402 - for (i = 0, atc->n_daio = 0; i < num_daios; i++) { 1393 + for (i = 0; i < NUM_DAIOTYP; i++) { 1394 + if ((i == MIC) && !cap.dedicated_mic) 1395 + continue; 1403 1396 da_desc.type = (atc->model != CTSB073X) ? i : 1404 1397 ((i == SPDIFIO) ? SPDIFI1 : i); 1405 1398 da_desc.output = i < LINEIM; ··· 1413 1402 i); 1414 1403 return err; 1415 1404 } 1416 - atc->n_daio++; 1417 1405 } 1418 1406 1419 1407 src_mgr = atc->rsc_mgrs[SRC]; 1420 1408 src_dsc.multi = 1; 1421 1409 src_dsc.msr = atc->msr; 1422 1410 src_dsc.mode = ARCRW; 1423 - for (i = 0, atc->n_src = 0; i < num_srcs; i++) { 1411 + for (i = 0; i < NUM_ATC_SRCS; i++) { 1412 + if (((i > 3) && !cap.dedicated_mic)) 1413 + continue; 1424 1414 err = src_mgr->get_src(src_mgr, &src_dsc, 1425 1415 (struct src **)&atc->srcs[i]); 1426 1416 if (err) 1427 1417 return err; 1428 - 1429 - atc->n_src++; 1430 1418 } 1431 1419 1432 1420 srcimp_mgr = atc->rsc_mgrs[SRCIMP]; 1433 1421 srcimp_dsc.msr = 8; 1434 - for (i = 0, atc->n_srcimp = 0; i < num_srcs; i++) { 1422 + for (i = 0; i < NUM_ATC_SRCS; i++) { 1423 + if (((i > 3) && !cap.dedicated_mic)) 1424 + continue; 1435 1425 err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, 1436 1426 (struct srcimp **)&atc->srcimps[i]); 1437 1427 if (err) 1438 1428 return err; 1439 - 1440 - atc->n_srcimp++; 1441 1429 } 1442 1430 1443 1431 sum_mgr = atc->rsc_mgrs[SUM]; 1444 1432 sum_dsc.msr = atc->msr; 1445 - for (i = 0, atc->n_pcm = 0; i < (2*4); i++) { 1433 + for (i = 0; i < NUM_ATC_PCM; i++) { 1446 1434 err = sum_mgr->get_sum(sum_mgr, &sum_dsc, 1447 1435 (struct sum **)&atc->pcm[i]); 1448 1436 if (err) 1449 1437 return err; 1450 - 1451 - atc->n_pcm++; 1452 1438 } 1453 1439 1454 1440 return 0; ··· 1498 1490 struct sum *sum; 1499 1491 struct ct_mixer *mixer; 1500 1492 struct rsc *rscs[2] = {NULL}; 1493 + struct capabilities cap; 1501 1494 int i, j; 1502 1495 1503 1496 mixer = atc->mixer; 1497 + cap = atc->capabilities(atc); 1504 1498 1505 1499 for (i = MIX_WAVE_FRONT, j = LINEO1; i <= MIX_SPDIF_OUT; i++, j++) { 1506 1500 mixer->get_output_ports(mixer, i, &rscs[0], &rscs[1]); ··· 1520 1510 src = atc->srcs[3]; 1521 1511 mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); 1522 1512 1523 - if (atc->model == CTSB1270) { 1513 + if (cap.dedicated_mic) { 1524 1514 /* Titanium HD has a dedicated ADC for the Mic. */ 1525 1515 dai = container_of(atc->daios[MIC], struct dai, daio); 1526 1516 atc_connect_dai(atc->rsc_mgrs[SRC], dai,
-4
sound/pci/ctxfi/ctatc.h
··· 132 132 void **pcm; /* SUMs for collecting all pcm stream */ 133 133 void **srcs; /* Sample Rate Converters for input signal */ 134 134 void **srcimps; /* input mappers for SRCs */ 135 - unsigned char n_daio; 136 - unsigned char n_src; 137 - unsigned char n_srcimp; 138 - unsigned char n_pcm; 139 135 140 136 struct ct_timer *timer; 141 137