Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1253218iog; Tue, 14 Jun 2022 02:22:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYTV7zPi/r31RLLjunxSzLt5QXYgmiH7oBOF7K4OMvfJhLzWoUD65JWGACcMqOczUe13r4 X-Received: by 2002:a17:90b:4d05:b0:1e0:b53:f4a3 with SMTP id mw5-20020a17090b4d0500b001e00b53f4a3mr3543009pjb.3.1655198539904; Tue, 14 Jun 2022 02:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655198539; cv=none; d=google.com; s=arc-20160816; b=VB06MFkpDSsVirE/YXHPh3BJDebx4Wcd6qI2xo5Uy/sGcNi8KQVDS0LsY137Yi9Lcy Objo6yCvxK1spejBPskgaFvLy+1FajFD282niUV2oYtzE6DNOg5wpxlosKZpwLO7p4N4 ZgkZQfTqDy/Kl/bZpyp4ZzPPELj8I4ATplZUjmkXknk8LY5CgSfM6sPNEDS3t+3Yj7Jp 7/GCtD9zIUV0z3LI+HMhnyVmyeB0925pJUCBzT4I9dcZh2nOrOEqgiGFn6YThBTdcjGa Fi/XamgX4AojpSKXCM+GVLZptmJRa9A2oDjuJj0Uq0Dj/u/XWLClLgmFQfoETmk+2Qgg cIbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VUSdGLwnJ0Y/lNfZiFkctM/6S+/lIr4cXT4yYV5L0eg=; b=ixgDin4zRzHkMv9KIn9ykwdlRkbAw+v1VjJzQ6jLRFJi6o5sNgG7jHSmhz0wIG0WWu 6lU+Dsv3WAgpNNg8fLWcOy6mKw/m3uTmHfCKcZT4gMx8fF2cCIUU70Zm+t3tp2fn4gTk MKdcXSfGrfoZ7Yw1WL+hmAk7MAmgLVLskGa1MiuxqKjcIYViC1C0SHJj9M4R/q3G9N5c nk5/RYUjDM1yX6pwSebNtataQ6ec0/WShR3pa1xzKeWp0CcOFIq2ZUSF75Ku9bG1hOHk jk8S2XenWo8Si/uMoPQpDOngk345gkfqs4d6txPdcSIoyOlpQ1IdaNuVUXbjFhNS9I5P H0fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=ds3Ls87l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c198-20020a6335cf000000b003f9cde547fasi12408613pga.631.2022.06.14.02.22.08; Tue, 14 Jun 2022 02:22:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=ds3Ls87l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241293AbiFNIr1 (ORCPT + 99 others); Tue, 14 Jun 2022 04:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242359AbiFNIq0 (ORCPT ); Tue, 14 Jun 2022 04:46:26 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC96B42A01 for ; Tue, 14 Jun 2022 01:46:21 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id m25so8906153lji.11 for ; Tue, 14 Jun 2022 01:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VUSdGLwnJ0Y/lNfZiFkctM/6S+/lIr4cXT4yYV5L0eg=; b=ds3Ls87l3/RTps8cjzbiCoEtfAT/UNTYNbmZ3vxsR0hnyRIM4JISzsT8HkoR+6+4eP 3Cqfb+JGxyWAcNqNoxVve8rYObAC8MnNPQ+zdDSbT547/eFDUrPgC4XCC1yhvfm7wVDs gBoQe8fxIVPWmwyvCxK0peaqzLKc2z/XRjO1Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VUSdGLwnJ0Y/lNfZiFkctM/6S+/lIr4cXT4yYV5L0eg=; b=OaCI+tYv+UqNuL+k/tqEOJ8mqFawVXH9mpKTvSfv2skHb5EgngwREPs+/bMWTP9DxV SYE2kxxWj6BBbaZ087gX5RZwlgU+4bOFtmUOVun5AGRgToi2/M+xbTo00JyH8t58zKXW zu/BX+Acvjz1oiR0wKtNJWf6ZzV8O4WIQdp3ct5zjCRdXJtwGY+bUSzxq89uhc3eCoQQ 5YTcB9S3AGoT5UawDmV2rvwjEMYnwf5OHHGopr4z4c9At/FGmNw8+lgQWxehO/ESJuhn yJtnwvf0bLvGnAKdy9lT7w22h7aQFSQmlV1zxfYlrXENxEZDri4mGvPrBjVKni9WU/bw x6Iw== X-Gm-Message-State: AJIora8ndcdPf89gZw3LNgiTgNbxjd+HF3RmtSToRhOhfEl1O9CR0kh8 RT7A+SkYg2RFcAuaZsOYTlPp2g== X-Received: by 2002:a2e:3a17:0:b0:255:772a:e9e2 with SMTP id h23-20020a2e3a17000000b00255772ae9e2mr1859147lja.440.1655196380110; Tue, 14 Jun 2022 01:46:20 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id g1-20020ac24d81000000b0047255d2118fsm1306116lfe.190.2022.06.14.01.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 01:46:19 -0700 (PDT) From: Rasmus Villemoes To: netdev@vger.kernel.org, Andrew Lunn , Heiner Kallweit , Russell King Cc: devicetree@vger.kernel.org, Rob Herring , Jakub Kicinski , "David S. Miller" , Grygorii Strashko , Praneeth Bajjuri , linux-kernel@vger.kernel.org, Rasmus Villemoes Subject: [PATCH net-next v2 3/3] net: phy: dp83867: implement support for io_impedance_ctrl nvmem cell Date: Tue, 14 Jun 2022 10:46:12 +0200 Message-Id: <20220614084612.325229-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220614084612.325229-1-linux@rasmusvillemoes.dk> References: <20220606202220.1670714-1-linux@rasmusvillemoes.dk> <20220614084612.325229-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have a board where measurements indicate that the current three options - leaving IO_IMPEDANCE_CTRL at the (factory calibrated) reset value or using one of the two boolean properties to set it to the min/max value - are too coarse. Implement support for the newly added binding allowing device tree to specify an nvmem cell containing an appropriate value for this specific board. Signed-off-by: Rasmus Villemoes --- drivers/net/phy/dp83867.c | 55 ++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 8561f2d4443b..45d8a9298251 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -521,6 +522,51 @@ static int dp83867_verify_rgmii_cfg(struct phy_device *phydev) } #if IS_ENABLED(CONFIG_OF_MDIO) +static int dp83867_of_init_io_impedance(struct phy_device *phydev) +{ + struct dp83867_private *dp83867 = phydev->priv; + struct device *dev = &phydev->mdio.dev; + struct device_node *of_node = dev->of_node; + struct nvmem_cell *cell; + u8 *buf, val; + int ret; + + cell = of_nvmem_cell_get(of_node, "io_impedance_ctrl"); + if (IS_ERR(cell)) { + ret = PTR_ERR(cell); + if (ret != -ENOENT) + return phydev_err_probe(phydev, ret, + "failed to get nvmem cell io_impedance_ctrl\n"); + + /* If no nvmem cell, check for the boolean properties. */ + if (of_property_read_bool(of_node, "ti,max-output-impedance")) + dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; + else if (of_property_read_bool(of_node, "ti,min-output-impedance")) + dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; + else + dp83867->io_impedance = -1; /* leave at default */ + + return 0; + } + + buf = nvmem_cell_read(cell, NULL); + nvmem_cell_put(cell); + + if (IS_ERR(buf)) + return PTR_ERR(buf); + + val = *buf; + kfree(buf); + + if ((val & DP83867_IO_MUX_CFG_IO_IMPEDANCE_MASK) != val) { + phydev_err(phydev, "nvmem cell 'io_impedance_ctrl' contents out of range\n"); + return -ERANGE; + } + dp83867->io_impedance = val; + + return 0; +} + static int dp83867_of_init(struct phy_device *phydev) { struct dp83867_private *dp83867 = phydev->priv; @@ -548,12 +594,9 @@ static int dp83867_of_init(struct phy_device *phydev) } } - if (of_property_read_bool(of_node, "ti,max-output-impedance")) - dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; - else if (of_property_read_bool(of_node, "ti,min-output-impedance")) - dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; - else - dp83867->io_impedance = -1; /* leave at default */ + ret = dp83867_of_init_io_impedance(phydev); + if (ret) + return ret; dp83867->rxctrl_strap_quirk = of_property_read_bool(of_node, "ti,dp83867-rxctrl-strap-quirk"); -- 2.31.1