Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp640213imb; Fri, 1 Mar 2019 09:57:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IbLJ1m5uuyTrXs1pkqeMugdgpGXpDrshFqiMzZSOdhI32y9FJxVhw0D3H1+gUzujRYW9x4Q X-Received: by 2002:a62:bd17:: with SMTP id a23mr6650357pff.233.1551463043838; Fri, 01 Mar 2019 09:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551463043; cv=none; d=google.com; s=arc-20160816; b=eGRCTdA5yb21ChHxciWEo3ffvZtQSrcKf83ujmUimEwxIT8//QOyJHBFtMkBLqgRoQ /C64Jst7DM6FJfpDw3++SQwyFeYPuxdgCEzQ7aRBB1K7ihjXbhbNL2hmBBVscsTZyknY 1eqfse6ZjN7OhLgxgyR31OmV2j6lPHQE+tK+RQ9noCpJbOdYs3kNntepcAR62wKao5dV wTmVCYAbhMCNPOHN+Hv9WWvtS/hT9aRvu9i51fmdwEiX0A9VsvXA1jFRnIxySvXy2Klp p7Wd6ibK6KemwG5VU5uy3EHPVaNM4SiOgVlq1Nx27dai9fyf4CZ4r0QCfymGtjthJLHs cDFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jvpAI1GcXq8PLJ0rfrk/9lBgootey+psldD0iwOt4Pw=; b=pbM6ppcFa+3FmsIOVTy5iLcayIgT/S5EJqR668tuh3hXyUF0umC0NeXWak6TFTSjT1 YzW53t1QZkITLjgOV4ifjDIjNhvldImozYJJfHTSMKrX9QVMM7calqqAXTKnsjkll2EK S2NpaL17ffkg2va85zwccWi3PSHMveCZStL8lzXFrriczcz6XFEGhhcMw2yx+8weGyf/ DoTsrXoQ4ic5wbZ4ou4J+mMmXHLj+MxUj7qjv7OmIXOFqJap3TfDwMcqEgpPj9jg9E1S AB6mkWkYcDCRGRRueTvBUlvp33VDtYoyLTf7pjuB7LedOBhCDll5MK2QRUAdsd0aOI5Y tN4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aGPYReni; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a90si20862376plc.314.2019.03.01.09.57.08; Fri, 01 Mar 2019 09:57:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aGPYReni; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389257AbfCAQyN (ORCPT + 99 others); Fri, 1 Mar 2019 11:54:13 -0500 Received: from mail-ua1-f67.google.com ([209.85.222.67]:33245 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389088AbfCAQyN (ORCPT ); Fri, 1 Mar 2019 11:54:13 -0500 Received: by mail-ua1-f67.google.com with SMTP id q17so23109681uam.0 for ; Fri, 01 Mar 2019 08:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jvpAI1GcXq8PLJ0rfrk/9lBgootey+psldD0iwOt4Pw=; b=aGPYReniyqoW65SIjJD4XKrK4Z15t4pWNomQ/U7Ker0W4fnb5/w/HvjRlbRbscmPtv Rd3eTIKXi7c5jhetN3GIdpwHmqZFAwWICObJW2hku+vRh7aRE2sQHkJ21DTHxKTCMg+K yV13dhTwaOPK3jQZNyoON0D4lhYoFWmI8sh9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jvpAI1GcXq8PLJ0rfrk/9lBgootey+psldD0iwOt4Pw=; b=MLO784uZBM7m8Jzws/F3G9zAX2XWZ1jp95q3mz9G3ZiRDfm6iW5vi7xUJY0GCe5PX+ Z0HJnHHrOnTN/SftJIM+kytdnNFHaGpp7JPlpZb3Hxq7+h+IBuPAm3b+67c41jkGOMen 2GLtqa53CGWluxSIuR+G2CgfwEyYnCiq9D5Ja3i8EAjAMvqsYPVGv79Yk4eJFiOlenF8 gaErZ0TnNVEb4orZop8Rhu41vJUnFbFrKhHNckJknis8qYz07c+w6VRBeNNQTpeEKlud IEaCtE/Czk8v8A8/HXXmN2yjMbhOosYiYblPILUJ9R7RNOSuX0ho4GzAtF4o1r8n+BkN inMw== X-Gm-Message-State: APjAAAXXICprOUPQXX2tEFkZ5PExBEqg+OXPN57WIzv/CexKbiHkq+bA gDsffA6k34cd8+FYNM+sT125aTz8Kv0= X-Received: by 2002:a67:7f07:: with SMTP id a7mr2997131vsd.196.1551459251878; Fri, 01 Mar 2019 08:54:11 -0800 (PST) Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com. [209.85.222.50]) by smtp.gmail.com with ESMTPSA id l14sm13951468vke.54.2019.03.01.08.54.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 08:54:11 -0800 (PST) Received: by mail-ua1-f50.google.com with SMTP id e15so21935944uam.3 for ; Fri, 01 Mar 2019 08:54:11 -0800 (PST) X-Received: by 2002:a67:dc92:: with SMTP id g18mr3158769vsk.144.1551458948569; Fri, 01 Mar 2019 08:49:08 -0800 (PST) MIME-Version: 1.0 References: <20190301153348.29870-1-christoph.muellner@theobroma-systems.com> In-Reply-To: <20190301153348.29870-1-christoph.muellner@theobroma-systems.com> From: Doug Anderson Date: Fri, 1 Mar 2019 08:48:56 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] phy: rockchip-emmc: Allow to set drive impedance via DTS. To: Christoph Muellner Cc: Rob Herring , Mark Rutland , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Shawn Lin , Philipp Tomsich , Kishon Vijay Abraham I , Enric Balletbo i Serra , Klaus Goger , Viresh Kumar , Matthias Brugger , Emil Renner Berthing , Tony Xie , Randy Li , Vicente Bergas , Ezequiel Garcia , devicetree@vger.kernel.org, Linux ARM , "open list:ARM/Rockchip SoC..." , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Mar 1, 2019 at 7:37 AM Christoph Muellner wrote: > > The rockchip-emmc PHY can be configured with different > drive impedance values. Currenlty a value of 50 Ohm is > hard coded into the driver. > > This patch introduces the DTS property 'drive-impedance-ohm' > for the rockchip-emmc phy node, which uses the value from the DTS > to setup the drive impedance accordingly. > > Signed-off-by: Christoph Muellner > Signed-off-by: Philipp Tomsich > --- > drivers/phy/rockchip/phy-rockchip-emmc.c | 38 ++++++++++++++++++++++++++++++-- > 1 file changed, 36 insertions(+), 2 deletions(-) > > diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c b/drivers/phy/rockchip/phy-rockchip-emmc.c > index 19bf84f0bc67..5413fa73dd45 100644 > --- a/drivers/phy/rockchip/phy-rockchip-emmc.c > +++ b/drivers/phy/rockchip/phy-rockchip-emmc.c > @@ -87,6 +87,7 @@ struct rockchip_emmc_phy { > unsigned int reg_offset; > struct regmap *reg_base; > struct clk *emmcclk; > + unsigned int drive_impedance; > }; > > static int rockchip_emmc_phy_power(struct phy *phy, bool on_off) > @@ -281,10 +282,10 @@ static int rockchip_emmc_phy_power_on(struct phy *phy) > { > struct rockchip_emmc_phy *rk_phy = phy_get_drvdata(phy); > > - /* Drive impedance: 50 Ohm */ > + /* Drive impedance: from DTS */ > regmap_write(rk_phy->reg_base, > rk_phy->reg_offset + GRF_EMMCPHY_CON6, > - HIWORD_UPDATE(PHYCTRL_DR_50OHM, > + HIWORD_UPDATE(rk_phy->drive_impedance, > PHYCTRL_DR_MASK, > PHYCTRL_DR_SHIFT)); > > @@ -314,6 +315,28 @@ static const struct phy_ops ops = { > .owner = THIS_MODULE, > }; > > +static u32 convert_drive_impedance_ohm(struct platform_device *pdev, u32 dr_ohm) > +{ > + switch (dr_ohm) { > + case 100: > + return PHYCTRL_DR_100OHM; > + case 66: > + return PHYCTRL_DR_66OHM; > + case 50: > + return PHYCTRL_DR_50OHM; > + case 40: > + return PHYCTRL_DR_40OHM; > + case 33: > + return PHYCTRL_DR_33OHM; > + } > + > + dev_warn(&pdev->dev, > + "Invalid value %u for drive-impedance-ohm. " > + "Falling back to 50 Ohm.\n", > + dr_ohm); > + return PHYCTRL_DR_50OHM; > +} > + > static int rockchip_emmc_phy_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -322,6 +345,7 @@ static int rockchip_emmc_phy_probe(struct platform_device *pdev) > struct phy_provider *phy_provider; > struct regmap *grf; > unsigned int reg_offset; > + u32 val; > > if (!dev->parent || !dev->parent->of_node) > return -ENODEV; > @@ -345,6 +369,16 @@ static int rockchip_emmc_phy_probe(struct platform_device *pdev) > rk_phy->reg_offset = reg_offset; > rk_phy->reg_base = grf; > > + if (of_property_read_u32(dev->of_node, "drive-impedance-ohm", &val)) { > + dev_info(dev, > + "Missing drive-impedance-ohm property in node %s " > + "Falling back to 50 Ohm.\n", > + dev->of_node->name); This is awfully noisy for something that pretty much all existing boards will run. debug level instead of info level? Also: * Don't split strings across lines * There's a magic % thing to get the name of an OF node. Use that. > + rk_phy->drive_impedance = PHYCTRL_DR_50OHM; > + } else { > + rk_phy->drive_impedance = convert_drive_impedance_ohm(pdev, val); > + } It's been a long time since I looked at this, but I could have sworn that it was more complicated than that. Specifically I though you were supposed to query the eMMC card for what it supported and then resolve that with what the host could support. Assuming that this is supposed to be queried from the card (which is how I remember it) then you definitely don't want it in the device tree since you want to be able to stuff various different eMMC parts and we should be able to figure out the impedance at runtime. NOTE: IIRC the old value of 50 ohms is required to be supported by all hosts and cards and is specified to be the default. I do see at least the summary of what I thought of this before at (Sorry if the above is wrong and feel free to correct me--I don't have time at the moment to do all the full research but hopefully you can dig more based on my pointers. Feel free to call me on my BS) -Doug