From patchwork Fri Sep 30 10:00:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12995102 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 05021C433FE for ; Fri, 30 Sep 2022 10:01:18 +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 A1A441676; Fri, 30 Sep 2022 12:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A1A441676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1664532076; bh=cJgJtLc2/wKUEpSs6Yxh61bAGDxmfNDbQ5874tGEZOM=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=B4tmaNXAPwm0x0uUHulzrz4fiq1QOHFflxJOhbd0y3RzM1EH0QuR3BqXDJkIEfcKG UlBneaQq0a3p/sUgL1WWeyJY8LiBna0m1JSmAPzYtiGXnpsdsM3clFSdJs5neJmYWs H9y5kc/q9JfEXlRy0GZJU8GImFRrhkEvC+QYcyzQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 41901F80155; Fri, 30 Sep 2022 12:00:26 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7EDCAF801D5; Fri, 30 Sep 2022 12:00:25 +0200 (CEST) Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (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 18979F80155 for ; Fri, 30 Sep 2022 12:00:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 18979F80155 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OWK5LGKW" Received: by mail-lj1-x232.google.com with SMTP id b6so4241823ljr.10 for ; Fri, 30 Sep 2022 03:00:18 -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=eflBW1/omcz649gzqa80EdxHOHLRvARzQtLAthFPzJI=; b=OWK5LGKWP0pdp3UPFCNUfXZUKNnZoBJUrmaauwMpZ82/O4KMFbn4fiY5fm0U5Ydqld OsiAVf+z608fk9ECGQhxGFQzomsxoLyemejEjZHZ+DGWAr++8OYtnDf+pJDBIZToR878 gfptsC3sbcKHx7ZTNpJok8J2N+TQOp66L1Jg3EP2AfGAUTEosVpw43u8rqeSqUs8LVWF ZFHFjy0CJaDfUa5B61twfyKo88jykM86qFHIoWncHvxv4n0TxHNOLDsrUHWnrwPGelj/ V/fISMnD0XD5ynehEItyMZ4az5V3iZWBJJGca2njI6DzP7lvejVWnowY1lM2Wln3FJyu mxQg== 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=eflBW1/omcz649gzqa80EdxHOHLRvARzQtLAthFPzJI=; b=6Y556Pw+elpRY9XCuMCdscLy/buAL7/xohia7dvbmPqggQ04lLTCCqv4bR9Mdpzw4P T/ZZGSWQE7L74rT9d/9TZsHyZw2wIt5lUqNUvYhKZPnu1qhoZOWW/PxW5XFKhxz+L9ad J/8xwjEejVqLFOqZYZgXPlsYqOWLrwWTBUlNr1WnVmeFG5k5KlEj3eZAHe8VIgm7T5P3 3UNqMgt6mLxX6GxuZjM9BPVGXqht/POkaj/2FD/w/45HLO92SP9HCqc3fGt22dLcBQ/+ ryuOeALdoMwc2Iljf8DTTCKRyxZPVOWOLOIL5jYd+ANdD7xhy/oDzT1jRmTf8pfhXYfp kKzA== X-Gm-Message-State: ACrzQf3StjuIor3aQo37uL1a0JkcWHm03HL9xTXjDpI7GaLAN8D3b3yu v+nFJPKusChEU2skRFtXIG113g== X-Google-Smtp-Source: AMsMyM6B4uYou33xi63CeYgaZwCwUV++xi/7sDtaqK1haWq9kFsQCN9YPhgm/HPc4sDoaDjGduqapQ== X-Received: by 2002:a2e:a54b:0:b0:26c:72ed:b758 with SMTP id e11-20020a2ea54b000000b0026c72edb758mr2692885ljn.245.1664532017099; Fri, 30 Sep 2022 03:00:17 -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 q65-20020a2e2a44000000b0026c3e350682sm113521ljq.14.2022.09.30.03.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 03:00:16 -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 v2 1/2] slimbus: stream: handle unsupported bitrates for presence rate Date: Fri, 30 Sep 2022 12:00:14 +0200 Message-Id: <20220930100015.259106-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 Reviewed-by: Konrad Dybcio --- Changes since v1: 1. Rebase (drop development pieces in the context). 2. Return prrate (which has errno) instead of -EINVAL. 3. Add Rb tag. --- 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 d5ce974e880b..f631d5ed9809 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; if (rt->ports) { dev_err(&rt->dev->dev, "Stream already Prepared\n"); @@ -221,6 +221,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 prrate; + } + if (cfg->rate % ctrl->a_framer->superfreq) { /* * data rate not exactly multiple of super frame, @@ -241,7 +248,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 10:00:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12995103 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 48C0CC433F5 for ; Fri, 30 Sep 2022 10:01:28 +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 38CF51687; Fri, 30 Sep 2022 12:00:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 38CF51687 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1664532086; bh=ibC3sk0eCldRdK+RwJnOiXO6QsAax1e7Tm0jbnJ5Oi8=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HOXRVAt4J5c3miTIvRT6O38eWIJEAqn+dDL9ivHqiPB1XxAxE4NuaxeWLn33UnsC2 9zlCHaPuC2aKzXfNE1LFQBT0KQoZ0ZLbU4rkr/FC+zA4pTS3qtj828cMXzMDnbMpRD B8jhVv/dF/ZaCbywJVUJgIGWbP4iXiSn06kJt5V0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B919EF801D5; Fri, 30 Sep 2022 12:00:35 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 49E1BF801D5; Fri, 30 Sep 2022 12:00:34 +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 C2F7BF804E5 for ; Fri, 30 Sep 2022 12:00:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C2F7BF804E5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="voc8TJMG" Received: by mail-lf1-x133.google.com with SMTP id o2so6088701lfc.10 for ; Fri, 30 Sep 2022 03:00:19 -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=9KpEUUalWoRI8TdGgOpsCg4Iu1p4euYEEJL3jAX6IA8=; b=voc8TJMGolTORHdohzjvuHAb4UaOqMJCdsBpDglcWWDasx3Bh/t4bB1zHsBgXyB/XH gvMWUPtHlADr2zsn56C3/uwUm51/k9+SybvXdpWO2dvuE8rZMFV41uj1L0MFso4CHhjZ R30v7heDZtcRI7nUwugKeNDVji1gkKjbvTy6nMAANQwgYRbWmSdRjZayLqTXkLPM6DCv CWjp/sJZMawQ5yZ+nfePEF+kuPODV9K0dwrvncOqW3ubk4ExxC+h44618XHTeZ8GMujZ el1qaFBGZnKf/m7mp1i1RXcPFh4M4qJhygCH051dou0CqHJpsAxXF9u1xIiIEqeBQiPN gX3g== 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=9KpEUUalWoRI8TdGgOpsCg4Iu1p4euYEEJL3jAX6IA8=; b=i3kJ9XMSapWDWxzysi8P/4IYHI/Lvjs6DynP8CSIZoF19G0V8O3H/S0ZUri9MA+VZZ Mv9MZMm7lIPmrgmMe5X2M1Ac4Sf5nB/dQ/liv2ZCge9LpwbBEbmpjR/4lpTWh6mN+mEZ rKDIeyXD6k9DnQ/3it/aHvs+PI0DnKlS9oHg7lzLWtZK0frL1691bIL+Z/dYjZsPaJgT ulTTVo4OmDSs3D0SWa7pmHkYOv2I7ZS6/d94KdVgquDUXnaUv/MBOimETBrh8vP5rwfh OtJmKV5AiL7bGCKO/RimBlLFtsRXiOLLmk/V8QSWkAyD7wjpAM2+N+RdrMTaBpjvdQj+ S9AA== X-Gm-Message-State: ACrzQf3G4cxEDs7v8VPLmsFlzsnVDTXBFQT3L8FnV3PfXYB+kZniu9yn /7xlQqU/C4UhW+D7PALV1TeWtw== X-Google-Smtp-Source: AMsMyM5HvS85QSAxGq4Faz53kk6h8+znPOxxIkcAMRbZnP3Zfwji5og6cRVKRepMrNrIc8z33OvEow== X-Received: by 2002:a05:6512:304d:b0:498:9d7b:43f with SMTP id b13-20020a056512304d00b004989d7b043fmr2984022lfb.48.1664532017997; Fri, 30 Sep 2022 03:00:17 -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 q65-20020a2e2a44000000b0026c3e350682sm113521ljq.14.2022.09.30.03.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 03:00:17 -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 v2 2/2] slimbus: qcom-ngd-ctrl: add support for 44.1 Khz frequency Date: Fri, 30 Sep 2022 12:00:15 +0200 Message-Id: <20220930100015.259106-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220930100015.259106-1-krzysztof.kozlowski@linaro.org> References: <20220930100015.259106-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 --- Changes since v1: 1. Rebase (drop development pieces in the context). --- 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++;