Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp562084imb; Fri, 1 Mar 2019 07:56:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IatopO/shGznkZJGBvcKFXSaqZGpwgEuIitAU0FNJW/T7jxi/SNNYGMASvYI+yZ/t3GYVPn X-Received: by 2002:a62:3990:: with SMTP id u16mr6234261pfj.80.1551455819528; Fri, 01 Mar 2019 07:56:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551455819; cv=none; d=google.com; s=arc-20160816; b=fBHOUc7TiiG1vdYOcRRmaz2oqPedLxxY/oPDgtckckNFyP4G+fr5UcnP/Caklfbfjr 5+6jbmdCMPa8gNulK80jAtN3Y/rzGucLjAzU2SYK/gunJb0pJ86UEuNiaMJnkYcAdXhH 2+WF/uoAbWjdfqiS0B9K61RAlPtJ2Quo9Wdx7BpTF2mivbRG8kJ43Zg8aR/BbGkuGAzC mNs0+4HGEU4vOBg8EHch/hNrqWMrbqxcsedY76Se9Q3GkLE0mhdABOqJodJnlQ8jF879 YQ4bNbv1VjV3pUGla6CnSJudq5SlRLmskkxIzteJCh9JiDqKtqhKk3H+4PFCbLQLb5PX CFJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=TOde+GZKxwd366vn/494fce+I68kRiP4+P6M8DP9n3Y=; b=IdT+uQ344cOOcdLsw3s5mrxKRC9BrFZM5Y09KOFDozVTgFQvHe+xCCb+YhSMWi8GyW oeTOnmtMHYnU6XSv7ZsHBqPGNv6E3oQF7Tl6BBl/fZei3/avksye3NmHXoMFJ8Ej4yCV WzjdSsm3wYGq1yNNTy5JhWPMUhjClgsGosr+eyyv4FhCgXRezcuan1pMEe3VjftQcO2y M+2VH7aRz3QO4pTOkkU+1Mzs3K5LH4+51jo6+6o6W07GQlJPzEFJemzGreWrhc3/eDhZ 2pd9TjrjF5/RfYeaoqZ9J2GeiGqYmy/xlrR6K4hCcxP+x3mN4aNsskZ0CYXoCc/PrYgD oWCA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si21021435plb.289.2019.03.01.07.56.44; Fri, 01 Mar 2019 07:56:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388625AbfCAP4T (ORCPT + 99 others); Fri, 1 Mar 2019 10:56:19 -0500 Received: from vegas.theobroma-systems.com ([144.76.126.164]:60015 "EHLO mail.theobroma-systems.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728331AbfCAP4T (ORCPT ); Fri, 1 Mar 2019 10:56:19 -0500 X-Greylist: delayed 1148 seconds by postgrey-1.27 at vger.kernel.org; Fri, 01 Mar 2019 10:56:18 EST Received: from ip092042140082.rev.nessus.at ([92.42.140.82]:42682 helo=purcell.lan) by mail.theobroma-systems.com with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1gzkDW-0005Ag-JD; Fri, 01 Mar 2019 16:36:54 +0100 From: Christoph Muellner To: robh+dt@kernel.org, mark.rutland@arm.com, heiko@sntech.de, shawn.lin@rock-chips.com Cc: Christoph Muellner , Philipp Tomsich , Kishon Vijay Abraham I , Enric Balletbo i Serra , Klaus Goger , Douglas Anderson , Viresh Kumar , Matthias Brugger , Emil Renner Berthing , Tony Xie , Randy Li , Vicente Bergas , Ezequiel Garcia , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] phy: rockchip-emmc: Allow to set drive impedance via DTS. Date: Fri, 1 Mar 2019 16:33:43 +0100 Message-Id: <20190301153348.29870-1-christoph.muellner@theobroma-systems.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + rk_phy->drive_impedance = PHYCTRL_DR_50OHM; + } else { + rk_phy->drive_impedance = convert_drive_impedance_ohm(pdev, val); + } + generic_phy = devm_phy_create(dev, dev->of_node, &ops); if (IS_ERR(generic_phy)) { dev_err(dev, "failed to create PHY\n"); -- 2.11.0