From patchwork Wed Sep 6 20:52:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 9941297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 796146038C for ; Wed, 6 Sep 2017 20:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AFC51FF61 for ; Wed, 6 Sep 2017 20:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F6F3223A0; Wed, 6 Sep 2017 20:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08FEA2236A for ; Wed, 6 Sep 2017 20:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dk/8wqVmpcn3gvaDnKPoOusi+X8yLQMAe7F6yc2nE2s=; b=Gv/8s9GibLg6BhjHPwVZjgXFr1 TFufcHzkiBwWueODfsh3bkWyl1YwfddRmuEM8lQiqljmhJha+I0wEQAr9xJCvTy8dYzyP2PPbZzLQ ULUD4M9+ILmwQLjlIN6xoe/TpEsiZqLPR1dKs24cPlLuUKjtpviohyUj06v6K3Ux7RDhdMNiQdgJ2 AERvRmko++uu5hGrS7XpLCgphB3We9zNDtFhfbnQraBIQoqm0I1z7OwdNY4N1+ctwrMxLiD5WrmE4 kbvMPb1T4Xk5u+8ERGXQYPEu6gt9IHRJbXPmtRT0Uxh9R0XNZPKdKUDLwCGCKrbVRNznP0+u7aFgG wobf5FyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dphKB-0004Jh-CV; Wed, 06 Sep 2017 20:53:27 +0000 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dphJq-0003pV-MO for linux-rockchip@lists.infradead.org; Wed, 06 Sep 2017 20:53:17 +0000 Received: by mail-pg0-x22c.google.com with SMTP id v66so17117791pgb.5 for ; Wed, 06 Sep 2017 13:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RGJYVtXUqZTktrTYKq6bxiqJyOQURV/m1l7oaoVlKuo=; b=a7HnsJHRhbVJC/phl+dgDtjvicHHNlVfRWM3Vvrhj/leapSuYVcQNmbhaJqnGiTUM+ 0ddYrfH8pbxXsTOR4i/AhSsKCrO5Sl15wZ4ryq9rBHXXqT+uG+HtDMrWaRWdHg5BTq7H 5ivmd9E/KD+UoHLc+MNXIWUZiWlOtpvIjik6Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RGJYVtXUqZTktrTYKq6bxiqJyOQURV/m1l7oaoVlKuo=; b=V0FHIo11az33VcTNueFRP1xD2PL0Zgn6rvUzrqbCVC3aEt/IYgZk/H3FwAvrhlmHir SL5EJs2tRikJttzq4VBmH7gFd8/oM6RCDyVOdXTJEt9Bl/Lbmue5E9htaAlFAuqfKxTO nPm8IASXfQoxP/gesgL4T0PLmNC2dGGQhj5l0MKtixbLvtAtwiJwVumD87R3JqO/YPyt quvHWi45P4lPzTFJLZb1c26KUgMkSqB/M4p8v0IE00zldJsud+8f2u4Ejb2hNhLnNSrZ ziqK6cKC30C627pxfGbFFyTOT5SJC305wFYZYFatuFaXnOTg0tDlW6r/3rVgCKB7IKJo RqmA== X-Gm-Message-State: AHPjjUjdEhoj4HvHSTNCQL6ueidmQRR3MpuGC4NQy3bS5aUWS+Sqrs/H t23zQJpqCDrV6ed+ X-Google-Smtp-Source: ADKCNb5T5v2TVgx8pFiBs2Zns7pULjRtkGxzCYgMJV5mD95JjcESvUTZG603XHzF+RUGCJfv28B4Nw== X-Received: by 10.98.98.5 with SMTP id w5mr406166pfb.337.1504731165806; Wed, 06 Sep 2017 13:52:45 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.112.154]) by smtp.gmail.com with ESMTPSA id r15sm870771pfj.41.2017.09.06.13.52.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Sep 2017 13:52:45 -0700 (PDT) From: Douglas Anderson To: kishon@ti.com, heiko@sntech.de, zyw@rock-chips.com Subject: [PATCH 3/3] phy: rockchip-typec: Do the calibration more correctly Date: Wed, 6 Sep 2017 13:52:01 -0700 Message-Id: <20170906205201.16207-4-dianders@chromium.org> X-Mailer: git-send-email 2.14.1.581.gf28d330327-goog In-Reply-To: <20170906205201.16207-1-dianders@chromium.org> References: <20170906205201.16207-1-dianders@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170906_135310_746690_A866BE38 X-CRM114-Status: GOOD ( 11.74 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: shawnn@chromium.org, Douglas Anderson , dnschneid@chromium.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Calculate the calibration code as per the docs. The docs talk about reading and averaging the pullup and pulldown calibration codes. They also talk about adding in some adjustment codes. Let's do what the docs say. In practice this doesn't seem to matter a whole lot. On a device I tested the pullup and pulldown codes were nearly the same (0x23 and 0x24) and the adjustment codes were 0. Reviewed-by: Chris Zhong Signed-off-by: Douglas Anderson --- drivers/phy/rockchip/phy-rockchip-typec.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c index b8696a7c45fb..e59983a82dcc 100644 --- a/drivers/phy/rockchip/phy-rockchip-typec.c +++ b/drivers/phy/rockchip/phy-rockchip-typec.c @@ -194,6 +194,7 @@ /* Use this for "n" in macros like "_MULT_XXX" to target the aux channel */ #define AUX_CH_LANE 8 + #define TX_ANA_CTRL_REG_1 (0x5020 << 2) #define TXDA_DP_AUX_EN BIT(15) @@ -560,24 +561,33 @@ static void tcphy_dp_aux_calibration(struct rockchip_typec_phy *tcphy) u16 val; u16 tx_ana_ctrl_reg_1; u16 tx_ana_ctrl_reg_2; - s32 pu_calib_code; - - /* disable txda_cal_latch_en for rewrite the calibration values */ - tx_ana_ctrl_reg_1 = readl(tcphy->base + TX_ANA_CTRL_REG_1); - tx_ana_ctrl_reg_1 &= ~TXDA_CAL_LATCH_EN; - writel(tx_ana_ctrl_reg_1, tcphy->base + TX_ANA_CTRL_REG_1); + s32 pu_calib_code, pd_calib_code; + s32 pu_adj, pd_adj; + u16 calib; /* - * read a resistor calibration code from CMN_TXPUCAL_CTRL[5:0] and - * write it to TX_DIG_CTRL_REG_2[5:0]. + * Calculate calibration code as per docs: use an average of the + * pull down and pull up. Then add in adjustments. */ val = readl(tcphy->base + CMN_TXPUCAL_CTRL); pu_calib_code = CMN_CALIB_CODE_POS(val); + val = readl(tcphy->base + CMN_TXPDCAL_CTRL); + pd_calib_code = CMN_CALIB_CODE_POS(val); + val = readl(tcphy->base + CMN_TXPU_ADJ_CTRL); + pu_adj = CMN_CALIB_CODE(val); + val = readl(tcphy->base + CMN_TXPD_ADJ_CTRL); + pd_adj = CMN_CALIB_CODE(val); + calib = (pu_calib_code + pd_calib_code) / 2 + pu_adj + pd_adj; + + /* disable txda_cal_latch_en for rewrite the calibration values */ + tx_ana_ctrl_reg_1 = readl(tcphy->base + TX_ANA_CTRL_REG_1); + tx_ana_ctrl_reg_1 &= ~TXDA_CAL_LATCH_EN; + writel(tx_ana_ctrl_reg_1, tcphy->base + TX_ANA_CTRL_REG_1); /* write the calibration, then delay 10 ms as sample in docs */ val = readl(tcphy->base + TX_DIG_CTRL_REG_2); val &= ~(TX_RESCAL_CODE_MASK << TX_RESCAL_CODE_OFFSET); - val |= pu_calib_code << TX_RESCAL_CODE_OFFSET; + val |= calib << TX_RESCAL_CODE_OFFSET; writel(val, tcphy->base + TX_DIG_CTRL_REG_2); usleep_range(10000, 10050);