From patchwork Wed Aug 30 02:40:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 718745 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 179CFC83F1D for ; Wed, 30 Aug 2023 02:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241745AbjH3Cka (ORCPT ); Tue, 29 Aug 2023 22:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241734AbjH3CkX (ORCPT ); Tue, 29 Aug 2023 22:40:23 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72494D7 for ; Tue, 29 Aug 2023 19:40:20 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-50079d148aeso7921788e87.3 for ; Tue, 29 Aug 2023 19:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693363219; x=1693968019; darn=vger.kernel.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=eftHGQRECzJuXi1OVtNB5hDXhj+Beyk7gIuR4DJasbs=; b=KtJQ381XdR/dLR82WKVphmKPHBuJHAAAk+Dka+MwxRXy3IwpOCt4Z7sLyjnaE9l3oL lNxC1CJ9a867vEvK2XB4WBlrnR4Z7Kq90DlAbgdbF2lp2uBAG3/npTh7X2TC90rKxlnv x/skRaqP1RuWI3XZv0FdbVpcxOwh3ZQ8remZe5SytRreOzPLyakqvmXJB5m1VNQadQv3 IR8IMGvQHKqfMVn+KWbxuKCW2WxbpdGhAmQMy08g7deZ2uasoWMCIxKx9tLSanFvviFS 0rC1pFAoEHZHmfcXzuc4S9CI7jYRvkFD17Hsy3r1mKGE+kqsG4TffmCFwqpAJADSNBCL ERZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693363219; x=1693968019; 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=eftHGQRECzJuXi1OVtNB5hDXhj+Beyk7gIuR4DJasbs=; b=XljY+pjZF4+N1YwrdgVTGJHF9DpKXc8FRHv0msaetQtJ+cgG8IIvKsBUrTqPWFVqd9 Z7xQB7FkyDDIcG2x7cM+MFQkJv82wg/lf0NfQHuwHjrBnhpMpL+Gl1zPBdu+FAvt+8rG EbqEQz3hTrFUfUJsbWvgw5egYj3X09EXuY/hQGP1deyZI33rR40xReWxjDPqxxNehS4e MXcyXVv9yUVu7yAP2C2L2GEIjVastiepg6nyWP3TVly8fBin0zExjCm6nPVKJei+D+qj CkHoId/aNHeb+Iz0sf2PmxXrad93OsqVP2oxs3t/gUTWK2XtmHuSw8cQQOeRIgdjpcyC U3Xw== X-Gm-Message-State: AOJu0YwcGqHSTGlOMNKmsSeOjZVukD3Hio+sWsplQQJ7HpD0jv2kNT/3 TTVtc99PCoYpZLbrwdwUVjybow== X-Google-Smtp-Source: AGHT+IFHf9gBoE1ACeP5RVIgyVWnmxwTQm1ACDYzoey0sp3f/Y6uJkIWgpkT86PBWwx0PT6aRJeXxQ== X-Received: by 2002:a05:6512:368f:b0:500:bf44:b2b6 with SMTP id d15-20020a056512368f00b00500bf44b2b6mr406324lfs.45.1693363218120; Tue, 29 Aug 2023 19:40:18 -0700 (PDT) Received: from [192.168.1.101] (abyl195.neoplus.adsl.tpnet.pl. [83.9.31.195]) by smtp.gmail.com with ESMTPSA id w7-20020ac254a7000000b004fb99da37e3sm2183878lfk.220.2023.08.29.19.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 19:40:17 -0700 (PDT) From: Konrad Dybcio Date: Wed, 30 Aug 2023 04:40:15 +0200 Subject: [PATCH 1/4] dt-bindings: phy: qcom,snps-eusb2-repeater: Add magic tuning overrides MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v1-1-ab23825385a8@linaro.org> References: <20230830-topic-eusb2_override-v1-0-ab23825385a8@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v1-0-ab23825385a8@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=1693363215; l=1464; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=gOCoteo3eQFlsbrCmDlbDQsd6KpyGXjafi9HiIGRkBg=; b=I1ZTgaIC2oul/Cky4mzGoprgT3MxHSMek90ddaxpeFmCCCti1/S1gJ/cYPlRgCg7X23/Efw9k oZB5EyI87n3CD7c8+a1pi5LAwKjFZirypeO0ii1ML28JEmvoAHi1ABk X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 --- .../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..83fd6f936bf9 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-hsdisc-value: + $ref: /schemas/types.yaml#/definitions/uint8 + description: High-Speed disconnect threshold + minimum: 0 + maximum: 7 + default: 0 + + qcom,tune-iusb2-value: + $ref: /schemas/types.yaml#/definitions/uint8 + description: High-Speed trasmit amplitude + minimum: 0 + maximum: 15 + default: 8 + + qcom,tune-usb2-preem-value: + $ref: /schemas/types.yaml#/definitions/uint8 + description: TX pre-emphasis tuning + minimum: 0 + maximum: 7 + default: 5 + required: - compatible - reg From patchwork Wed Aug 30 02:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 718746 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0635AC83F1E for ; Wed, 30 Aug 2023 02:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241730AbjH3Cka (ORCPT ); Tue, 29 Aug 2023 22:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241736AbjH3CkY (ORCPT ); Tue, 29 Aug 2023 22:40:24 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19AB2CD7 for ; Tue, 29 Aug 2023 19:40:21 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bcc14ea414so77690761fa.0 for ; Tue, 29 Aug 2023 19:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693363219; x=1693968019; darn=vger.kernel.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=GRX8mvWPNnXmxTYU68Ksm6d1xtkXk5pDG32vjLUfxzRybSOibWJKmFqV8WaYS2JuwU F7N2nWMQ7CKMWMJ6S7sCH8AyZiFiOjPxS54lDNIKtPaZKCf0yRmuhOwO/fEiqnIvjMq5 9zG6LjAsLcA8SkgS64v0SmzVnIkSDy4iCRL5craaHbO40A7XW14gVRrGM5Ukly6ZR8Fs 5xGVvn+UlzWQbIIks4CzSQ3guEeE799KQOs6lvU18qYqD4A7qPRKPTb/kuM27qnR5yob dm/U5bcoFy0FQKuvwitlLVpmKF/i7rko+j7FMgqZE/Z5rftqukdR4fd2NbxwP6ifaXLL iTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693363219; x=1693968019; 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=bG8zG6ozE+dFn9TR8lJLqhNYJlJQmxrpwLbmxo9Ea0PeQVoxSUH3U/bY7X55+yDInl DuFYYnKKqOAuEffEVYU2QU31rNsbGd5WJiuE8mt7dDOe/GmWq1IopyB6DmGzBO0htrrE wShhuU3o7hZ68Y+y8A7Cof4Tls+I3wFOoS1+Cmo6l9CioJvWudWXYbGmxdUP+HePXR14 /nKXs6oUxcGxygMe9+Lx9KBClPu57JWeUKTjjFTwc0V2uvmb4FB8dElE08vs60/WmMz3 mhWjnbxG/Gj89fHQ2hTnCK7E49SGzbJhkKj63yrEWiJ3o0p/3ih5HR5q/o2rXwuGkWNq e90A== X-Gm-Message-State: AOJu0YzKENJZ9D1JsYZVKynju7pIG2AvvrbEQcVrzxZRxDAMTdGNZgHQ W7c1Rk0NcThV1dGknjtq9U2Arg== X-Google-Smtp-Source: AGHT+IFpBDe1bzQ/cK5vCouexaMPmERPp/g75Tb3Qz47U7S6slLNMI13E0TDLktmOPGAUr6ny71NYg== X-Received: by 2002:a19:2d57:0:b0:4fb:7675:1c16 with SMTP id t23-20020a192d57000000b004fb76751c16mr428572lft.49.1693363219478; Tue, 29 Aug 2023 19:40:19 -0700 (PDT) Received: from [192.168.1.101] (abyl195.neoplus.adsl.tpnet.pl. [83.9.31.195]) by smtp.gmail.com with ESMTPSA id w7-20020ac254a7000000b004fb99da37e3sm2183878lfk.220.2023.08.29.19.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 19:40:19 -0700 (PDT) From: Konrad Dybcio Date: Wed, 30 Aug 2023 04:40:16 +0200 Subject: [PATCH 2/4] phy: qualcomm: phy-qcom-eusb2-repeater: Use regmap_fields MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v1-2-ab23825385a8@linaro.org> References: <20230830-topic-eusb2_override-v1-0-ab23825385a8@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v1-0-ab23825385a8@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=1693363215; l=6150; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=LovaKfaqbkXiJ4az1PcPQZkH3FJdcJGz/pvW4OALguE=; b=a1geA4S8J2PTY4afb36vvk6SABGZSBl3BzJ58jL28SAunNSUJTSIThBvWtY/k3frdhxgqX9Er 6Pzctxcx9efBmMgVVRoGbJildXxxJjFaq9yznlfbyMmi1UDDIbYyDdr X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 Aug 30 02:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 719288 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D83F3C83F1C for ; Wed, 30 Aug 2023 02:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241748AbjH3Ckb (ORCPT ); Tue, 29 Aug 2023 22:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241739AbjH3CkZ (ORCPT ); Tue, 29 Aug 2023 22:40:25 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E66D7 for ; Tue, 29 Aug 2023 19:40:22 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-50098cc8967so7964003e87.1 for ; Tue, 29 Aug 2023 19:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693363220; x=1693968020; darn=vger.kernel.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=C4cHSwUyFzEktn3DghWL2c38zb9i5jrhA53otXSIPl0=; b=Ut4dqSjT/JKTP/HR6VMC5nJ9QZ5uZ/0LVp/VwZq+4XLFNFDRq5vNvquHiO3JuVTDNE O7+Tf9JdQnCPWrUTvkjKfE5B/EUYTayHOj66P/XpbyG7yw187MZVIsrtxAqNkAo8tfgA GIcrwePlOi4qOFtpFtEhhZTkOUYr0jpBvXa9HhzfJQkMkh6XbS3rB/GnXiF76wk7vhs1 +PAKXLogl4FHuJc1fzUNcof4iz9ZpqYMn68yLWULtLHVQyWqg0IMHyM/EdKC6scTGpey sc3xjxAvKK917GWwTGodZ89Y0iXZgI6urywYTF0u9WJA72m7gNYaZbxVfgXLmQ1gCTf5 JhHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693363220; x=1693968020; 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=C4cHSwUyFzEktn3DghWL2c38zb9i5jrhA53otXSIPl0=; b=kPOAERN/EAvqYkYvPVVlycQHjYIO3GgOChLerOT8ueeqgQs+/azQsK1SSAWncbVZUC DgV3yK0Xucp/DgTDtepduXz0Zzaf5ke2Yb8L5VzldM7H4D+sCOVCv6u3bxrAuG2SUjfx gWSjqHdeuy/ySnYSTNkse2G/FugXeJM1ZLYub7xh/yOVeAgzuixEmQhzCX6e5jwrRpfq jIan3DJVMroiF826khwLfYqi5RE0hx/6klYolqlviQvG1TwEpTZteBmp1wqa8uPEuCM0 wgw5Bl6iH2flSggnkxT5sc/jgHHeofhlTTzr8DPeVd+1a/DVGUyYmJ5jWeKjXx/QpAuO 8fbw== X-Gm-Message-State: AOJu0Yxe50wCBRkXzxPsT1NtqjBOxoy4cBDvcZlMRtuGT8DAy1Ax4C9L xX5JkSsnDx+6hQ+QwSUp5BUuZQ== X-Google-Smtp-Source: AGHT+IHBkg4b6ijOZVk1MC+rXi+R32uS7DM4uSAUqboM9an2pgttvClkrCz3fzYKhKRMPaEc7qH+jw== X-Received: by 2002:a19:4f45:0:b0:4fe:a2c:24b0 with SMTP id a5-20020a194f45000000b004fe0a2c24b0mr406115lfk.26.1693363220722; Tue, 29 Aug 2023 19:40:20 -0700 (PDT) Received: from [192.168.1.101] (abyl195.neoplus.adsl.tpnet.pl. [83.9.31.195]) by smtp.gmail.com with ESMTPSA id w7-20020ac254a7000000b004fb99da37e3sm2183878lfk.220.2023.08.29.19.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 19:40:20 -0700 (PDT) From: Konrad Dybcio Date: Wed, 30 Aug 2023 04:40:17 +0200 Subject: [PATCH 3/4] phy: qualcomm: phy-qcom-eusb2-repeater: Zero out untouched tuning regs MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v1-3-ab23825385a8@linaro.org> References: <20230830-topic-eusb2_override-v1-0-ab23825385a8@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v1-0-ab23825385a8@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=1693363215; l=4436; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=clg99SRrpP7Rr9sq765kCJ32qSeqb/MC63Wr0fr+Fsk=; b=lkPO+s4HhubGVZzqV8mpoo0iahoW2A7Wd+geW/BccLi+Ts93n5LWCzvlqOlLa5f7MJhXNb937 6hFpHSz+XXeArI0DUBNJ6BlIp+w1vKdKDVcz8SlKnJP+eXu0iAmwkau X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 | 49 ++++++++++++++++++-------- 1 file changed, 35 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..645f0e95703a 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 = { @@ -119,7 +141,7 @@ static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr) 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; + const u32 *init_tbl = rptr->cfg->init_tbl; u32 val; int ret; int i; @@ -130,9 +152,8 @@ 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++) + 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); From patchwork Wed Aug 30 02:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 719287 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B32BFC83F25 for ; Wed, 30 Aug 2023 02:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241733AbjH3Ckb (ORCPT ); Tue, 29 Aug 2023 22:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241743AbjH3Ck0 (ORCPT ); Tue, 29 Aug 2023 22:40:26 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7842FCD2 for ; Tue, 29 Aug 2023 19:40:23 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4ff8cf11b90so8158985e87.1 for ; Tue, 29 Aug 2023 19:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693363222; x=1693968022; darn=vger.kernel.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=u79yO0iAhOgHSkdtiLEgJV1fUj3/h29d83dbFcGVhBU=; b=BrBqBKL77X0uemEsLAHm/YcDZNOl+bVb4Eam0RM3uwKqNEsxYiAhfrBrs2bun0P2s2 PLrEvJFgY3gGxeYuWcJWNOMoESggXsfLAcyaYjH3LSjnBnIpaoB7jOYA1JfOpMYG8PuC 7XbjHovhDgbRzTKd2TCTPf9GID5/1xrLMtX06zbc0iPZDf+L8ypoIYys1H3WQiQIHNnS AA4gjAlbORXmlxR3wYoS0qWkV+2wdlITIZ+0PaSssYzIGJgflz3nmZcfxDx4QQrSYhmv aqPXDqLcT1N4Y2aWXqSzwNdHOPOzrtQ1E5QN/MGWBMSW6Qko8ywh7U7PMr8KnfYtbsgO Ev9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693363222; x=1693968022; 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=u79yO0iAhOgHSkdtiLEgJV1fUj3/h29d83dbFcGVhBU=; b=kQaNnmI8lkGZEDiixYvKF+BLMVT6GtFFgitl5g3EYPbwNvVvT7Ni1A+vQX6gSGvqC8 YI9H2cMpnX3ffGI2EruZ4t1M7lQFG8NbGRzEPBS6Cg2b8h59rm63QKVcH0yFMfNYzjuk qByGmLgzMNB7ykv22nwM2gT6Bx3AK7JAMKC+VasvAd2KRX/EUkkiL6+lcxypuXE1XwD5 gTt+jMGrjR+i1hEXk7FgvbTHRtnT9ty6lWN4QzpTkAab/zNz8XaloLqQZLin7Q8+V24F pJi8KaXq9ME7Vpa7Nx441gFQGV1HmiRxHfZ5t2pGFZxNE2cLUC7PNbc6mL0NZq0cJooI SBoA== X-Gm-Message-State: AOJu0YyxcGbvrRtHJXaNYO2uGtgI4VzhsM23DKJLSi3pyZPRFVyG3/Wn qANbJHZcL/ic4yXOfxe5Pz/vPr5myGPy63wu6iixvQ== X-Google-Smtp-Source: AGHT+IEB+Pvy4SQ9xZVdKt+EmXsnpVvha1l5vFdek6iZ3eZULbMZNYOs++suiQW5lY4y3P0QFRWZaQ== X-Received: by 2002:a05:6512:312b:b0:500:a0a3:80ff with SMTP id p11-20020a056512312b00b00500a0a380ffmr445095lfd.58.1693363221890; Tue, 29 Aug 2023 19:40:21 -0700 (PDT) Received: from [192.168.1.101] (abyl195.neoplus.adsl.tpnet.pl. [83.9.31.195]) by smtp.gmail.com with ESMTPSA id w7-20020ac254a7000000b004fb99da37e3sm2183878lfk.220.2023.08.29.19.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 19:40:21 -0700 (PDT) From: Konrad Dybcio Date: Wed, 30 Aug 2023 04:40:18 +0200 Subject: [PATCH 4/4] phy: qualcomm: phy-qcom-eusb2-repeater: Add tuning overrides MIME-Version: 1.0 Message-Id: <20230830-topic-eusb2_override-v1-4-ab23825385a8@linaro.org> References: <20230830-topic-eusb2_override-v1-0-ab23825385a8@linaro.org> In-Reply-To: <20230830-topic-eusb2_override-v1-0-ab23825385a8@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=1693363215; l=1714; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=NiPnqK52QKHkd/CcD5h/xTEyUsqIlLXa328usvhRCnU=; b=VOEa0hyyG8UbttF1hLRne2t5QpVGEd7PBgEJAs3wp6uAI0TP1KnT9BEe4A+kAXPL1NCFnQmTd /cC2j3wCQ5fA7z1vShBb/7d6X7rOXpxgi457n+zuW2LVAKcm2t95ufT X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c index 645f0e95703a..53e10feb16a1 100644 --- a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c @@ -141,7 +141,9 @@ static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr) static int eusb2_repeater_init(struct phy *phy) { 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; @@ -152,6 +154,17 @@ static int eusb2_repeater_init(struct phy *phy) regmap_field_update_bits(rptr->regs[F_EN_CTL1], EUSB2_RPTR_EN, EUSB2_RPTR_EN); + memcpy(init_tbl, rptr->cfg->init_tbl, sizeof(init_tbl)); + + if (!of_property_read_u8(np, "qcom,tune-iusb2-value", &override)) + init_tbl[F_TUNE_IUSB2] = override; + + if (!of_property_read_u8(np, "qcom,tune-hsdisc-value", &override)) + init_tbl[F_TUNE_HSDISC] = override; + + if (!of_property_read_u8(np, "qcom,tune-usb2-preem-value", &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]);