From patchwork Fri Sep 30 09:20:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12995077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA7EAC433F5 for ; Fri, 30 Sep 2022 09:21:10 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 4DD2B1676; Fri, 30 Sep 2022 11:20:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4DD2B1676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1664529668; bh=poNkf/HDkDJXANlPovJj8BjfwtI3HiozGLYjF3dNGAU=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=ce4JdC17c85FzMUW5de9ELfWQrS1c0nut0qLd6yjlES1acWioR3lA4JMGee9Qnv/4 yiC0sGsqE0qfPknaxVV2GKt1mMIxZmm3TTrdxQETd0UMXQjnYXUiPEHZZZH8IMat5N PiRGz4ohwnIrr6bSWz1vYZ15U/iLddv37r5jvjC4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id CEED8F80155; Fri, 30 Sep 2022 11:20:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0C1EDF801D5; Fri, 30 Sep 2022 11:20:17 +0200 (CEST) Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D9EE9F800AA for ; Fri, 30 Sep 2022 11:20:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D9EE9F800AA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AZQiM/rF" Received: by mail-lf1-x130.google.com with SMTP id a3so5956436lfk.9 for ; Fri, 30 Sep 2022 02:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=JUsD5OyMxzTqjJC2MueYgQBSzr/7dS7Jwt69lfzIL4M=; b=AZQiM/rFdvvMZHz8CLmCW8QSQW2kURL/RUSJ1xj6rxN/LqgaEMnHvsYxPLuUGOz49A rwPZJPAsf0vOTeHiS/MKyEiPeP4t2r0S+o0jjEcGO+fBnka+KjV4yjuu6irOIaAr3L/Q f8pMf4YDUVzPq9ti8S/T02uLXC6sH0R/M9iAJpVpKGl72d4Cta0HtouQx6YAwZdC7pFo oz4ZT9GZPP1Tljc59oXOjcX14ozmXnX0LPjh5s385LR+siRQWRlc0wY7NXNy2bZ1/bHv jhQ3mz0dpl6GLGIG6lvZt+HBaX0tXQEpx3Z29A+jEEcgKaoB6C6p2q/jJD/3a9Xk2h45 oeeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=JUsD5OyMxzTqjJC2MueYgQBSzr/7dS7Jwt69lfzIL4M=; b=XEW28Et0/t0vlqbdRqts7Z8aUMcRuZsSr75v76eu5n2+kLkXp0WsfC0OWSrHWASoK6 PaSV+6VQ8TybQnWtCGrhbIft6ZZSEotqxYTzNMvUCIpGpFmpQVQekEL7Cxmpx9qQZQTR 1FNhkF0miNdM6g2zKoLAiSY4hiDAcbeMUPf5R5vwf3JpRw+99Tt93sEy/nakf8H3XZou ORifOoqlYq4KFjSB3cy1nsQgiBZEMrrEZSAYHBlw6k0EcoJcqpsXdVGCN7AU2o+SRnoq cFT1O9q3CuQpIaoUWbXTkPrEL3uxLDLAkePdYK/tNaWJ3yck9r2oDHf/UN6f7E/B/SuQ 8/pQ== X-Gm-Message-State: ACrzQf0WbKm4mxbvo6b696NDOJKq08jMQnHp+9j9MX38fbltBrZGCPZt EolEtgXRMwYxKizdlGApnV7lQg== X-Google-Smtp-Source: AMsMyM7MmADAWQBvaYBjBOds2otRjU2INo8y9+KsdLttZq9CCty5vGMNFq1nb8eMuG8ekVRHWuDXzQ== X-Received: by 2002:a05:6512:3185:b0:49c:3310:6910 with SMTP id i5-20020a056512318500b0049c33106910mr3408122lfe.352.1664529608805; Fri, 30 Sep 2022 02:20:08 -0700 (PDT) Received: from krzk-bin.. (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id i6-20020a2ea226000000b0026aba858fbfsm103461ljm.137.2022.09.30.02.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 02:20:08 -0700 (PDT) From: Krzysztof Kozlowski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] slimbus: stream: handle unsupported bitrates for presence rate Date: Fri, 30 Sep 2022 11:20:05 +0200 Message-Id: <20220930092006.85982-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Cc: Krzysztof Kozlowski X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Handle errors of getting presence rate for unsupported stream bitrate, instead of sending -EINVAL in change content message. Signed-off-by: Krzysztof Kozlowski --- drivers/slimbus/stream.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/slimbus/stream.c b/drivers/slimbus/stream.c index f8eade1e0132..28fbecb3907d 100644 --- a/drivers/slimbus/stream.c +++ b/drivers/slimbus/stream.c @@ -204,7 +204,7 @@ int slim_stream_prepare(struct slim_stream_runtime *rt, { struct slim_controller *ctrl = rt->dev->ctrl; struct slim_port *port; - int num_ports, i, port_id; + int num_ports, i, port_id, prrate; pr_err("%s:%d AAAA\n", __func__, __LINE__); if (rt->ports) { @@ -222,6 +222,13 @@ int slim_stream_prepare(struct slim_stream_runtime *rt, rt->bps = cfg->bps; rt->direction = cfg->direction; + prrate = slim_get_prate_code(cfg->rate); + if (prrate < 0) { + dev_err(&rt->dev->dev, "Cannot get presence rate for rate %d Hz\n", + cfg->rate); + return -EINVAL; + } + if (cfg->rate % ctrl->a_framer->superfreq) { /* * data rate not exactly multiple of super frame, @@ -242,7 +249,7 @@ int slim_stream_prepare(struct slim_stream_runtime *rt, port = &rt->ports[i]; port->state = SLIM_PORT_DISCONNECTED; port->id = port_id; - port->ch.prrate = slim_get_prate_code(cfg->rate); + port->ch.prrate = prrate; port->ch.id = cfg->chs[i]; port->ch.data_fmt = SLIM_CH_DATA_FMT_NOT_DEFINED; port->ch.aux_fmt = SLIM_CH_AUX_FMT_NOT_APPLICABLE; From patchwork Fri Sep 30 09:20:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12995078 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB627C433F5 for ; Fri, 30 Sep 2022 09:21:36 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 0E5A985D; Fri, 30 Sep 2022 11:20:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0E5A985D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1664529695; bh=BmfAjmFoGPgjjbmPaKUTAITyWLuwEC50Z5dJV54F5Ys=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iMt27Rl20xXr6BeVneMAXXXNzpUpUhWxkdR9KifkpThNubelT8IEtIHf4Tn2IB5Bu Qs1dA3G3wcaN7hI6UCRUjRjqmgeabWDMYoeYrHrzJxkYlumc3GKdyYUeNlosUrgc7Y a27mB2d7gieEaps7qO4oC7o7UD1Ul9Iy4QCtEnuo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 151C8F80539; Fri, 30 Sep 2022 11:20:22 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 17F0AF801D5; Fri, 30 Sep 2022 11:20:17 +0200 (CEST) Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 0AD58F80095 for ; Fri, 30 Sep 2022 11:20:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0AD58F80095 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lDdeIh0c" Received: by mail-lf1-x133.google.com with SMTP id 10so5976467lfy.5 for ; Fri, 30 Sep 2022 02:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=7Sv5seCRTWybOOOOludWC1A9KTXxVnMAlKH82j49yng=; b=lDdeIh0cWxEkskELtP03Xa8NbQmjyC39cByRE9LguZ7etBFGJO1mMkfoIxIHzsDJQc 1TW2F3Z9ubFF1rlXTndLb2Xrvz1Fvm0ZVHnCjj+la8YDXH0eDnXmLQiAtZZCXIswyVW0 +VD3R6ol67HKiwfx1kWAt4HUdjV7Q6lLiAJQznSupBUHmrOsfSc/WxEn7Qb1PvtHlvBn PRHnSp3IXcDmflioPwMXVQIX+2Ni801Op1Pe7HI6l1xzhQyz3uzDZGzQW5DIylXPRuXA qHUhEXxMEPgdxdmChRdP7LpPXTQ5aNWdk9U9VOEdFQ4INt4ueS5XgRCydwWYxPpvIhga 5dLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7Sv5seCRTWybOOOOludWC1A9KTXxVnMAlKH82j49yng=; b=2yg6PAPMrtl86bKbigzwNynAvxCtb3eALz2zeCtUvrZLWQlJHF9yLPR34yFJgmlA5k iSZJE+MrarF7DogODexP2qHZNRJBmUvooPyZEBwoEz6L9IvPN7RdHkq3I6jSJWbzR3nz DpRjCBTlfga2O80LnWzStGLm/Y2syBK4oRfPbrec3UndSH+wFl4oYQR5PH1viUxYpT8t 9G73Hy9s7p2HFaO+SHJK5TeCUom3SjCR0xqcfaMFRE8dizm6xxWkzsKqTGJPXzvflJNk GMUe5Com6Zi89LuC6LF1r2+93pSE3fdglZ4Wanzny37BKKdFAFbxrcofZyKkp3k36+0G rD1Q== X-Gm-Message-State: ACrzQf0eirME9LOd/8fw61TJKjLqLTFOBbQDhOll6GBsj8OlLgcGlBrL liPtXFIdSeKTc/1pRLChzwzHaw== X-Google-Smtp-Source: AMsMyM4auLp3LAPf6h4uJworyb16xNE8RvMv9WwpYX6v09WUHaBQx0ZOYHzJXC16Alv7j/0sl81oqw== X-Received: by 2002:a05:6512:12c5:b0:49e:5431:45d0 with SMTP id p5-20020a05651212c500b0049e543145d0mr3223201lfg.111.1664529609923; Fri, 30 Sep 2022 02:20:09 -0700 (PDT) Received: from krzk-bin.. (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id i6-20020a2ea226000000b0026aba858fbfsm103461ljm.137.2022.09.30.02.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 02:20:09 -0700 (PDT) From: Krzysztof Kozlowski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Srinivas Kandagatla , linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] slimbus: qcom-ngd-ctrl: add support for 44.1 Khz frequency Date: Fri, 30 Sep 2022 11:20:06 +0200 Message-Id: <20220930092006.85982-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930092006.85982-1-krzysztof.kozlowski@linaro.org> References: <20220930092006.85982-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Cc: Krzysztof Kozlowski , Prudhvi Yarlagadda X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Add support for 44.1Khz frequency by dynamically calculating the slimbus parameters instead of statically defining them. Co-developed-by: Prudhvi Yarlagadda Signed-off-by: Prudhvi Yarlagadda Signed-off-by: Krzysztof Kozlowski --- drivers/slimbus/qcom-ngd-ctrl.c | 64 ++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c index ac84fdc2822f..051ac5cba207 100644 --- a/drivers/slimbus/qcom-ngd-ctrl.c +++ b/drivers/slimbus/qcom-ngd-ctrl.c @@ -944,6 +944,54 @@ static int qcom_slim_ngd_xfer_msg_sync(struct slim_controller *ctrl, return ret; } +static int qcom_slim_calc_coef(struct slim_stream_runtime *rt, int *exp) +{ + struct slim_controller *ctrl = rt->dev->ctrl; + int coef; + + if (rt->ratem * ctrl->a_framer->superfreq < rt->rate) + rt->ratem++; + + coef = rt->ratem; + *exp = 0; + + /* + * CRM = Cx(2^E) is the formula we are using. + * Here C is the coffecient and E is the exponent. + * CRM is the Channel Rate Multiplier. + * Coefficeint should be either 1 or 3 and exponenet + * should be an integer between 0 to 9, inclusive. + */ + while (1) { + while ((coef & 0x1) != 0x1) { + coef >>= 1; + *exp = *exp + 1; + } + + if (coef <= 3) + break; + + coef++; + } + + /* + * we rely on the coef value (1 or 3) to set a bit + * in the slimbus message packet. This bit is + * BIT(5) which is the segment rate coefficient. + */ + if (coef == 1) { + if (*exp > 9) + return -EIO; + coef = 0; + } else { + if (*exp > 8) + return -EIO; + coef = 1; + } + + return coef; +} + static int qcom_slim_ngd_enable_stream(struct slim_stream_runtime *rt) { struct slim_device *sdev = rt->dev; @@ -967,16 +1015,22 @@ static int qcom_slim_ngd_enable_stream(struct slim_stream_runtime *rt) struct slim_port *port = &rt->ports[i]; if (txn.msg->num_bytes == 0) { - int seg_interval = SLIM_SLOTS_PER_SUPERFRAME/rt->ratem; - int exp; + int exp = 0, coef = 0; wbuf[txn.msg->num_bytes++] = sdev->laddr; wbuf[txn.msg->num_bytes] = rt->bps >> 2 | (port->ch.aux_fmt << 6); - /* Data channel segment interval not multiple of 3 */ - exp = seg_interval % 3; - if (exp) + /* calculate coef dynamically */ + coef = qcom_slim_calc_coef(rt, &exp); + if (coef < 0) { + dev_err(&sdev->dev, + "%s: error calculating coef %d\n", __func__, + coef); + return -EIO; + } + + if (coef) wbuf[txn.msg->num_bytes] |= BIT(5); txn.msg->num_bytes++;