From patchwork Wed Sep 13 09:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13382715 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 48F4ECA5531 for ; Wed, 13 Sep 2023 09:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2O7Wa9CGKYKv9GKkcRaiLbKzKRvBUcOQsUkKWTFeDoA=; b=N4VLZd87PmP+nK xQS3QttZ/Mpzyigmbj8BcikcqyPeElGLrxFtiCRgsVJkqGcqr7fYP7WeIeWW1yr/5CNb6TpoaXTzZ hm8/udkA5aaJkU5gKjngmz8ZrfIpnUmSxKGJrEKwBXhLZYJb2Y9VcbOKcCNvWyliwR85ytFb4Cm2X O6q2UiHBfX6xPEsKIdFv0WlulSapY7NTeGYLpBvu8em5mhXnzPXV5ifVCdF6TPRNtuUNcLDnl5A/j U9xrFhehDemgXMyaNOJxLpaIQe3zA1BRCiYzfhQJn0Fj2sl6xMStrRvc1wTcipC2Hp5ZIoZekMGfK AprhzMgfC/Y9b7JkNg9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZP-005M13-3D; Wed, 13 Sep 2023 09:54:04 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZN-005Lzq-1x for linux-phy@lists.infradead.org; Wed, 13 Sep 2023 09:54:02 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b703a0453fso113613971fa.3 for ; Wed, 13 Sep 2023 02:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694598839; x=1695203639; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bGEWNaFOSGbgLmGphSZoYFcO8R5kpnOWxma4oPpmrkM=; b=Q1c2KMuRf1JF40a6X6eanNCSWyvjDjjOiGeM5bsM0T8ggen1mIkXKJBLxLNDCowfDJ tN522rLM7BNCdbDgNJk3s+sMBlL7TnTSTv+c5qLmryiFRqL0tLq81FDcpsD6dwoypADp +s3nrRzFzd642PcAo/O4IoPh+lpsWeDFUj6r4nVqAUUC+tSmRDdQPI7QHmO1zbWQRWyI yoL5Y4atLjkltnvozoj1m1qN0URzg/EMpSQoMo5hGeJaZM3XUYezJs26E8LXBFl6RLMY nbcNAk7p/4+YZcHIlaRY0Ec4WUtjppgAvJdsyByT6c+trVob3hToj/3UGg2QM8RIN3wX Kryw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694598839; x=1695203639; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bGEWNaFOSGbgLmGphSZoYFcO8R5kpnOWxma4oPpmrkM=; b=f6S8n/oxkejF4JwdZgPA2oWfRfbv9yRIEoO4M9c53tDJkE1KNTY5hFPIOAUOLX9/fY II5A6hBAuZyUoMUEF51v7T6osQ3JVWxGnC7AEWrwkYyXkWdndcj3YJ61eh6MHBd9Oq+H CpIO2Uh9+74qe44livcg05QHK3oKlz0vTjy8xyQz1DMywFqtAMgAdDyfamHzAx49yVwd L0wxCZ9AvEHCMjcBL3k9ds9VJXY2OoXXDxFantX2pyleB6Q58Mw2gA6arJqzXJToLbce uM54SCNS9EOEJsQAAVPH3dzdyU3sVhn9OlAj5Q6j5Sg69b82EhV+MMc0z6mWav8XcIom 49iA== X-Gm-Message-State: AOJu0YxgpXuNSiRke4GUuUsULluoocjBlUcjzWIQmlbttkMHQxNemE2d Tu6l6GpbfOwnkWuN2PdhO+Eztg== X-Google-Smtp-Source: AGHT+IGRBzDoV6q1Yg7xSUFIzw7/wQfW9voe7rkKcePRlezQHiH+2VWYtd85objRfoUB5jzbALjOiQ== X-Received: by 2002:a2e:9806:0:b0:2b9:e6a0:5c3a with SMTP id a6-20020a2e9806000000b002b9e6a05c3amr1705981ljj.48.1694598839540; Wed, 13 Sep 2023 02:53:59 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id l21-20020a170906939500b00985ed2f1584sm8092669ejx.187.2023.09.13.02.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:53:59 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 11:53:23 +0200 Subject: [PATCH v2 1/4] dt-bindings: phy: qcom,snps-eusb2-repeater: Add magic tuning overrides MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v2-1-7d8c893d93f6@linaro.org> References: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> To: Andy Gross , Bjorn Andersson , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Abel Vesa Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694598835; l=1475; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=+WkmKOaL4o5Pf6bG2lB645yeG0HwBKcy91tPmktunQA=; b=Ma2LEKDh/8hk+rsvOx7vD/eD/ZV5DGMbX+SL8VQxrsc3O3sKPGbAoG7NjjqSM31BPA4Bth27J GG9ZG6Qx8DuD2gA7zYTmHwQrUqRI6EMbl/lzO269iELzs75JLwQRn/9 X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230913_025401_640539_C3DBF72B X-CRM114-Status: UNSURE ( 8.35 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org The EUSB2 repeater requires some alterations to its init sequence, depending on board design. Add support for making the necessary changes to that sequence to make USB functional on SM8550-based Xperia 1 V. They all have lackluster description due to lack of information. Signed-off-by: Konrad Dybcio Acked-by: Rob Herring --- .../bindings/phy/qcom,snps-eusb2-repeater.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml index 029569d5fcf3..24c733c10e0e 100644 --- a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml +++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml @@ -32,6 +32,27 @@ properties: vdd3-supply: true + qcom,tune-usb2-disc-thres: + $ref: /schemas/types.yaml#/definitions/uint8 + description: High-Speed disconnect threshold + minimum: 0 + maximum: 7 + default: 0 + + qcom,tune-usb2-amplitude: + $ref: /schemas/types.yaml#/definitions/uint8 + description: High-Speed trasmit amplitude + minimum: 0 + maximum: 15 + default: 8 + + qcom,tune-usb2-preem: + $ref: /schemas/types.yaml#/definitions/uint8 + description: High-Speed TX pre-emphasis tuning + minimum: 0 + maximum: 7 + default: 5 + required: - compatible - reg From patchwork Wed Sep 13 09:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13382716 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 AF3FBCA5536 for ; Wed, 13 Sep 2023 09:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QKharc35FAk+sSNb96+mJiBf171RYI2GPijVIzEUvJQ=; b=c2HIPRGj3ilw9g sU/28HF1fzuB4qjCUw4IsM95c3ZiLbYs7wesycnNj8pSD3Avh23HrSz4EjEBXkTkQfEUGcYAU32TD 38xYCvpTWVPh0tweb9XO5t+A02loZ1BfUrkL9XqHhE4Knz0GmoVqc3nXViJ7eFZnowaV09nO+T/AV 3q1q9K6+7GVyN7HgU9vNixg89I1HkcMWjXPNeqJrBFDZtVprNh0CCvlDFqVAhRv6Y7HxcUl0bOtPP qQk0i1g6HErsQToc611/ExRT0Lrx67c87MT0cABkxsUXsWNw+Be61T+iZ03474hT2MObjQ7CS1uy/ q8crq1xsVymZhTX+pZ8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZR-005M1b-1L; Wed, 13 Sep 2023 09:54:05 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZP-005M0Q-0t for linux-phy@lists.infradead.org; Wed, 13 Sep 2023 09:54:04 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2bfb17435e4so15030581fa.0 for ; Wed, 13 Sep 2023 02:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694598841; x=1695203641; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AqhtzcGyFHDluGDjY5bQjlFxQW1yi0cE3p4JZH8FKz0=; b=gzG2mb+wYgyyfSpfVwlQAMCR65+c297TFNe3ucHT+uSCMiH+rOWGIzEhA3KZ13IVeD X+KK7Lg2fut/naqjol5IgsB/sJDmY1qCUQmt++iu3IFUTRLVMT0ZnKeDR+A8nHhBNN0k zK9RKwtxliA60c7tNvCJ/FFZ0OsIVShoAXgjTWvP4WeE/Ebp3YrG2hce4XuLBpFv2Hcq cYOgFzZ0pNnNQQMx8r5AiKquMBoglllJsvF8S0JEhwUDFL9+QTEEmCIREZx7PXxkjgvh 6PEpyH05QX7ZqaHVJWnAfWkB9VR//w7a6It4acn/7aZ1xqQTbnHEUy5chqCipgqC+ALL ir5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694598841; x=1695203641; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AqhtzcGyFHDluGDjY5bQjlFxQW1yi0cE3p4JZH8FKz0=; b=JVH/1lvwBW0N+R0vCEnl/BCTnXNRkb62IthOeA2sIQchv4LAaPKLvJYiiC4blmOpJK ababIjudy+lIv7DL5RKt7cYz2wZEqv52cg06CUgplzTE/gpjmMqLl51ddcEUIZhx+B0s k1sNXHa12hqSuHiam37Qp2FtOWPk9yjTF1dCYL5aS43l4VwwUHkut5a6Ka1hBcL0lwdz JU/rk6DeoRAMKZa07Raj49XZNAxJdQcbBOy1yaBn6+thoSBZQ3AXmF6ViiL/42DWjXeH yVRxBYDbXx1TutHrHtkZFWvBR/veUk0SKG+ejo5LDD3vfzkxDMjyoLwnGtonYirL+KAJ cuRA== X-Gm-Message-State: AOJu0Yw2luzqw+zlGvEGgrr+yb3qB82D3kB8qVlwL+ImxVIpFcRG9uc9 TxWEdGajJnZnb5p6H+bOwEkQmw== X-Google-Smtp-Source: AGHT+IHNbvyFQSnMJb6OfLYWUcESZqwdneFRKa8pRDV1Q+3U0qRNYgJV0xi45nmOtjU3fgbew0oEQw== X-Received: by 2002:a2e:9c95:0:b0:2bf:b106:6296 with SMTP id x21-20020a2e9c95000000b002bfb1066296mr1992334lji.4.1694598841134; Wed, 13 Sep 2023 02:54:01 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id l21-20020a170906939500b00985ed2f1584sm8092669ejx.187.2023.09.13.02.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:54:00 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 11:53:24 +0200 Subject: [PATCH v2 2/4] phy: qualcomm: phy-qcom-eusb2-repeater: Use regmap_fields MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v2-2-7d8c893d93f6@linaro.org> References: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> To: Andy Gross , Bjorn Andersson , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Abel Vesa Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694598835; l=6150; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=LovaKfaqbkXiJ4az1PcPQZkH3FJdcJGz/pvW4OALguE=; b=XQp+5kTi6ild6Zxmlevo6fXNSvkR8Nv36RLh64N3zxki1otft+Now1GEIXUujMQqQ5DBWTfRS WxuRAaSJgqFCoVICxB3WM94ZbpcnKYskhI1gv+Va/0L5iwrtLU+/Orp X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230913_025403_323324_71BAA73B X-CRM114-Status: GOOD ( 18.37 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org Switch to regmap_fields, so that the values written into registers are sanitized by their explicit sizes and the different registers are structured in an iterable object to make external changes to the init sequence simpler. Signed-off-by: Konrad Dybcio --- drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c | 91 +++++++++++++++++--------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c index 52c275fbb2a1..7561da01e633 100644 --- a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c @@ -28,14 +28,42 @@ #define EUSB2_TUNE_SQUELCH_U 0x54 #define EUSB2_TUNE_USB2_PREEM 0x57 -#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v) \ +#define QCOM_EUSB2_REPEATER_INIT_CFG(r, v) \ { \ - .offset = o, \ + .reg = r, \ .val = v, \ } +enum reg_fields { + F_TUNE_USB2_PREEM, + F_TUNE_SQUELCH_U, + F_TUNE_IUSB2, + F_NUM_TUNE_FIELDS, + + F_FORCE_VAL_5 = F_NUM_TUNE_FIELDS, + F_FORCE_EN_5, + + F_EN_CTL1, + + F_RPTR_STATUS, + F_NUM_FIELDS, +}; + +static struct reg_field eusb2_repeater_tune_reg_fields[F_NUM_FIELDS] = { + [F_TUNE_USB2_PREEM] = REG_FIELD(EUSB2_TUNE_USB2_PREEM, 0, 2), + [F_TUNE_SQUELCH_U] = REG_FIELD(EUSB2_TUNE_SQUELCH_U, 0, 2), + [F_TUNE_IUSB2] = REG_FIELD(EUSB2_TUNE_IUSB2, 0, 3), + + [F_FORCE_VAL_5] = REG_FIELD(EUSB2_FORCE_VAL_5, 0, 7), + [F_FORCE_EN_5] = REG_FIELD(EUSB2_FORCE_EN_5, 0, 7), + + [F_EN_CTL1] = REG_FIELD(EUSB2_EN_CTL1, 0, 7), + + [F_RPTR_STATUS] = REG_FIELD(EUSB2_RPTR_STATUS, 0, 7), +}; + struct eusb2_repeater_init_tbl { - unsigned int offset; + unsigned int reg; unsigned int val; }; @@ -48,11 +76,10 @@ struct eusb2_repeater_cfg { struct eusb2_repeater { struct device *dev; - struct regmap *regmap; + struct regmap_field *regs[F_NUM_FIELDS]; struct phy *phy; struct regulator_bulk_data *vregs; const struct eusb2_repeater_cfg *cfg; - u16 base; enum phy_mode mode; }; @@ -61,9 +88,9 @@ static const char * const pm8550b_vreg_l[] = { }; static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = { - QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8), - QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3), - QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5), + QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_IUSB2, 0x8), + QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_SQUELCH_U, 0x3), + QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_USB2_PREEM, 0x5), }; static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = { @@ -93,7 +120,6 @@ static int eusb2_repeater_init(struct phy *phy) { struct eusb2_repeater *rptr = phy_get_drvdata(phy); const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl; - int num = rptr->cfg->init_tbl_num; u32 val; int ret; int i; @@ -102,17 +128,14 @@ static int eusb2_repeater_init(struct phy *phy) if (ret) return ret; - regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1, - EUSB2_RPTR_EN, EUSB2_RPTR_EN); + regmap_field_update_bits(rptr->regs[F_EN_CTL1], EUSB2_RPTR_EN, EUSB2_RPTR_EN); - for (i = 0; i < num; i++) - regmap_update_bits(rptr->regmap, - rptr->base + init_tbl[i].offset, - init_tbl[i].val, init_tbl[i].val); + for (i = 0; i < rptr->cfg->init_tbl_num; i++) + regmap_field_update_bits(rptr->regs[init_tbl[i].reg], + init_tbl[i].val, init_tbl[i].val); - ret = regmap_read_poll_timeout(rptr->regmap, - rptr->base + EUSB2_RPTR_STATUS, val, - val & RPTR_OK, 10, 5); + ret = regmap_field_read_poll_timeout(rptr->regs[F_RPTR_STATUS], + val, val & RPTR_OK, 10, 5); if (ret) dev_err(rptr->dev, "initialization timed-out\n"); @@ -131,10 +154,10 @@ static int eusb2_repeater_set_mode(struct phy *phy, * per eUSB 1.2 Spec. Below implement software workaround until * PHY and controller is fixing seen observation. */ - regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5, - F_CLK_19P2M_EN, F_CLK_19P2M_EN); - regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5, - V_CLK_19P2M_EN, V_CLK_19P2M_EN); + regmap_field_update_bits(rptr->regs[F_FORCE_EN_5], + F_CLK_19P2M_EN, F_CLK_19P2M_EN); + regmap_field_update_bits(rptr->regs[F_FORCE_VAL_5], + V_CLK_19P2M_EN, V_CLK_19P2M_EN); break; case PHY_MODE_USB_DEVICE: /* @@ -143,10 +166,10 @@ static int eusb2_repeater_set_mode(struct phy *phy, * repeater doesn't clear previous value due to shared * regulators (say host <-> device mode switch). */ - regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5, - F_CLK_19P2M_EN, 0); - regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5, - V_CLK_19P2M_EN, 0); + regmap_field_update_bits(rptr->regs[F_FORCE_EN_5], + F_CLK_19P2M_EN, 0); + regmap_field_update_bits(rptr->regs[F_FORCE_VAL_5], + V_CLK_19P2M_EN, 0); break; default: return -EINVAL; @@ -175,8 +198,9 @@ static int eusb2_repeater_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct phy_provider *phy_provider; struct device_node *np = dev->of_node; + struct regmap *regmap; + int i, ret; u32 res; - int ret; rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL); if (!rptr) @@ -189,15 +213,22 @@ static int eusb2_repeater_probe(struct platform_device *pdev) if (!rptr->cfg) return -EINVAL; - rptr->regmap = dev_get_regmap(dev->parent, NULL); - if (!rptr->regmap) + regmap = dev_get_regmap(dev->parent, NULL); + if (!regmap) return -ENODEV; ret = of_property_read_u32(np, "reg", &res); if (ret < 0) return ret; - rptr->base = res; + for (i = 0; i < F_NUM_FIELDS; i++) + eusb2_repeater_tune_reg_fields[i].reg += res; + + ret = devm_regmap_field_bulk_alloc(dev, regmap, rptr->regs, + eusb2_repeater_tune_reg_fields, + F_NUM_FIELDS); + if (ret) + return ret; ret = eusb2_repeater_init_vregs(rptr); if (ret < 0) { From patchwork Wed Sep 13 09:53:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13382717 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 0E092CA5538 for ; Wed, 13 Sep 2023 09:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XLLu+eBWa8CT6PM4yxK55nfCv26cmm/sTIwZEJ8JGHQ=; b=FUbqSQUmAL0GPb yQUoXUmcIhHpVFKGnjdsN7rxKuNB692Rdy3fW/HKvNK+q3sHPM/89AD/jyPGG/4d8kkeLtgKeYyUh qyNfWGoxrDMh0Vy1NL9oveXR6Te+H/HBgzjX8TR+yl++egdB+siqcq8F6ARAUuXRkbAEDtEEi5xfc P48Fu9Tspl0IkCE925r5MoMjEfnTd9bDpX8bboEDfG4D6FatfYbr5P4RpFoqfoMp4ZZ+QdC2L7gmq iykh57K5ZVHxf8VsU9h8zyu5Ll4M+JmWOEjP04jOJdpk/cq1O4emYh6cvPguZuPlrpR9I84zngEAZ D5j675HfX0e3CSW1CUVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZT-005M2U-2R; Wed, 13 Sep 2023 09:54:07 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZQ-005M0g-2e for linux-phy@lists.infradead.org; Wed, 13 Sep 2023 09:54:06 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-99bf3f59905so826789166b.3 for ; Wed, 13 Sep 2023 02:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694598842; x=1695203642; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AUYPXOt61j/CwnUtExvJrzeKAesEhBK7qFjfb3sogTc=; b=tGTONgB9V3vTpnIPvXeYatt/dqSPec53fr5ChPeDCYfjU6PhkV37Lridc8e7Tq/TSh NM2+eK2/l0/e7uYtf15MDlkCCR6sgcgJ/Aj4aTOsC21QkJpLX5tqdzmXi4rEoSAGAIIb emmRpKvF6/mUsH9BxfER8r5ph3iL7V9L5hTAY3zMPMp7NJLdT+5Rca+3Z+/WfvNfd64G IAI3eeR+iNKpOWPMtAfhJsweJO/YxVrFBVJVYDbCrGneD0nLfnKvu+3zmF3xkZFUWv8i Isqq+SjeTI47QriizYyax8KwH8wNjjD9YAltJhA7u8dBxe4h+7JqY4JqWRY2oDGT1oJu +gYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694598842; x=1695203642; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AUYPXOt61j/CwnUtExvJrzeKAesEhBK7qFjfb3sogTc=; b=o4MqqTGwXtTFZt4M+oZwr8vTBhvVB26917wt2mZbD1oznjR/i/afwzHyxGoZeq+eWF 94J5NVxN0cZIqdcn5djSnLOfrIm0RwihfscUu/r1yr/TYMnDRuOYuHAmBaqWmbwvBCiW WRz0BJ+vnvFXuHuDmkoT7wmTNwxXu14glTWePJFzcs+VA7sUBE+hSXCU2yUvygrKmSBp JbkHSY+2/6TvLSZxkUITnnDbmN9Nhf9k2MHTS05U4x8hFdinpgUABtirm/lATTGsBL+w iMX7tK2yZNKpwrka+wr5p2N+AEvYVCabfhHKItgfoTnjrxAXFtCCfVRe5jQTDJSuIUbD iRYw== X-Gm-Message-State: AOJu0YxO40F7T+7F1J08S5x9bXTFfHcAg4GbWcBqZsrRsnEkFo2a/JlJ r5vdDG0dNAzlWJyUxX5RYayrqg== X-Google-Smtp-Source: AGHT+IF3u0RPMs4cBDpVSYGCHGpMz3tr9kd6x2COE/ERda2UhDsvG9XOz9FQy0oOIWnpxKOoEq/PbA== X-Received: by 2002:a17:906:518d:b0:9a1:eb67:c0ce with SMTP id y13-20020a170906518d00b009a1eb67c0cemr1832553ejk.50.1694598842583; Wed, 13 Sep 2023 02:54:02 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id l21-20020a170906939500b00985ed2f1584sm8092669ejx.187.2023.09.13.02.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:54:02 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 11:53:25 +0200 Subject: [PATCH v2 3/4] phy: qualcomm: phy-qcom-eusb2-repeater: Zero out untouched tuning regs MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v2-3-7d8c893d93f6@linaro.org> References: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> To: Andy Gross , Bjorn Andersson , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Abel Vesa Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694598835; l=4717; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=tfXcOnK4MVXM/ELTMdiq7X69Wiw7KaRfq/u6evxvcmU=; b=UGw8FhPHnMGx6HcP17G3JFukIQzCmtAOIvW5d6j5oSc8nQNnuQvW3QQokYYi2FIlAOogWBmFl GoTcZmp6N5RATkgBJkozkgEqsVFqL3D9TEPi/tH1z96eTbgboVA9uP8 X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230913_025404_869352_C1625B1C X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org The vendor kernel zeroes out all tuning data outside the init sequence as part of initialization. Follow suit to avoid UB. Signed-off-by: Konrad Dybcio --- drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c | 58 +++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c index 7561da01e633..d4fb85c20eb0 100644 --- a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c @@ -24,9 +24,18 @@ #define EUSB2_FORCE_VAL_5 0xeD #define V_CLK_19P2M_EN BIT(6) +#define EUSB2_TUNE_USB2_CROSSOVER 0x50 #define EUSB2_TUNE_IUSB2 0x51 +#define EUSB2_TUNE_RES_FSDIF 0x52 +#define EUSB2_TUNE_HSDISC 0x53 #define EUSB2_TUNE_SQUELCH_U 0x54 +#define EUSB2_TUNE_USB2_SLEW 0x55 +#define EUSB2_TUNE_USB2_EQU 0x56 #define EUSB2_TUNE_USB2_PREEM 0x57 +#define EUSB2_TUNE_USB2_HS_COMP_CUR 0x58 +#define EUSB2_TUNE_EUSB_SLEW 0x59 +#define EUSB2_TUNE_EUSB_EQU 0x5A +#define EUSB2_TUNE_EUSB_HS_COMP_CUR 0x5B #define QCOM_EUSB2_REPEATER_INIT_CFG(r, v) \ { \ @@ -35,9 +44,18 @@ } enum reg_fields { + F_TUNE_EUSB_HS_COMP_CUR, + F_TUNE_EUSB_EQU, + F_TUNE_EUSB_SLEW, + F_TUNE_USB2_HS_COMP_CUR, F_TUNE_USB2_PREEM, + F_TUNE_USB2_EQU, + F_TUNE_USB2_SLEW, F_TUNE_SQUELCH_U, + F_TUNE_HSDISC, + F_TUNE_RES_FSDIF, F_TUNE_IUSB2, + F_TUNE_USB2_CROSSOVER, F_NUM_TUNE_FIELDS, F_FORCE_VAL_5 = F_NUM_TUNE_FIELDS, @@ -50,9 +68,18 @@ enum reg_fields { }; static struct reg_field eusb2_repeater_tune_reg_fields[F_NUM_FIELDS] = { + [F_TUNE_EUSB_HS_COMP_CUR] = REG_FIELD(EUSB2_TUNE_EUSB_HS_COMP_CUR, 0, 1), + [F_TUNE_EUSB_EQU] = REG_FIELD(EUSB2_TUNE_EUSB_EQU, 0, 1), + [F_TUNE_EUSB_SLEW] = REG_FIELD(EUSB2_TUNE_EUSB_SLEW, 0, 1), + [F_TUNE_USB2_HS_COMP_CUR] = REG_FIELD(EUSB2_TUNE_USB2_HS_COMP_CUR, 0, 1), [F_TUNE_USB2_PREEM] = REG_FIELD(EUSB2_TUNE_USB2_PREEM, 0, 2), + [F_TUNE_USB2_EQU] = REG_FIELD(EUSB2_TUNE_USB2_EQU, 0, 1), + [F_TUNE_USB2_SLEW] = REG_FIELD(EUSB2_TUNE_USB2_SLEW, 0, 1), [F_TUNE_SQUELCH_U] = REG_FIELD(EUSB2_TUNE_SQUELCH_U, 0, 2), + [F_TUNE_HSDISC] = REG_FIELD(EUSB2_TUNE_HSDISC, 0, 2), + [F_TUNE_RES_FSDIF] = REG_FIELD(EUSB2_TUNE_RES_FSDIF, 0, 2), [F_TUNE_IUSB2] = REG_FIELD(EUSB2_TUNE_IUSB2, 0, 3), + [F_TUNE_USB2_CROSSOVER] = REG_FIELD(EUSB2_TUNE_USB2_CROSSOVER, 0, 2), [F_FORCE_VAL_5] = REG_FIELD(EUSB2_FORCE_VAL_5, 0, 7), [F_FORCE_EN_5] = REG_FIELD(EUSB2_FORCE_EN_5, 0, 7), @@ -62,13 +89,8 @@ static struct reg_field eusb2_repeater_tune_reg_fields[F_NUM_FIELDS] = { [F_RPTR_STATUS] = REG_FIELD(EUSB2_RPTR_STATUS, 0, 7), }; -struct eusb2_repeater_init_tbl { - unsigned int reg; - unsigned int val; -}; - struct eusb2_repeater_cfg { - const struct eusb2_repeater_init_tbl *init_tbl; + const u32 *init_tbl; int init_tbl_num; const char * const *vreg_list; int num_vregs; @@ -87,10 +109,10 @@ static const char * const pm8550b_vreg_l[] = { "vdd18", "vdd3", }; -static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = { - QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_IUSB2, 0x8), - QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_SQUELCH_U, 0x3), - QCOM_EUSB2_REPEATER_INIT_CFG(F_TUNE_USB2_PREEM, 0x5), +static const u32 pm8550b_init_tbl[F_NUM_TUNE_FIELDS] = { + [F_TUNE_IUSB2] = 0x8, + [F_TUNE_SQUELCH_U] = 0x3, + [F_TUNE_USB2_PREEM] = 0x5, }; static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = { @@ -118,8 +140,9 @@ static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr) static int eusb2_repeater_init(struct phy *phy) { + struct reg_field *regfields = eusb2_repeater_tune_reg_fields; struct eusb2_repeater *rptr = phy_get_drvdata(phy); - const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl; + const u32 *init_tbl = rptr->cfg->init_tbl; u32 val; int ret; int i; @@ -130,9 +153,16 @@ static int eusb2_repeater_init(struct phy *phy) regmap_field_update_bits(rptr->regs[F_EN_CTL1], EUSB2_RPTR_EN, EUSB2_RPTR_EN); - for (i = 0; i < rptr->cfg->init_tbl_num; i++) - regmap_field_update_bits(rptr->regs[init_tbl[i].reg], - init_tbl[i].val, init_tbl[i].val); + for (i = 0; i < F_NUM_TUNE_FIELDS; i++) { + if (init_tbl[i]) { + regmap_field_update_bits(rptr->regs[i], init_tbl[i], init_tbl[i]); + } else { + /* Write 0 if there's no value set */ + u32 mask = GENMASK(regfields[i].msb, regfields[i].lsb); + + regmap_field_update_bits(rptr->regs[i], mask, 0); + } + } ret = regmap_field_read_poll_timeout(rptr->regs[F_RPTR_STATUS], val, val & RPTR_OK, 10, 5); From patchwork Wed Sep 13 09:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 13382718 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5BC25CA553B for ; Wed, 13 Sep 2023 09:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kkhN00E0+bmNegaKTxmtO6pq1LbxLWokD6Nu0TSpwfE=; b=4IePuDGUxzOdPL aMVq6TduooW9d+ycrFbsgo7tJpGs5cgVcclrOoUZZbGpzzNLNu07gc332wEbWEqywg4bFuZM1fKqi +jOkJY8J3vkVadFy2a+n64D+nTCcMuIcJ3Suahc0FYQrhhaHObqPxNhVWQKH5SunBwrfKy4Vr6lba w5Ykn320fqkjltgIBRLyRJodQrmAU9N9/n2mmMGuw2jVz1Asrz3LZ+7iLc3wJ3DTzox08cohgBe69 rrA7P0wMrT8uCm8WFBrCVv7orA337CWjuMIcFYP0o0KBn7yqUOKqe4CsXjD7cqpHnvLJ32TPLuEcP pCOUxpEZ5wQKEs11iZJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZV-005M34-0F; Wed, 13 Sep 2023 09:54:09 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qgMZS-005M1G-0a for linux-phy@lists.infradead.org; Wed, 13 Sep 2023 09:54:07 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9ad8bf9bfabso203884666b.3 for ; Wed, 13 Sep 2023 02:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694598844; x=1695203644; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=y61vDLY2d3z1XABw8fo4c9R1eNGV9j8r0ag87ujCd/s=; b=Ag6UdKSA6m91aO6Gj4IcnnfwFiB/X95Ng8vSaw4p+TjE2ZF5jZeeXz9vK4zZI091S4 s/l7InoW3zVlnk2w4Ox2bdCjqhY4Jn9XcoAhGWhIi8Bjmn16LszNW5wY+slxMnV5qjqB LKtMASvRN7wh06DHAuKm/0FlWRJQD59AraFLF6q7xMoPcuoj8EW+05GeQaVm78tIgXXC GdKAcjXTPltU7xZ3EwCAMy0vtjoLfQC0GvuGvfO6mXenkT/OZNsASedYR6L4gaTDHiVw /uZhR1EuTzzoiOKJmwiz0uCZ2hs7PVPmYHuk/ku9eFzJi/elRpG4Yar9bK2IAA7Guj4h Mnhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694598844; x=1695203644; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y61vDLY2d3z1XABw8fo4c9R1eNGV9j8r0ag87ujCd/s=; b=W5Jh6RGA0WjrMS+PiZ9qRg5jzwvKKmSpRis81FHPiqjqCIOCgYylJIPP4rORTXx5Q8 ADzdrP/3Bac6TsHiy1HymjjFC+GMezt++cGXml6I3RUAa1ZLVLXUoI2l7B4z3VFx94ej EXub/vkJq3Nmzjh9nh7x6bPbf6ByiXkWH7yCqeS2e/Ny/lHC2N0+kl3yYhYOmf5k0hsx itbaFJtJXP716Nw/oY2gWlCRSDsR+tHR1+lIPkePlgMOzc/nJnztJabdFp6ABRSCgA8q hWJ46xf/BC4fT6sl+1sjBlivXjMmrYrK7iVymfsxQ/X49CNzzmp8qJ7c5bPxCOvX6ADd D5qA== X-Gm-Message-State: AOJu0YzcW9xfntvQEEzqGKh8OCiW38TwxavnLp6knFLSKRuSmZX4QQ7D CjMcnqsssDdRl2thu2dk9QeLpw== X-Google-Smtp-Source: AGHT+IFq5xptVCdrvn1Iw7ewtXMqSOxhBecllLxs5hb0dwAim5rm5D+Auq3O1vfHh7PKHxaom5Tmng== X-Received: by 2002:a17:906:319a:b0:9a1:c00e:60c5 with SMTP id 26-20020a170906319a00b009a1c00e60c5mr1459575ejy.48.1694598844117; Wed, 13 Sep 2023 02:54:04 -0700 (PDT) Received: from [10.167.154.1] (178235177106.dynamic-4-waw-k-1-1-0.vectranet.pl. [178.235.177.106]) by smtp.gmail.com with ESMTPSA id l21-20020a170906939500b00985ed2f1584sm8092669ejx.187.2023.09.13.02.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:54:03 -0700 (PDT) From: Konrad Dybcio Date: Wed, 13 Sep 2023 11:53:26 +0200 Subject: [PATCH v2 4/4] phy: qualcomm: phy-qcom-eusb2-repeater: Add tuning overrides MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v2-4-7d8c893d93f6@linaro.org> References: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v2-0-7d8c893d93f6@linaro.org> To: Andy Gross , Bjorn Andersson , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Abel Vesa Cc: Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1694598835; l=1798; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=vlWt+/crcyxMQdUhFQmb4WOVKaBs0wbkNDm3+xQ+iBc=; b=rj7SzS4MbUgXjzqv55kbUGwKD8esrMRttXxGkS+rICUBd8qFKbouTxfru32W5y6X7a00cfv4x 32ZjJI8ZlwwBxD5Fbcx78qPt7e2le1FLdTFvkRx6e79+TsMPkhHqPYH X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230913_025406_224187_86279CD2 X-CRM114-Status: GOOD ( 12.20 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org There are devices in the wild, like the Sony Xperia 1 V that *require* different tuning than the base design for USB to work. Add support for overriding the necessary tuning values. Signed-off-by: Konrad Dybcio --- drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c index d4fb85c20eb0..a623f092b11f 100644 --- a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c @@ -142,7 +142,9 @@ static int eusb2_repeater_init(struct phy *phy) { struct reg_field *regfields = eusb2_repeater_tune_reg_fields; struct eusb2_repeater *rptr = phy_get_drvdata(phy); - const u32 *init_tbl = rptr->cfg->init_tbl; + struct device_node *np = rptr->dev->of_node; + u32 init_tbl[F_NUM_TUNE_FIELDS] = { 0 }; + u8 override; u32 val; int ret; int i; @@ -163,6 +165,19 @@ static int eusb2_repeater_init(struct phy *phy) regmap_field_update_bits(rptr->regs[i], mask, 0); } } + memcpy(init_tbl, rptr->cfg->init_tbl, sizeof(init_tbl)); + + if (!of_property_read_u8(np, "qcom,tune-usb2-amplitude", &override)) + init_tbl[F_TUNE_IUSB2] = override; + + if (!of_property_read_u8(np, "qcom,tune-usb2-disc-thres", &override)) + init_tbl[F_TUNE_HSDISC] = override; + + if (!of_property_read_u8(np, "qcom,tune-usb2-preem", &override)) + init_tbl[F_TUNE_USB2_PREEM] = override; + + for (i = 0; i < F_NUM_TUNE_FIELDS; i++) + regmap_field_update_bits(rptr->regs[i], init_tbl[i], init_tbl[i]); ret = regmap_field_read_poll_timeout(rptr->regs[F_RPTR_STATUS], val, val & RPTR_OK, 10, 5);