Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp851942iof; Mon, 6 Jun 2022 13:51:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwhva3CcOTNkSH1yBkwvcBl2cXSIkRCLNu+Sm6C2dk330d0nTNEsI0Odx8GJ7G8APmS0ER X-Received: by 2002:a17:902:70c1:b0:163:5a8f:9df9 with SMTP id l1-20020a17090270c100b001635a8f9df9mr25867626plt.9.1654548681568; Mon, 06 Jun 2022 13:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654548681; cv=none; d=google.com; s=arc-20160816; b=bE8xDtdO3iE8HLSluprmiIM0R0a8VjSM2NwB1myinzH9kJkiVY6lbQBCnKwdDgBzQb LoqL1wxLVgZG18NKzkkiNGIYEJ9uZkCs14oG2Ie44ajR+AowhAhPNhQXVx706s6adzFL n6KPDKgZcUc87bbDFYSlQiug0lKTP9S+/l4CPYp8f1O08BlGWAz+GHcTlkZSqoAbWATm ed9N6taN8uNlv1YIOGF38D2cfdPufTSSH0DOobtuKe97VbJJkTw3U83RUvcYZ7vAXFNP 1VkMOHDuIEpoz8A/ytSynuWow8ly4iNMLeuNGcFV9e1nLk5Aenp9wbeZGLu7hz/o4UVH n7tQ== 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=ZLFWBi94Z5gc30hakoYtYKVO85pJ6YyZy45VIC3fhaKECa2wzsAWClBiXQTemNckVb KCwJWBDKbVA/aLcVu9BMnWVTDA2phZTsNwOkvZN6HhtgoCHtU/z6Bi81QuRoNxHo+Zov xUX+zGoOeZZJREFwf1uFBuQ42Trk9tjSEvBCmxi533gYQ0kxqJLq3EWk/pMQBesUBcyA MFuXYK64V0qTG2PqcB5peiwMsdEGqKyELN/i+th6TVpOcCYSmRNZy4pN8ebcuNhVaIqN amJ+RbfdC2zNARhUUOduNeYMDUDd+Vvpe6VafhIO8oKutglefF0Gu1EmQlpz2u9rwt9F cKqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=fyyHVyXB; 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 z15-20020a170902cccf00b00163c52336fbsi4919894ple.369.2022.06.06.13.51.06; Mon, 06 Jun 2022 13:51:21 -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=fyyHVyXB; 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 S233362AbiFFUWw (ORCPT + 99 others); Mon, 6 Jun 2022 16:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233375AbiFFUWe (ORCPT ); Mon, 6 Jun 2022 16:22:34 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 190D4DF5 for ; Mon, 6 Jun 2022 13:22:33 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id x62so20296242ede.10 for ; Mon, 06 Jun 2022 13:22:33 -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=fyyHVyXBohzxlEcKJtNBA0J4PW/3kKJlkInCdkTTIOy0hCUdbc6wQLZdjnNKUKDiUq neoo5gxyaB/TmYq+WyXdo11Lh+xPQSr0h4H538Rs10wdiiPnzjFKnZTh4rqsHC9OK6fy P9bCMhASV6zjcr0aeBlMdsn52n2/CZv6gfwXw= 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=gWW2VvNlTBrZGMauQH7jSuro7CWbsGr9xrE5i6tgyKaIeFfSv8b1WiVeYQLfopVJs4 pHDZR+fCbGtDWJ3vVaaLl9WWsAUXY9JtyKPYHZnZgVdS97Aao0lbu5IEFAdyHGq5YWTy LGVKCe2haPMdKk8Z56H74podydMhx9ss5nUv+8w7I/dWNCCxEk7bT0CJngHtGsXoHTKl dQiKfWnDrff6PbvPdgbPaknvjMVY9qsZuKk47ErMzh+vz7AVLIzoEZKhwKkEh2XwmkpK 21Q1XqB4gafGSr6/T3zAorhm2zV8kJsmVHnLBrezbNlsZ11hH/jFqYpEmPEuNhFMD6Df ZS2w== X-Gm-Message-State: AOAM532c8M4b8fagCsAD/fDIjcpv35RaA35RCaVwlMRw17Bgtac/vTgI xLP8t/F9ptljPZFGmkR1SX508g== X-Received: by 2002:a05:6402:4003:b0:42d:fb4d:dada with SMTP id d3-20020a056402400300b0042dfb4ddadamr29129905eda.183.1654546951582; Mon, 06 Jun 2022 13:22:31 -0700 (PDT) Received: from prevas-ravi.tritech.se ([80.208.64.233]) by smtp.gmail.com with ESMTPSA id d20-20020aa7ce14000000b0042dd4ccccf5sm9043789edv.82.2022.06.06.13.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 13:22:31 -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" , Dan Murphy , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/3] net: phy: dp83867: implement support for io_impedance_ctrl nvmem cell Date: Mon, 6 Jun 2022 22:22:20 +0200 Message-Id: <20220606202220.1670714-4-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220606202220.1670714-1-linux@rasmusvillemoes.dk> References: <20220606202220.1670714-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=unavailable 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