From nobody Tue Dec 2 01:26:43 2025 Received: from sender3-op-o12.zoho.com (sender3-op-o12.zoho.com [136.143.184.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE526346E54; Fri, 21 Nov 2025 15:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.184.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763738570; cv=pass; b=d/KI+tWhckXgXZ3BYEMk+myyBY7K6oZ4tpwoqdvUvuc6910qqwC6eaLeVLPBXS8nVsI/+yPr4PhrQy0PMYMNfWwnzmP5JYfbuN5xi8bMK3vMQId4WnDFiW1+WDIAgJPGiOfupFK6zYg0q1xB/KkL8l5Rk5h/wNMfn68FY+Dy8e4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763738570; c=relaxed/simple; bh=B1Uo4I+QMS2g33FRhhK409zvkqFzSWhgJjuH6mF2MVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VYWnt3Lcr9m80PiXq3Bi4G3oHzOzXuVh7GGmU7E7OOCg0NEB05RZS9y4ISR27rs9uslfICoarLvo+XDO1iwL1PDjpX0fK/ywbVsGn/Vc61AXocBiW1yBbiPIoXJGqQJr9NdBQQ/YUF84xfwzaKgfESgEi6Nrl9H+iSDM+9A6ieA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=harin.net; spf=pass smtp.mailfrom=harin.net; dkim=pass (2048-bit key) header.d=harin.net header.i=me@harin.net header.b=IiJ3+L3P; arc=pass smtp.client-ip=136.143.184.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=harin.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=harin.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=harin.net header.i=me@harin.net header.b="IiJ3+L3P" ARC-Seal: i=1; a=rsa-sha256; t=1763738559; cv=none; d=zohomail.com; s=zohoarc; b=lswe+6TudVghEhUsEadkhD7Qi86O+MktOKU51jt1l9tWAxs/+2wGMdc8uc7VSdxXlrsUqQbW0rc5sgzTwGkBCEgoyUPh91kOexHUxoGUg0QcT/p0fvQ4YktJhkHw4FrdBZlubr7YuJSgEUCh8O4Np//iyTJW6W14vsesIu/zvZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763738559; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=RtX3EPlwaF//L//oMs05r3TbF5sHKvoqV1lkf6z5Rm4=; b=gWEiQaXsi3XefRGYXR48kHoVLkyB5k3HpMi4Xv9+HJXvFbj2zkOPg7T2sJmdblEst75TZUXuTYlbJu+I+QcYrM2k1qd0eCiGkms77dZypW2k2E2EqjG1iJeZ9ApIMqvPuBmAKil5NnMTifNfLwwJ6sd7KEAXcq7IISXRW0vGFQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=harin.net; spf=pass smtp.mailfrom=me@harin.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1763738559; s=zmail; d=harin.net; i=me@harin.net; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=RtX3EPlwaF//L//oMs05r3TbF5sHKvoqV1lkf6z5Rm4=; b=IiJ3+L3PCJ4Fm5WNIw3KYnFTGrCodvi6hypEEwNr/DKPdZMUKN1qNQpb3yXPcmXd wwV4YVeITZsgoHV3RNk36waHpOHbvT2POJkB0jPP6fVclZBqWblLr61tci1hXVAl8wJ DavHJgIRxfSczzLfWJiw5jmlOr9wkZaw6dWiDFRuV65vTTTHrjWY+Y833uVG0Om5DC0 U1cwSiGU621gVk2hRq6/HXF3HBqEnXAErgQnzaWAd7w9pj5JPGJzxoZztccIIQdVZFe T0GiU7khXQ40Mr4NdqPEQIjIC38PRU9hWHbic7tip2yTRiTRp5lou5GUzhgzRaHxiM8 vRE5utCUfQ== Received: by mx.zohomail.com with SMTPS id 1763738557133149.28467807412017; Fri, 21 Nov 2025 07:22:37 -0800 (PST) From: Harin Lee To: Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Harin Lee Subject: [PATCH v2 4/6] ALSA: ctxfi: Refactor resource alloc for sparse mappings Date: Sat, 22 Nov 2025 00:22:18 +0900 Message-ID: <20251121152221.1152523-5-me@harin.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251121152221.1152523-1-me@harin.net> References: <20251121152221.1152523-1-me@harin.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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 --- sound/pci/ctxfi/ctatc.c | 60 ++++++++++++++++++++++++----------------- sound/pci/ctxfi/ctatc.h | 4 --- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c index 4719310d0daf..80888fffebd1 100644 --- a/sound/pci/ctxfi/ctatc.c +++ b/sound/pci/ctxfi/ctatc.c @@ -25,6 +25,9 @@ #include #include =20 +#define NUM_ATC_SRCS 6 +#define NUM_ATC_PCM (2 * 4) + #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */ #define MAX_MULTI_CHN 8 =20 @@ -1161,8 +1164,10 @@ static int atc_release_resources(struct ct_atc *atc) =20 if (atc->daios) { daio_mgr =3D (struct daio_mgr *)atc->rsc_mgrs[DAIO]; - for (i =3D 0; i < atc->n_daio; i++) { + for (i =3D 0; i < NUM_DAIOTYP; i++) { daio =3D atc->daios[i]; + if (!daio) + continue; if (daio->output) { dao =3D container_of(daio, struct dao, daio); dao->ops->clear_left_input(dao); @@ -1176,8 +1181,9 @@ static int atc_release_resources(struct ct_atc *atc) =20 if (atc->pcm) { sum_mgr =3D atc->rsc_mgrs[SUM]; - for (i =3D 0; i < atc->n_pcm; i++) - sum_mgr->put_sum(sum_mgr, atc->pcm[i]); + for (i =3D 0; i < NUM_ATC_PCM; i++) + if (atc->pcm[i]) + sum_mgr->put_sum(sum_mgr, atc->pcm[i]); =20 kfree(atc->pcm); atc->pcm =3D NULL; @@ -1185,8 +1191,9 @@ static int atc_release_resources(struct ct_atc *atc) =20 if (atc->srcs) { src_mgr =3D atc->rsc_mgrs[SRC]; - for (i =3D 0; i < atc->n_src; i++) - src_mgr->put_src(src_mgr, atc->srcs[i]); + for (i =3D 0; i < NUM_ATC_SRCS; i++) + if (atc->srcs[i]) + src_mgr->put_src(src_mgr, atc->srcs[i]); =20 kfree(atc->srcs); atc->srcs =3D NULL; @@ -1194,7 +1201,9 @@ static int atc_release_resources(struct ct_atc *atc) =20 if (atc->srcimps) { srcimp_mgr =3D atc->rsc_mgrs[SRCIMP]; - for (i =3D 0; i < atc->n_srcimp; i++) { + for (i =3D 0; i < NUM_ATC_SRCS; i++) { + if (!atc->srcimps[i]) + continue; srcimp =3D atc->srcimps[i]; srcimp->ops->unmap(srcimp); srcimp_mgr->put_srcimp(srcimp_mgr, atc->srcimps[i]); @@ -1367,30 +1376,32 @@ static int atc_get_resources(struct ct_atc *atc) struct srcimp_mgr *srcimp_mgr; struct sum_desc sum_dsc =3D {0}; struct sum_mgr *sum_mgr; - int err, i, num_srcs, num_daios; + struct capabilities cap; + int err, i; =20 - num_daios =3D ((atc->model =3D=3D CTSB1270) ? 8 : 7); - num_srcs =3D ((atc->model =3D=3D CTSB1270) ? 6 : 4); + cap =3D atc->capabilities(atc); =20 - atc->daios =3D kcalloc(num_daios, sizeof(void *), GFP_KERNEL); + atc->daios =3D kcalloc(NUM_DAIOTYP, sizeof(void *), GFP_KERNEL); if (!atc->daios) return -ENOMEM; =20 - atc->srcs =3D kcalloc(num_srcs, sizeof(void *), GFP_KERNEL); + atc->srcs =3D kcalloc(NUM_ATC_SRCS, sizeof(void *), GFP_KERNEL); if (!atc->srcs) return -ENOMEM; =20 - atc->srcimps =3D kcalloc(num_srcs, sizeof(void *), GFP_KERNEL); + atc->srcimps =3D kcalloc(NUM_ATC_SRCS, sizeof(void *), GFP_KERNEL); if (!atc->srcimps) return -ENOMEM; =20 - atc->pcm =3D kcalloc(2 * 4, sizeof(void *), GFP_KERNEL); + atc->pcm =3D kcalloc(NUM_ATC_PCM, sizeof(void *), GFP_KERNEL); if (!atc->pcm) return -ENOMEM; =20 daio_mgr =3D (struct daio_mgr *)atc->rsc_mgrs[DAIO]; da_desc.msr =3D atc->msr; - for (i =3D 0, atc->n_daio =3D 0; i < num_daios; i++) { + for (i =3D 0; i < NUM_DAIOTYP; i++) { + if ((i =3D=3D MIC) && !cap.dedicated_mic) + continue; da_desc.type =3D (atc->model !=3D CTSB073X) ? i : ((i =3D=3D SPDIFIO) ? SPDIFI1 : i); da_desc.output =3D (i < LINEIM); @@ -1402,42 +1413,39 @@ static int atc_get_resources(struct ct_atc *atc) i); return err; } - atc->n_daio++; } =20 src_mgr =3D atc->rsc_mgrs[SRC]; src_dsc.multi =3D 1; src_dsc.msr =3D atc->msr; src_dsc.mode =3D ARCRW; - for (i =3D 0, atc->n_src =3D 0; i < num_srcs; i++) { + for (i =3D 0; i < NUM_ATC_SRCS; i++) { + if (((i > 3) && !cap.dedicated_mic)) + continue; err =3D src_mgr->get_src(src_mgr, &src_dsc, (struct src **)&atc->srcs[i]); if (err) return err; - - atc->n_src++; } =20 srcimp_mgr =3D atc->rsc_mgrs[SRCIMP]; srcimp_dsc.msr =3D 8; - for (i =3D 0, atc->n_srcimp =3D 0; i < num_srcs; i++) { + for (i =3D 0; i < NUM_ATC_SRCS; i++) { + if (((i > 3) && !cap.dedicated_mic)) + continue; err =3D srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, (struct srcimp **)&atc->srcimps[i]); if (err) return err; - - atc->n_srcimp++; } =20 sum_mgr =3D atc->rsc_mgrs[SUM]; sum_dsc.msr =3D atc->msr; - for (i =3D 0, atc->n_pcm =3D 0; i < (2*4); i++) { + for (i =3D 0; i < NUM_ATC_PCM; i++) { err =3D sum_mgr->get_sum(sum_mgr, &sum_dsc, (struct sum **)&atc->pcm[i]); if (err) return err; - - atc->n_pcm++; } =20 return 0; @@ -1490,9 +1498,11 @@ static void atc_connect_resources(struct ct_atc *atc) struct sum *sum; struct ct_mixer *mixer; struct rsc *rscs[2] =3D {NULL}; + struct capabilities cap; int i, j; =20 mixer =3D atc->mixer; + cap =3D atc->capabilities(atc); =20 for (i =3D MIX_WAVE_FRONT, j =3D LINEO1; i <=3D MIX_SPDIF_OUT; i++, j++) { mixer->get_output_ports(mixer, i, &rscs[0], &rscs[1]); @@ -1510,7 +1520,7 @@ static void atc_connect_resources(struct ct_atc *atc) src =3D atc->srcs[3]; mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); =20 - if (atc->model =3D=3D CTSB1270) { + if (cap.dedicated_mic) { /* Titanium HD has a dedicated ADC for the Mic. */ dai =3D container_of(atc->daios[MIC], struct dai, daio); atc_connect_dai(atc->rsc_mgrs[SRC], dai, diff --git a/sound/pci/ctxfi/ctatc.h b/sound/pci/ctxfi/ctatc.h index 0bc7b71d910b..671edc46bd50 100644 --- a/sound/pci/ctxfi/ctatc.h +++ b/sound/pci/ctxfi/ctatc.h @@ -132,10 +132,6 @@ struct ct_atc { void **pcm; /* SUMs for collecting all pcm stream */ void **srcs; /* Sample Rate Converters for input signal */ void **srcimps; /* input mappers for SRCs */ - unsigned char n_daio; - unsigned char n_src; - unsigned char n_srcimp; - unsigned char n_pcm; =20 struct ct_timer *timer; =20 --=20 2.52.0