From patchwork Sat May 9 16:56:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1159 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id DB23E3F08E for ; Sat, 9 May 2020 18:56:43 +0200 (CEST) Received: by mail-pl1-f197.google.com with SMTP id f3sf4157052plo.14 for ; Sat, 09 May 2020 09:56:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043402; cv=pass; d=google.com; s=arc-20160816; b=Cv38q+WVW8SSbaiFLMgd9A6TbJviV/FHFmXuvBh2uk8dhXFo+jHfAkStV/Yas+fiMB JXD+LJQYluqSkRrnOUE5X1CwsmK+B50nbywEibqPA33LRAWDbVNiTDjajTswH+LtcPip LE0aoVnTQlLK3O+0E4RW/3i2J3wz6M9zfjKyjI7m8XVgZvGfYzywfCW+2l67L5H2JaFF CbeXrYucHEq9HaUU+b04eltsrY8PArqWd4RirR7ZTh4LQO8Oqb3ErPBfz7FMbtpIw/Vs J7IO8UFwephDlp4TWoWhzwbsnibJBDBzkQ9qRNndxjUGeAo3N9ysLVsaCU+oQTx+fZgl 9qkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=BuT5FY+5+B8iqDVqh6vDieMm+1QMcQLzkOtj7uvG1SE=; b=pIOSvFodzsiZOu9CEwqe9YSDHEbfMNIUrUhr0tk52IXlpDX/nQvdbu0+MlV9PrlBFQ tcNJavUTUBoBGsV6SqUplRADnSRcf/LCzceflUsRrNTTH9bl6FP6jda5uv1pQzGQax/W 96yfLoxxZZvpdnYerVf9W/AYJ6T8Ere1xe4J9fqVPJRWIzoCHVugGh2fd12Te7aVd2v7 Glx6MHK9gzNzCGWwtsEXbMVwNtS8r27ORfTmKwgG3Lid2T/ZVVi0yvWJ+J+X9O52wpCK 3VOyAtoG8UCmyKr9+066Rux6KXR3IBar15hCANM6A9Sspw2sveSKOHvU90hMFVsY+MlT XCDQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HDXyMRp2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=BuT5FY+5+B8iqDVqh6vDieMm+1QMcQLzkOtj7uvG1SE=; b=CnFhb+SWyOAILgKSgsWnr9K4z8rDVXEbwLAUJxklnz4PsiLkOaHL7KyUr9g4ZjP2s+ t4VhuPZsffiSEuuRZvKwp84ksUvTbuGceFOSTibDDJdse337dQ66UqqmfWbt5IpP9e8y Cqbc01uL2L5jCZUxsJValYciGeO5KNNF7p2tY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=BuT5FY+5+B8iqDVqh6vDieMm+1QMcQLzkOtj7uvG1SE=; b=aNVCPJBJDQ8JQ2POgNb5dPbIQ6Kx3eBiaYvlWst7jRFX43sxHWpgyi8kg/IkL3a/Ib f9rpuV419Gk081fOZZyupLjxwsXWdsGFmPe7pL+UNPWcBqGDumjLrHjYZNK4DiYV9yDI X6WjzDhFsiFfwmKk0A//umrIgl5kH6Oo/DGuxLXPYI2O5yTBm1UMqlYGjkr0y8AFlwmO NYtAYjAPiZIo8I/dQI/AgOp7SkpcnrHDzvLvV1OMJU9RL7+xjW8C/jDsJ9x4PnXdemEO 5Px/kU9vHO5lPhDinwM04/xTc3rSFilf3LxiEJkOELV31B5MyjezK/FjZazToYKejx5c butA== X-Gm-Message-State: AGi0PuYuXOoBhTW5aguwe90PHmFcP5CbWCrROGG4HiiD5/ZyOQ2iyLpe 4IdGkM/CYyqKgjRADlzKdB4pGP0Y X-Google-Smtp-Source: APiQypKLsOP3SuWHdNqMD08GOVVF0ip9fn49pq2R6huiFS29CDahgYLR+CQiufYzgdZpFkep2zBEBg== X-Received: by 2002:a63:1e01:: with SMTP id e1mr7007106pge.351.1589043402669; Sat, 09 May 2020 09:56:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:9289:: with SMTP id o131ls3240950pfd.8.gmail; Sat, 09 May 2020 09:56:42 -0700 (PDT) X-Received: by 2002:a63:1961:: with SMTP id 33mr7336499pgz.282.1589043402112; Sat, 09 May 2020 09:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043402; cv=none; d=google.com; s=arc-20160816; b=s4XnZ6J6mAWNNemGnr6/pCH51pfvQJD4yTNgf+vByPaJsshMK3JmhQPP0hwAJrH/xz o4RAJ7ZDmQZNh9EYm5fPNznVp1qwLIVP9+TWXSjvAHuYrXSpD3CwS/7PM7Z/F9oMLLRI 2BUvHSA1bq3svWHBS2OCpYX5Hqpl0K0TvGU/4lCkP+8CRy29UK7udrsfe7bV0XtX5ZlB hrJyRn42p1DUzD859dlwe8e/pS8Wi4cMlqCf6+LCQyi0RWaXoUuaIXQaLgJ/aY+4AwEJ GcBpxAo4v2619dBsQEey7HC3tVabSrKef9Vzv8hvaolTvlwZU5hDOREF/5lSAWm7JYmh iEmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0gK5/3e6XPljp57mBjGreH9T+A8rRJ92BhM6QCBY7t8=; b=NAtoC+jZouVM2OrlO6lKpRA0ZGWWym/bfBoXrlgy8NygYMNIAZ/FhWw4jb4YDqyW1O z4uCv1tplpw7rlAZW0Uu6hAeuw10KL4agzbDBnIEClotgNvVtUhCFU+lWjZwmv/Zpdc4 Iwh7xiHgFnKjPss0KRQ9xk+TX5JpIJovDLB6nT6ZkGqQkseO45cwtZ/P2UUnRw34Rqdn VxBaSPI+aAwfq2Mn8pnzPtiJ/tWOkJp0CkgNicLx0+it+zyZgFhncrWm7e5eN8loeT9q zk8HnPbQIJFgjXXfSIAKrxLjCEPKI6Tj6LskcHflXbXIFermHm3iGDFTn0xJdarr1FcX OXOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HDXyMRp2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i3sor6788402pli.24.2020.05.09.09.56.41 for (Google Transport Security); Sat, 09 May 2020 09:56:41 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:c3d3:: with SMTP id j19mr7433822plj.340.1589043401222; Sat, 09 May 2020 09:56:41 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:56:40 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 1/6] clk: rk3399: Add enable/disable clks Date: Sat, 9 May 2020 22:26:19 +0530 Message-Id: <20200509165624.20791-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HDXyMRp2; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Yes, most of the high speed peripheral clocks in rk3399 enabled by default. But it would be better to handle them via clk enable/disable API for handling proper reset conditions like 'usb reset' over command line. So, enable USB, GMAC clock via enable/disable ops. Signed-off-by: Jagan Teki Tested-by: Suniel Mahesh # roc-rk3399-pc Tested-by: Suniel Mahesh #roc-rk3399-pc Reviewed-by: Kever Yang --- Changes for v3: - Update USB clock registers drivers/clk/rockchip/clk_rk3399.c | 148 ++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/clk/rockchip/clk_rk3399.c b/drivers/clk/rockchip/clk_rk3399.c index d822acace1..5d2bdb42c7 100644 --- a/drivers/clk/rockchip/clk_rk3399.c +++ b/drivers/clk/rockchip/clk_rk3399.c @@ -1071,12 +1071,160 @@ static int __maybe_unused rk3399_clk_set_parent(struct clk *clk, return -ENOENT; } +static int rk3399_clk_enable(struct clk *clk) +{ + struct rk3399_clk_priv *priv = dev_get_priv(clk->dev); + + switch (clk->id) { + case SCLK_MAC: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(5)); + break; + case SCLK_MAC_RX: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(8)); + break; + case SCLK_MAC_TX: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(9)); + break; + case SCLK_MACREF: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(7)); + break; + case SCLK_MACREF_OUT: + rk_clrreg(&priv->cru->clkgate_con[5], BIT(6)); + break; + case ACLK_GMAC: + rk_clrreg(&priv->cru->clkgate_con[32], BIT(0)); + break; + case PCLK_GMAC: + rk_clrreg(&priv->cru->clkgate_con[32], BIT(2)); + break; + case SCLK_USB3OTG0_REF: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(1)); + break; + case SCLK_USB3OTG1_REF: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(2)); + break; + case SCLK_USB3OTG0_SUSPEND: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(3)); + break; + case SCLK_USB3OTG1_SUSPEND: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(4)); + break; + case ACLK_USB3OTG0: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(1)); + break; + case ACLK_USB3OTG1: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(2)); + break; + case ACLK_USB3_RKSOC_AXI_PERF: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(3)); + break; + case ACLK_USB3: + rk_clrreg(&priv->cru->clkgate_con[12], BIT(0)); + break; + case ACLK_USB3_GRF: + rk_clrreg(&priv->cru->clkgate_con[30], BIT(4)); + break; + case HCLK_HOST0: + rk_clrreg(&priv->cru->clksel_con[20], BIT(5)); + break; + case HCLK_HOST0_ARB: + rk_clrreg(&priv->cru->clksel_con[20], BIT(6)); + break; + case HCLK_HOST1: + rk_clrreg(&priv->cru->clksel_con[20], BIT(7)); + break; + case HCLK_HOST1_ARB: + rk_clrreg(&priv->cru->clksel_con[20], BIT(8)); + break; + default: + debug("%s: unsupported clk %ld\n", __func__, clk->id); + return -ENOENT; + } + + return 0; +} + +static int rk3399_clk_disable(struct clk *clk) +{ + struct rk3399_clk_priv *priv = dev_get_priv(clk->dev); + + switch (clk->id) { + case SCLK_MAC: + rk_setreg(&priv->cru->clkgate_con[5], BIT(5)); + break; + case SCLK_MAC_RX: + rk_setreg(&priv->cru->clkgate_con[5], BIT(8)); + break; + case SCLK_MAC_TX: + rk_setreg(&priv->cru->clkgate_con[5], BIT(9)); + break; + case SCLK_MACREF: + rk_setreg(&priv->cru->clkgate_con[5], BIT(7)); + break; + case SCLK_MACREF_OUT: + rk_setreg(&priv->cru->clkgate_con[5], BIT(6)); + break; + case ACLK_GMAC: + rk_setreg(&priv->cru->clkgate_con[32], BIT(0)); + break; + case PCLK_GMAC: + rk_setreg(&priv->cru->clkgate_con[32], BIT(2)); + break; + case SCLK_USB3OTG0_REF: + rk_setreg(&priv->cru->clkgate_con[12], BIT(1)); + break; + case SCLK_USB3OTG1_REF: + rk_setreg(&priv->cru->clkgate_con[12], BIT(2)); + break; + case SCLK_USB3OTG0_SUSPEND: + rk_setreg(&priv->cru->clkgate_con[12], BIT(3)); + break; + case SCLK_USB3OTG1_SUSPEND: + rk_setreg(&priv->cru->clkgate_con[12], BIT(4)); + break; + case ACLK_USB3OTG0: + rk_setreg(&priv->cru->clkgate_con[30], BIT(1)); + break; + case ACLK_USB3OTG1: + rk_setreg(&priv->cru->clkgate_con[30], BIT(2)); + break; + case ACLK_USB3_RKSOC_AXI_PERF: + rk_setreg(&priv->cru->clkgate_con[30], BIT(3)); + break; + case ACLK_USB3: + rk_setreg(&priv->cru->clkgate_con[12], BIT(0)); + break; + case ACLK_USB3_GRF: + rk_setreg(&priv->cru->clkgate_con[30], BIT(4)); + break; + case HCLK_HOST0: + rk_setreg(&priv->cru->clksel_con[20], BIT(5)); + break; + case HCLK_HOST0_ARB: + rk_setreg(&priv->cru->clksel_con[20], BIT(6)); + break; + case HCLK_HOST1: + rk_setreg(&priv->cru->clksel_con[20], BIT(7)); + break; + case HCLK_HOST1_ARB: + rk_setreg(&priv->cru->clksel_con[20], BIT(8)); + break; + default: + debug("%s: unsupported clk %ld\n", __func__, clk->id); + return -ENOENT; + } + + return 0; +} + static struct clk_ops rk3399_clk_ops = { .get_rate = rk3399_clk_get_rate, .set_rate = rk3399_clk_set_rate, #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) .set_parent = rk3399_clk_set_parent, #endif + .enable = rk3399_clk_enable, + .disable = rk3399_clk_disable, }; #ifdef CONFIG_SPL_BUILD From patchwork Sat May 9 16:56:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1160 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 084C13F08E for ; Sat, 9 May 2020 18:56:47 +0200 (CEST) Received: by mail-pl1-f197.google.com with SMTP id m2sf4136908plt.17 for ; Sat, 09 May 2020 09:56:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043406; cv=pass; d=google.com; s=arc-20160816; b=OpKb0wB2Qygl7Gv6CZ++vBkC7jgvSjMR0cJEQ7LF4F4cv7vQLAs5HMb5E8CfKZ5HK0 SthECevH0eFBO5/VCD8MPAT7jAgx14l5bnGFKhYQ+XJCbXOrzfJ/jK4jCa5bsobs3ODR 01iP22nTFCAiT8frDTpTYFFngfE+yQCXHzj00EalDNoIIS0/4Oea4DMJnijT9FaxhuqI D2ARR26qubdL14F7YadRb14ml316FWzEGdm8pEVOa+mYyJozmK8DfAHm/fX99RiSvfRn bQu1GaNT3Iod92wdiCadn4C+ZT1YOPm6IjeoLzKfMktw4/zDuTjSohThcML19UAuZuuF s6Fg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=PMTK6OBovrE6e53DwxhFMpSdKWfI1uz8UVXKd8ToSeo=; b=IRcTcslDUIbMGWzaQulNNBArtXJ/Imc8FyLLEr7dNGpEB2tfpxRzLB0e+V1MpLIAxj dGMRu8RwkSjz5eFfYAz7By/SshU5EEoVF8xIlgi5Ye/B6rZKidlbQFWNKDaVwGV+aRLJ hxyQU9HCH/O3Y4rcSy9a3vpGeeFePYCq5U3i66Lyv5stYC4O9/ryR88t6/rV4RxE3smt M34oXFl+mtwwMbAUlwLyWhrNiifYfO0LUDkBZpSXF15hNhrWCoXByDXh5EQn/h5sGfYD N0vk1jjsC5VXhqxU+yqnmnxyHvp61jvLG3IVwMnvorxP+sCoAhYEcFXtuWPZqOy06suw 4Ovg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GWxkFV07; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=PMTK6OBovrE6e53DwxhFMpSdKWfI1uz8UVXKd8ToSeo=; b=lpJN4uGSSp9aoap4x7OjcPmeKuGPY8K8DjvklIjS9LATCjE4K2MxqAfajw464LKvR3 sgvORAYMp9+aG7Z9xZGQWjRFF9TAIgW4x8/sWSPuZ7h3AU1grofEckN+4MiUg2uBechs +mHmCc3iQm9x3f+xlpKKePnYCZS0RTxYynSgY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=PMTK6OBovrE6e53DwxhFMpSdKWfI1uz8UVXKd8ToSeo=; b=fK0QznEvOH7V9TOdGaM/58DLTGA/uiihnaa2QeIQdDZqFiAzU+cIftDzzA6cRLewZH S5YMKidoSP85kumAug7Z6SPXZ4rO24kJf1WHDYjNOmxQVlcMY7oA9SWWPJLU7dsFwFHV X9m7YHdNn782pX1nXw4pK1WRbh6Sysg3oAeVZ6woNJGulB7n93aqRjzrLbx6YExh9dkM GN3LBztVCRgkzyhP+tfYRd2bhDqnnAQb9ncSXNsAaa1fLW14U6/PrKJG+Qvlx4SpPF5C 8CkeEhsaZBWcQlfxQqtksDt81PVMXdmmuE7RZYop3+56GcB8sqfJQQaLbQWTTtUxXpXm XHrw== X-Gm-Message-State: AGi0PubV45jWyT27lkwDHbDI+xLlkBdGXaeFBdCqZjqHFmehtIgj69ZB l/dSOjN+JHMq5Wr1RWbJO+2sSbIr X-Google-Smtp-Source: APiQypJhFSJdpASDWs5pmoVk06pG2C4B59vakkdAh5QEFPMqovjAmlpxcAKwSwRypSFpgfB3LULVCA== X-Received: by 2002:a63:f610:: with SMTP id m16mr7122862pgh.174.1589043405862; Sat, 09 May 2020 09:56:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:9289:: with SMTP id o131ls3240973pfd.8.gmail; Sat, 09 May 2020 09:56:45 -0700 (PDT) X-Received: by 2002:a63:1854:: with SMTP id 20mr7487540pgy.257.1589043405375; Sat, 09 May 2020 09:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043405; cv=none; d=google.com; s=arc-20160816; b=QhXMyc3Lbcbg0yntVwmz7976WjKGAZH9w/cdn+dOAZsJ9osQkUSdwWBzaA+VXqbKU/ RJFOZR0OK3Vj28B/c0tqhSt/p0RKLZMlg6MR5Mc2PmYojATkIE25E+8uEDYnQWO+FCe5 bNABwchQ5fJEEGimcgGvEaj5g/8ojy0RrAA1oqOSxwVi2UA5BIlI7KOBLeS+1OoR2s/a ZqHx0wX28wrDYCD4dcr3cTKl8bGCyZGSo7bRrWVqWOVbq65HvBXF4GkcGLKGQdWa5fyW bdV7adeN5n1F1MWCproC653dOHFNqk/SZeL64E0UpGNkm80XFhYMZxQGNpgBWvAK1E4x PZ2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bWXJOIJ9kTWujVzUlzTOv5wHMWkvOTqjzDzKMEva7i0=; b=Hpqlj4KQM9z1lTSAl5hbHJgSWw4yVCWAOjQNH0DqbCzhPnz/07m+T9uaS5cG16N47F bkVWiuvOo78T6ETa2poL2kPfVaS/nfPuNl+ky4GkPMdaawgT2KZqTQDB9a4k2cSiyeGx 7/c3v1vK/BFbZ9ImV6s+m/TKFA0bLndHuryX7bWXlo1g3P/VSj9DLJrvR53jXo2AngGZ SnsVt7MmsFnbR9BP3ggcfefegBt39sc+uN/Hy0Msw4K6rU2eSQVvhvD2ZzZs+2MyBHDR B/ZFd/DaEhbqLc8F0uPgv4n7V+g2BKOGOm9xdsqO4OBDGAnci8KublObXod27jJsZr/A STkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GWxkFV07; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p9sor6796206plq.52.2020.05.09.09.56.45 for (Google Transport Security); Sat, 09 May 2020 09:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:7289:: with SMTP id d9mr7908776pll.147.1589043405091; Sat, 09 May 2020 09:56:45 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:56:44 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 2/6] clk: rk3399: Enable/Disable the PCIEPHY clk Date: Sat, 9 May 2020 22:26:20 +0530 Message-Id: <20200509165624.20791-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GWxkFV07; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Enable/Disable the PCIEPHY clk for rk3399. CLK is clear in both enable and disable functionality. Signed-off-by: Jagan Teki Tested-by: Suniel Mahesh #roc-rk3399-pc Reviewed-by: Kever Yang --- Changes for v3: - none drivers/clk/rockchip/clk_rk3399.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/clk/rockchip/clk_rk3399.c b/drivers/clk/rockchip/clk_rk3399.c index 5d2bdb42c7..5fb72d83c2 100644 --- a/drivers/clk/rockchip/clk_rk3399.c +++ b/drivers/clk/rockchip/clk_rk3399.c @@ -1136,6 +1136,9 @@ static int rk3399_clk_enable(struct clk *clk) case HCLK_HOST1_ARB: rk_clrreg(&priv->cru->clksel_con[20], BIT(8)); break; + case SCLK_PCIEPHY_REF: + rk_clrreg(&priv->cru->clksel_con[18], BIT(10)); + break; default: debug("%s: unsupported clk %ld\n", __func__, clk->id); return -ENOENT; @@ -1209,6 +1212,9 @@ static int rk3399_clk_disable(struct clk *clk) case HCLK_HOST1_ARB: rk_setreg(&priv->cru->clksel_con[20], BIT(8)); break; + case SCLK_PCIEPHY_REF: + rk_clrreg(&priv->cru->clksel_con[18], BIT(10)); + break; default: debug("%s: unsupported clk %ld\n", __func__, clk->id); return -ENOENT; From patchwork Sat May 9 16:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1161 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C86D73F08E for ; Sat, 9 May 2020 18:56:51 +0200 (CEST) Received: by mail-pl1-f200.google.com with SMTP id m2sf4137004plt.17 for ; Sat, 09 May 2020 09:56:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043410; cv=pass; d=google.com; s=arc-20160816; b=XlY6d6pbVSvY1Rj5wgOVbhSzwldfbViRFTiWfZTXyyJtEUuxOixBnvwO91vzxuFe8X U1x9vorEbnmPHsWhQWZlaR98QrkTM7bXVeJScj4vjhGo49BPrOUzLuBHqIYZRRItZius 8Y3i/GKchrkfkIJoEALL7rgauKzQzB3x2ZHGGhkA2GmVsnC512195JPnMbJi6cAsUe/2 rZfEZ3C9p6ZLIzGczddk/ae8gBc/dzqMWP+POhU2EbemGRCC8PE3nNj9AEkpdPiQqo0C +9+AL77fPY4Z3kFPuXXQeqrslCCAhdVaKq9wWWHA2umYmVbRao2yhTH6f4AI6m/qmZMY sQ4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=HHitpRhq0NyvdJtdWO/hSUWk+EH13OCAcAWSZCErsRg=; b=siqHDJdMLDJ5uZHBpmaGGm/5PuqknrkPAeDlkstPlTJdF9vL532Y9XKx8LAgjAaywd 4/G9bQEce5bNFNcVvu4tA77i3vTbO7Fjw+ZpdTeQa9Kfoud10VoJCtT7wUMLbbDIWIS7 p9ATXbIXg+Efq62wKtqJz7nAIadOoKLOnqPGMol0qpDZgFOIO6MKLCjfheKWNs8OT0PL 7ZCQoAc+3gmLlfjpyXrVjS36cQQKuMZR+tp1tR0WL1S8yV8OuFi/TFWyeSIZDUoEaGm1 YQUXb+F9rUBny51mF8NwKclaxytyUsMjum6deEAGxUtuNjuaeCgxqKFqFMWG7SCbOJWt 0C5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dWaDiG10; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=HHitpRhq0NyvdJtdWO/hSUWk+EH13OCAcAWSZCErsRg=; b=opMNR8BblHke3k8my4PzY7BX4cigFVpFfhrq//xEeNTKwCMoOTTdhJ/TJx4aTo2L7X oC7vlxcGnYm8wg7mHMlfJOrc//Y1sf3qpvstxGQmQJm52igyzTycZ8u2FgBjeHjzD0xt JnKnJTKcl8hl37WrYYCRaMhV9+iWeIgD9HR4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=HHitpRhq0NyvdJtdWO/hSUWk+EH13OCAcAWSZCErsRg=; b=c7fpo8GFLa8ojTuITWuf4Wd38APSFMvuApjPbozU1cDUeDPZzyq/lTu8eeFqWxhjMN kD1J/s5Ebb9Z1pATKq5TxEg0+6utVBG535nosMgMgjTeEg9uULLSpNDQrICojnl+TnWo VQG8HHFvpZO3CZp908UtlYwuY5HjK/oCdftRAlBNAJmMhwpxWie4rjAUvYrnvgGkhAaS 8LJyxdqAZhuBfcY1YartOGsfX0YbKDo1j5p1kdbizAGZf8eNCI8AKcRuKtEycYXz2L/T URx8KOWx3AZXn7obmf1dGb4cY4DHmwm8sWuyKejcUv4yR5PJwBnQbsTzJHugaGP7C3Yv +e5A== X-Gm-Message-State: AGi0PuaG7jW/0to5TVKhGUauVjeK0tUFMqr25jCcj9i7IlyT1tFaiAHq +j/Vq1AHHtRNy1omxeAyrDxkPmbL X-Google-Smtp-Source: APiQypK/qXfZbFLOxsnbMdFK9SBrHUQKV1TGNHHXnkJ9bUI/Is+ydy+eBoJM6lkffdoE4pJiPDbn/Q== X-Received: by 2002:a17:90a:8a06:: with SMTP id w6mr12944237pjn.191.1589043410317; Sat, 09 May 2020 09:56:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:780a:: with SMTP id t10ls3293904pfc.1.gmail; Sat, 09 May 2020 09:56:50 -0700 (PDT) X-Received: by 2002:a63:4d5e:: with SMTP id n30mr7195889pgl.154.1589043409747; Sat, 09 May 2020 09:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043409; cv=none; d=google.com; s=arc-20160816; b=sruNbOnJ5QZWY/D+i62ba1LwHa4sHZodWaLkgko2TTpQrBkL5SaBHK+7tbv//7JALK btCwdexxM+iOYNqk8+oHNbW/snZVaGUYKfO4XMAs5NtiPN8hCAtiUaCX92E4TtLWrinQ kOTxx4NqtsF3NqlQCI0btte02dBhytpuH72UNpC5MDLiH5vY6qgLtNJCi9W82rrAl6C8 e/JPgHQ6ZMqK99VAKW/bMmRoqkadHI3etJxmt0DrgTp+StMbfQA1jgqqxSuqvbsoYROV IO5xuK8iuStkoEen2ZXaQB6qe8Lyzz/tupH3WjMIaGVFJug0dgJHSRlsgEdhlq/3mV9c r0Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MHdHHDYJKTAE5VPEB6ubYVNXx6dEp2WebpOoJ6AEFX8=; b=xbPtg4DtU5seMDvropFQLNrCkwBN7c77CKnKsBP6AZHDTXXX+tRD173uMZvYiSAnQf dHKCxQ901QAIvTGuCJMNre8dgWjBvJk+TWSclW/SSxOzNwgr8DKhxww+Dijbro8pPjc/ 0iKER1jyh03+lKeDzB2xRE6BJaXDIaXxRYLFnbp0bNtGDbj01oPiT2hRnVIVnrU07XbZ Q4ECo6E3ZKD1EHm8dAM60fDgVRyF6AmRowXxPgnHnyhMd5ropd1N+SFm84sfKLLaUBCr bZZ8ORRESJenXZxYCo36BNretnVRYYD7g6LPdU47OeyiBkhojECEVDRysMgXK1OQqw4L /ttw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dWaDiG10; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h19sor6898820plb.61.2020.05.09.09.56.49 for (Google Transport Security); Sat, 09 May 2020 09:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:8688:: with SMTP id g8mr8023843plo.268.1589043409178; Sat, 09 May 2020 09:56:49 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:56:48 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 3/6] pci: Add Rockchip PCIe controller driver Date: Sat, 9 May 2020 22:26:21 +0530 Message-Id: <20200509165624.20791-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dWaDiG10; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add Rockchip PCIe controller driver for rk3399 platform. Driver support Gen1 by operating as a Root complex. Thanks to Patrick for initial work. Signed-off-by: Patrick Wildt Signed-off-by: Jagan Teki Reviewed-by: Kever Yang Tested-by: Suniel Mahesh #roc-rk3399-pc --- Changes for v3: - none drivers/pci/Kconfig | 8 + drivers/pci/Makefile | 1 + drivers/pci/pcie_rockchip.c | 467 ++++++++++++++++++++++++++++++++++++ drivers/pci/pcie_rockchip.h | 79 ++++++ 4 files changed, 555 insertions(+) create mode 100644 drivers/pci/pcie_rockchip.c create mode 100644 drivers/pci/pcie_rockchip.h diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 437cd9a055..3dba84103b 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -197,4 +197,12 @@ config PCIE_MEDIATEK Say Y here if you want to enable Gen2 PCIe controller, which could be found on MT7623 SoC family. +config PCIE_ROCKCHIP + bool "Enable Rockchip PCIe driver" + select DM_PCI + default y if ROCKCHIP_RK3399 + help + Say Y here if you want to enable PCIe controller support on + Rockchip SoCs. + endif diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index c051ecc9f3..493e9354dd 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -43,3 +43,4 @@ obj-$(CONFIG_PCI_PHYTIUM) += pcie_phytium.o obj-$(CONFIG_PCIE_INTEL_FPGA) += pcie_intel_fpga.o obj-$(CONFIG_PCI_KEYSTONE) += pcie_dw_ti.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie_mediatek.o +obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o diff --git a/drivers/pci/pcie_rockchip.c b/drivers/pci/pcie_rockchip.c new file mode 100644 index 0000000000..3f06f783ca --- /dev/null +++ b/drivers/pci/pcie_rockchip.c @@ -0,0 +1,467 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Rockchip AXI PCIe host controller driver + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + * Copyright (c) 2020 Jagan Teki + * Copyright (c) 2019 Patrick Wildt + * Copyright (c) 2018 Mark Kettenis + * + * Bits taken from Linux Rockchip PCIe host controller. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie_rockchip.h" + +DECLARE_GLOBAL_DATA_PTR; + +static int rockchip_pcie_off_conf(pci_dev_t bdf, uint offset) +{ + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + unsigned int func = PCI_FUNC(bdf); + + return (bus << 20) | (dev << 15) | (func << 12) | (offset & ~0x3); +} + +static int rockchip_pcie_rd_conf(const struct udevice *udev, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) +{ + struct rockchip_pcie *priv = dev_get_priv(udev); + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + int where = rockchip_pcie_off_conf(bdf, offset); + ulong value; + + if (bus == priv->first_busno && dev == 0) { + value = readl(priv->apb_base + PCIE_RC_NORMAL_BASE + where); + *valuep = pci_conv_32_to_size(value, offset, size); + return 0; + } + + if ((bus == priv->first_busno + 1) && dev == 0) { + value = readl(priv->axi_base + where); + *valuep = pci_conv_32_to_size(value, offset, size); + return 0; + } + + *valuep = pci_get_ff(size); + + return 0; +} + +static int rockchip_pcie_wr_conf(struct udevice *udev, pci_dev_t bdf, + uint offset, ulong value, + enum pci_size_t size) +{ + struct rockchip_pcie *priv = dev_get_priv(udev); + unsigned int bus = PCI_BUS(bdf); + unsigned int dev = PCI_DEV(bdf); + int where = rockchip_pcie_off_conf(bdf, offset); + ulong old; + + if (bus == priv->first_busno && dev == 0) { + old = readl(priv->apb_base + PCIE_RC_NORMAL_BASE + where); + value = pci_conv_size_to_32(old, value, offset, size); + writel(value, priv->apb_base + PCIE_RC_NORMAL_BASE + where); + return 0; + } + + if ((bus == priv->first_busno + 1) && dev == 0) { + old = readl(priv->axi_base + where); + value = pci_conv_size_to_32(old, value, offset, size); + writel(value, priv->axi_base + where); + return 0; + } + + return 0; +} + +static int rockchip_pcie_atr_init(struct rockchip_pcie *priv) +{ + struct udevice *ctlr = pci_get_controller(priv->dev); + struct pci_controller *hose = dev_get_uclass_priv(ctlr); + u64 addr, size, offset; + u32 type; + int i, region; + + /* Use region 0 to map PCI configuration space. */ + writel(25 - 1, priv->apb_base + PCIE_ATR_OB_ADDR0(0)); + writel(0, priv->apb_base + PCIE_ATR_OB_ADDR1(0)); + writel(PCIE_ATR_HDR_CFG_TYPE0 | PCIE_ATR_HDR_RID, + priv->apb_base + PCIE_ATR_OB_DESC0(0)); + writel(0, priv->apb_base + PCIE_ATR_OB_DESC1(0)); + + for (i = 0; i < hose->region_count; i++) { + if (hose->regions[i].flags == PCI_REGION_SYS_MEMORY) + continue; + + if (hose->regions[i].flags == PCI_REGION_IO) + type = PCIE_ATR_HDR_IO; + else + type = PCIE_ATR_HDR_MEM; + + /* Only support identity mappings. */ + if (hose->regions[i].bus_start != + hose->regions[i].phys_start) + return -EINVAL; + + /* Only support mappings aligned on a region boundary. */ + addr = hose->regions[i].bus_start; + if (addr & (PCIE_ATR_OB_REGION_SIZE - 1)) + return -EINVAL; + + /* Mappings should lie between AXI and APB regions. */ + size = hose->regions[i].size; + if (addr < (u64)priv->axi_base + PCIE_ATR_OB_REGION0_SIZE) + return -EINVAL; + if (addr + size > (u64)priv->apb_base) + return -EINVAL; + + offset = addr - (u64)priv->axi_base - PCIE_ATR_OB_REGION0_SIZE; + region = 1 + (offset / PCIE_ATR_OB_REGION_SIZE); + while (size > 0) { + writel(32 - 1, + priv->apb_base + PCIE_ATR_OB_ADDR0(region)); + writel(0, priv->apb_base + PCIE_ATR_OB_ADDR1(region)); + writel(type | PCIE_ATR_HDR_RID, + priv->apb_base + PCIE_ATR_OB_DESC0(region)); + writel(0, priv->apb_base + PCIE_ATR_OB_DESC1(region)); + + addr += PCIE_ATR_OB_REGION_SIZE; + size -= PCIE_ATR_OB_REGION_SIZE; + region++; + } + } + + /* Passthrough inbound translations unmodified. */ + writel(32 - 1, priv->apb_base + PCIE_ATR_IB_ADDR0(2)); + writel(0, priv->apb_base + PCIE_ATR_IB_ADDR1(2)); + + return 0; +} + +static int rockchip_pcie_init_port(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + u32 cr, val, status; + int ret; + + if (dm_gpio_is_valid(&priv->ep_gpio)) + dm_gpio_set_value(&priv->ep_gpio, 0); + + ret = reset_assert(&priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to assert aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to assert pclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->pm_rst); + if (ret) { + dev_err(dev, "failed to assert pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->core_rst); + if (ret) { + dev_err(dev, "failed to assert core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to assert mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_assert(&priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to assert mgmt-sticky reset (ret=%d)\n", + ret); + return ret; + } + + ret = reset_assert(&priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to assert pipe reset (ret=%d)\n", ret); + return ret; + } + + udelay(10); + + ret = reset_deassert(&priv->pm_rst); + if (ret) { + dev_err(dev, "failed to deassert pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to deassert aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to deassert pclk reset (ret=%d)\n", ret); + return ret; + } + + /* Select GEN1 for now */ + cr = PCIE_CLIENT_GEN_SEL_1; + /* Set Root complex mode */ + cr |= PCIE_CLIENT_CONF_ENABLE | PCIE_CLIENT_MODE_RC; + writel(cr, priv->apb_base + PCIE_CLIENT_CONFIG); + + ret = reset_deassert(&priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to deassert mgmt-sticky reset (ret=%d)\n", + ret); + return ret; + } + + ret = reset_deassert(&priv->core_rst); + if (ret) { + dev_err(dev, "failed to deassert core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to deassert mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_deassert(&priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to deassert pipe reset (ret=%d)\n", ret); + return ret; + } + + /* Enable Gen1 training */ + writel(PCIE_CLIENT_LINK_TRAIN_ENABLE, + priv->apb_base + PCIE_CLIENT_CONFIG); + + if (dm_gpio_is_valid(&priv->ep_gpio)) + dm_gpio_set_value(&priv->ep_gpio, 1); + + ret = readl_poll_sleep_timeout + (priv->apb_base + PCIE_CLIENT_BASIC_STATUS1, + status, PCIE_LINK_UP(status), 20, 500 * 1000); + if (ret) { + dev_err(dev, "PCIe link training gen1 timeout!\n"); + return ret; + } + + /* Initialize Root Complex registers. */ + writel(PCIE_LM_VENDOR_ROCKCHIP, priv->apb_base + PCIE_LM_VENDOR_ID); + writel(PCI_CLASS_BRIDGE_PCI << 16, + priv->apb_base + PCIE_RC_BASE + PCI_CLASS_REVISION); + writel(PCIE_LM_RCBARPIE | PCIE_LM_RCBARPIS, + priv->apb_base + PCIE_LM_RCBAR); + + if (dev_read_bool(dev, "aspm-no-l0s")) { + val = readl(priv->apb_base + PCIE_RC_PCIE_LCAP); + val &= ~PCIE_RC_PCIE_LCAP_APMS_L0S; + writel(val, priv->apb_base + PCIE_RC_PCIE_LCAP); + } + + /* Configure Address Translation. */ + ret = rockchip_pcie_atr_init(priv); + if (ret) { + dev_err(dev, "PCIE-%d: ATR init failed\n", dev->seq); + return ret; + } + + return 0; +} + +static int rockchip_pcie_set_vpcie(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + int ret; + + if (!IS_ERR(priv->vpcie3v3)) { + ret = regulator_set_enable(priv->vpcie3v3, true); + if (ret) { + dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", + ret); + return ret; + } + } + + ret = regulator_set_enable(priv->vpcie1v8, true); + if (ret) { + dev_err(dev, "failed to enable vpcie1v8 (ret=%d)\n", ret); + goto err_disable_3v3; + } + + ret = regulator_set_enable(priv->vpcie0v9, true); + if (ret) { + dev_err(dev, "failed to enable vpcie0v9 (ret=%d)\n", ret); + goto err_disable_1v8; + } + + return 0; + +err_disable_1v8: + regulator_set_enable(priv->vpcie1v8, false); +err_disable_3v3: + if (!IS_ERR(priv->vpcie3v3)) + regulator_set_enable(priv->vpcie3v3, false); + return ret; +} + +static int rockchip_pcie_parse_dt(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + int ret; + + priv->axi_base = dev_read_addr_name(dev, "axi-base"); + if (!priv->axi_base) + return -ENODEV; + + priv->apb_base = dev_read_addr_name(dev, "apb-base"); + if (!priv->axi_base) + return -ENODEV; + + ret = gpio_request_by_name(dev, "ep-gpios", 0, + &priv->ep_gpio, GPIOD_IS_OUT); + if (ret) { + dev_err(dev, "failed to find ep-gpios property\n"); + return ret; + } + + ret = reset_get_by_name(dev, "core", &priv->core_rst); + if (ret) { + dev_err(dev, "failed to get core reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "mgmt", &priv->mgmt_rst); + if (ret) { + dev_err(dev, "failed to get mgmt reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "mgmt-sticky", &priv->mgmt_sticky_rst); + if (ret) { + dev_err(dev, "failed to get mgmt-sticky reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pipe", &priv->pipe_rst); + if (ret) { + dev_err(dev, "failed to get pipe reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pm", &priv->pm_rst); + if (ret) { + dev_err(dev, "failed to get pm reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "pclk", &priv->pclk_rst); + if (ret) { + dev_err(dev, "failed to get pclk reset (ret=%d)\n", ret); + return ret; + } + + ret = reset_get_by_name(dev, "aclk", &priv->aclk_rst); + if (ret) { + dev_err(dev, "failed to get aclk reset (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie3v3-supply", + &priv->vpcie3v3); + if (ret && ret != -ENOENT) { + dev_err(dev, "failed to get vpcie3v3 supply (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie1v8-supply", + &priv->vpcie1v8); + if (ret) { + dev_err(dev, "failed to get vpcie1v8 supply (ret=%d)\n", ret); + return ret; + } + + ret = device_get_supply_regulator(dev, "vpcie0v9-supply", + &priv->vpcie0v9); + if (ret) { + dev_err(dev, "failed to get vpcie0v9 supply (ret=%d)\n", ret); + return ret; + } + + return 0; +} + +static int rockchip_pcie_probe(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + struct udevice *ctlr = pci_get_controller(dev); + struct pci_controller *hose = dev_get_uclass_priv(ctlr); + int ret; + + priv->first_busno = dev->seq; + priv->dev = dev; + + ret = rockchip_pcie_parse_dt(dev); + if (ret) + return ret; + + ret = rockchip_pcie_set_vpcie(dev); + if (ret) + return ret; + + ret = rockchip_pcie_init_port(dev); + if (ret) + return ret; + + dev_info(dev, "PCIE-%d: Link up (Bus%d)\n", + dev->seq, hose->first_busno); + + return 0; +} + +static const struct dm_pci_ops rockchip_pcie_ops = { + .read_config = rockchip_pcie_rd_conf, + .write_config = rockchip_pcie_wr_conf, +}; + +static const struct udevice_id rockchip_pcie_ids[] = { + { .compatible = "rockchip,rk3399-pcie" }, + { } +}; + +U_BOOT_DRIVER(rockchip_pcie) = { + .name = "rockchip_pcie", + .id = UCLASS_PCI, + .of_match = rockchip_pcie_ids, + .ops = &rockchip_pcie_ops, + .probe = rockchip_pcie_probe, + .priv_auto_alloc_size = sizeof(struct rockchip_pcie), +}; diff --git a/drivers/pci/pcie_rockchip.h b/drivers/pci/pcie_rockchip.h new file mode 100644 index 0000000000..6ded5c9553 --- /dev/null +++ b/drivers/pci/pcie_rockchip.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Rockchip PCIe Headers + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + * Copyright (c) 2020 Jagan Teki + * Copyright (c) 2019 Patrick Wildt + * + */ + +#define HIWORD_UPDATE(mask, val) (((mask) << 16) | (val)) +#define HIWORD_UPDATE_BIT(val) HIWORD_UPDATE(val, val) + +#define ENCODE_LANES(x) ((((x) >> 1) & 3) << 4) +#define PCIE_CLIENT_BASE 0x0 +#define PCIE_CLIENT_CONFIG (PCIE_CLIENT_BASE + 0x00) +#define PCIE_CLIENT_CONF_ENABLE HIWORD_UPDATE_BIT(0x0001) +#define PCIE_CLIENT_LINK_TRAIN_ENABLE HIWORD_UPDATE_BIT(0x0002) +#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040) +#define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0) +#define PCIE_CLIENT_BASIC_STATUS1 0x0048 +#define PCIE_CLIENT_LINK_STATUS_UP GENMASK(21, 20) +#define PCIE_CLIENT_LINK_STATUS_MASK GENMASK(21, 20) +#define PCIE_LINK_UP(x) \ + (((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP) +#define PCIE_RC_NORMAL_BASE 0x800000 +#define PCIE_LM_BASE 0x900000 +#define PCIE_LM_VENDOR_ID (PCIE_LM_BASE + 0x44) +#define PCIE_LM_VENDOR_ROCKCHIP 0x1d87 +#define PCIE_LM_RCBAR (PCIE_LM_BASE + 0x300) +#define PCIE_LM_RCBARPIE BIT(19) +#define PCIE_LM_RCBARPIS BIT(20) +#define PCIE_RC_BASE 0xa00000 +#define PCIE_RC_CONFIG_DCR (PCIE_RC_BASE + 0x0c4) +#define PCIE_RC_CONFIG_DCR_CSPL_SHIFT 18 +#define PCIE_RC_CONFIG_DCR_CPLS_SHIFT 26 +#define PCIE_RC_PCIE_LCAP (PCIE_RC_BASE + 0x0cc) +#define PCIE_RC_PCIE_LCAP_APMS_L0S BIT(10) +#define PCIE_ATR_BASE 0xc00000 +#define PCIE_ATR_OB_ADDR0(i) (PCIE_ATR_BASE + 0x000 + (i) * 0x20) +#define PCIE_ATR_OB_ADDR1(i) (PCIE_ATR_BASE + 0x004 + (i) * 0x20) +#define PCIE_ATR_OB_DESC0(i) (PCIE_ATR_BASE + 0x008 + (i) * 0x20) +#define PCIE_ATR_OB_DESC1(i) (PCIE_ATR_BASE + 0x00c + (i) * 0x20) +#define PCIE_ATR_IB_ADDR0(i) (PCIE_ATR_BASE + 0x800 + (i) * 0x8) +#define PCIE_ATR_IB_ADDR1(i) (PCIE_ATR_BASE + 0x804 + (i) * 0x8) +#define PCIE_ATR_HDR_MEM 0x2 +#define PCIE_ATR_HDR_IO 0x6 +#define PCIE_ATR_HDR_CFG_TYPE0 0xa +#define PCIE_ATR_HDR_CFG_TYPE1 0xb +#define PCIE_ATR_HDR_RID BIT(23) + +#define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024) +#define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024) + +struct rockchip_pcie { + fdt_addr_t axi_base; + fdt_addr_t apb_base; + int first_busno; + struct udevice *dev; + + /* resets */ + struct reset_ctl core_rst; + struct reset_ctl mgmt_rst; + struct reset_ctl mgmt_sticky_rst; + struct reset_ctl pipe_rst; + struct reset_ctl pm_rst; + struct reset_ctl pclk_rst; + struct reset_ctl aclk_rst; + + /* gpio */ + struct gpio_desc ep_gpio; + + /* vpcie regulators */ + struct udevice *vpcie12v; + struct udevice *vpcie3v3; + struct udevice *vpcie1v8; + struct udevice *vpcie0v9; +}; From patchwork Sat May 9 16:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1162 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E797C3F08E for ; Sat, 9 May 2020 18:56:55 +0200 (CEST) Received: by mail-il1-f197.google.com with SMTP id z5sf4989734ilz.1 for ; Sat, 09 May 2020 09:56:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043414; cv=pass; d=google.com; s=arc-20160816; b=koOlrSYtQU51rT4vITwzPCl/4A/6Svdzm8BnS3kE3N8rV0dELU58WIKBBBRhejDvEP 5dNZ+YZDrbUzC4Yk4GYnQzd8YmgcPho0H2nMefXxYixdK+AD1ZSKAyTS94xJGiROB3Zm 1Ug4gGXNZb72Ujv8TD2jk4BtC8hpSDOj4jfmqYmDggt/AFMwBkMAF0FJ3oqs1tmxW3Jw 1wO7uw5Dvom5BcEcGAbSDbkZxjV4ucc++Lj1pJ2l5mSCGZPJY74iUCnnnvmENohQ06Nd +agaAakqMOdp+r4CspZn6tgazwmb/eGzs4vitIHfpuq+KtEM4lxETnqdSnSt1CZ700Gn Z6Vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=fHpFp3ur+JPAdXL5/iywHlVAqsSt+UOXsXgF4mbTJm0=; b=gnpFx92Yi1oLyNz7LD5s2igaIombE9Cqa+2g9DwbkwiCSJK9ZZUxwYrW8FmTFTH0zM QA+2PMXd6mRkdPjbAFxLomcl0alJrFljCF8eWx74jelOJJRF40vYVcPUDzWy5cZmhv+f qXvbx8lDH+GUv2+JwNGS0O1wtcLTWBbjulVBVwo9szez6YczjRcdc2vJO4xVaIKaAma3 55bJjWbPb6or/+2ChIm4mltTxASGRksiZfCs3T7LHDFXMCrJxl6YIKwjIYyofj2H1+N6 u5E1IroR7owAEe/aCKednzcWz6r3N4Qb5uByET/nISIdZzpRrY1jFAls8ODAAAP8/LaX sgJg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="O36e/9QM"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=fHpFp3ur+JPAdXL5/iywHlVAqsSt+UOXsXgF4mbTJm0=; b=BnympgGEyZ2SRfdEbU5/wsTxmWjSGZmxNuD0xOE1eq5diR3VjznYEdYaF4Pm0w9c2+ m+0KfuGd+EhTf/9tiLRrxlDvowldItRwr68npkMapvH1cj3zzNXcLsts3wdpMDmCh/Ks gXttlyzT2iF1Ff8bicor0+LNnuxMfeN1UswuE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=fHpFp3ur+JPAdXL5/iywHlVAqsSt+UOXsXgF4mbTJm0=; b=E1rqMSRb9wC6GFauWmnPDbAUeBWtoLyCxC4XbVISFDcGK0CiwpIA+gOjaXrP0s5R/3 UeK2H5eApgJhyTSswMn+mYH/3/oKCsrEE77DbKiDEcavKGLObK6lhME4mQhf9sD0hnLR iGpz2c9v/NU0ELWFYnoP1ZL6ijF9nJNLyrsCL1c1QLnmwT1pO3nIeAcTmfF7Xiyz+OaZ Bdw3ebw4SzjgGjeacFHzJBnzQ28qKhopfegvTRDUWrwuqHfzxMoRssO3WAf4meU4PA7b CTi8t1lCwKVwAUinF2ZG0tMV01HTJWhMfFCZFiDHmR7aDQcoVThv6DTyzGgrCHXsnR4f 2kWQ== X-Gm-Message-State: AGi0PuYKroDkwcC8IsVBM5+RZq5/5EzaENbKtKxi85G3txosImA/THie 9y5sRTu2SsWGvYWuMb4K140KgOqt X-Google-Smtp-Source: APiQypIfr9rfoJzma6VaiURfOkaowiYfPVV78eVhKAf9oCOlu/e/tPLR1PGSaoicJqQkV8hrMsqtSQ== X-Received: by 2002:a02:2428:: with SMTP id f40mr7996837jaa.49.1589043413978; Sat, 09 May 2020 09:56:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6638:3a9:: with SMTP id z9ls1037976jap.11.gmail; Sat, 09 May 2020 09:56:53 -0700 (PDT) X-Received: by 2002:a02:c9cb:: with SMTP id c11mr7469255jap.93.1589043413455; Sat, 09 May 2020 09:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043413; cv=none; d=google.com; s=arc-20160816; b=t7ORfcC0DzacP5+PNpAjGTGf9OXaUIPyrcLqEaHuePvvuuxnBv2sueWht/Vo2jU4q3 3hgEX3gO02pw7meaZy+dEQe0KHSzMhNHoDWOgz0FsPLwg/Ia3xWDO/epSPMT4PZLsHrW WAS9gGTy4Xo7kmOASCjBUbgngVaJ1978GH9DbajOaVzFfB8+dwTBXxoGLMHvsmGiEnCL /gCEcK7NakE3tckxw/WqsWipRx2Hy1O5LDD+gVqTsYTmmJT9x84Msa+k3HcnUHnC1wpO YUUt1YxerRNoK1Ct7YjhHz4RZI/wlpYGKYJnk7L3Fl2T1SLg6RVbw8Gzjn8bh8Hg5CD2 GzWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=12JLHJJoRLxNkpyAhU61EyjuReXe2tUXvBwcr6h09W4=; b=H9TDtnzRxRlNqMaSDtInSHGfJ4huVdK/qNEcosp/LR5wiD2RgawgBwgHXSHvs+wgoz wHm4y2kwI9Smu9fiw04AtFCb4W1d9MYDntQ2gxp4gfJaIC08GD9dTIUvb/yikTAnT1PF LR2jv/yhuX5ZNF/6HEQvmikXk9qxYv/SkrlRuZlYEZ0IxpbWv/qsLOgDlXzbWbTLfknG gxIm155kTgjPaj/dqQf1NdmRTHFqibPaTiW1FiZydhe6iqBIQpRykzV5gomLCPToAV5n NM3sb0ed6DLkWYgTLfqIFDsor1v9U5GovuZReg343YvLlN51eIZlkJOqjQYhLJeSx3vE A3kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="O36e/9QM"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w9sor5857675ioj.70.2020.05.09.09.56.53 for (Google Transport Security); Sat, 09 May 2020 09:56:53 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:e28c:: with SMTP id d12mr12704645pjz.19.1589043413026; Sat, 09 May 2020 09:56:53 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:56:52 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 4/6] pci: Add Rockchip PCIe PHY controller driver Date: Sat, 9 May 2020 22:26:22 +0530 Message-Id: <20200509165624.20791-5-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="O36e/9QM"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Yes, it is possible to have a dedicated UCLASS PHY driver for this Rockchip PCIe PHY but there are some issues on Generic PHY framework to support the same. The Generic PHY framework is unable to get the PHY if the PHY parent is of a different uclass. Say if we try to get the PCIe PHY then the phy-uclass will look for PHY in the first instance if it is not in the root node it will try to probe the parent by assuming that the actual PHY is inside the parent PHY of UCLASS_PHY. But, in rk3399 hardware representation PHY like emmc, usb and pcie are part of syscon which is completely a different of UCLASS_SYSCON. Example: grf: syscon@ff770000 { compatible = "rockchip,rk3399-grf", "syscon", "simple-mfd"; reg = <0x0 0xff770000 0x0 0x10000>; #address-cells = <1>; #size-cells = <1>; pcie_phy: pcie-phy { compatible = "rockchip,rk3399-pcie-phy"; clocks = <&cru SCLK_PCIEPHY_REF>; clock-names = "refclk"; #phy-cells = <1>; resets = <&cru SRST_PCIEPHY>; drive-impedance-ohm = <50>; reset-names = "phy"; status = "disabled"; }; }; Due to this limitation, this patch adds a separate PHY driver for Rockchip PCIe. This might be removed in future once Generic PHY supports this limitation. Signed-off-by: Jagan Teki Tested-by: Suniel Mahesh #roc-rk3399-pc Reviewed-by: Kever Yang --- Changes for v3: - none drivers/pci/Makefile | 2 +- drivers/pci/pcie_rockchip.c | 50 ++++++-- drivers/pci/pcie_rockchip.h | 63 ++++++++++ drivers/pci/pcie_rockchip_phy.c | 205 ++++++++++++++++++++++++++++++++ 4 files changed, 306 insertions(+), 14 deletions(-) create mode 100644 drivers/pci/pcie_rockchip_phy.c diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 493e9354dd..955351c5c2 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -43,4 +43,4 @@ obj-$(CONFIG_PCI_PHYTIUM) += pcie_phytium.o obj-$(CONFIG_PCIE_INTEL_FPGA) += pcie_intel_fpga.o obj-$(CONFIG_PCI_KEYSTONE) += pcie_dw_ti.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie_mediatek.o -obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o +obj-$(CONFIG_PCIE_ROCKCHIP) += pcie_rockchip.o pcie_rockchip_phy.o diff --git a/drivers/pci/pcie_rockchip.c b/drivers/pci/pcie_rockchip.c index 3f06f783ca..82a8396e42 100644 --- a/drivers/pci/pcie_rockchip.c +++ b/drivers/pci/pcie_rockchip.c @@ -159,6 +159,8 @@ static int rockchip_pcie_atr_init(struct rockchip_pcie *priv) static int rockchip_pcie_init_port(struct udevice *dev) { struct rockchip_pcie *priv = dev_get_priv(dev); + struct rockchip_pcie_phy *phy = pcie_get_phy(priv); + struct rockchip_pcie_phy_ops *ops = phy_get_ops(phy); u32 cr, val, status; int ret; @@ -183,29 +185,35 @@ static int rockchip_pcie_init_port(struct udevice *dev) return ret; } + ret = ops->init(phy); + if (ret) { + dev_err(dev, "failed to init phy (ret=%d)\n", ret); + goto err_exit_phy; + } + ret = reset_assert(&priv->core_rst); if (ret) { dev_err(dev, "failed to assert core reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->mgmt_rst); if (ret) { dev_err(dev, "failed to assert mgmt reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->mgmt_sticky_rst); if (ret) { dev_err(dev, "failed to assert mgmt-sticky reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_assert(&priv->pipe_rst); if (ret) { dev_err(dev, "failed to assert pipe reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } udelay(10); @@ -213,19 +221,19 @@ static int rockchip_pcie_init_port(struct udevice *dev) ret = reset_deassert(&priv->pm_rst); if (ret) { dev_err(dev, "failed to deassert pm reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_deassert(&priv->aclk_rst); if (ret) { dev_err(dev, "failed to deassert aclk reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } ret = reset_deassert(&priv->pclk_rst); if (ret) { dev_err(dev, "failed to deassert pclk reset (ret=%d)\n", ret); - return ret; + goto err_exit_phy; } /* Select GEN1 for now */ @@ -234,29 +242,35 @@ static int rockchip_pcie_init_port(struct udevice *dev) cr |= PCIE_CLIENT_CONF_ENABLE | PCIE_CLIENT_MODE_RC; writel(cr, priv->apb_base + PCIE_CLIENT_CONFIG); + ret = ops->power_on(phy); + if (ret) { + dev_err(dev, "failed to power on phy (ret=%d)\n", ret); + goto err_power_off_phy; + } + ret = reset_deassert(&priv->mgmt_sticky_rst); if (ret) { dev_err(dev, "failed to deassert mgmt-sticky reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->core_rst); if (ret) { dev_err(dev, "failed to deassert core reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->mgmt_rst); if (ret) { dev_err(dev, "failed to deassert mgmt reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } ret = reset_deassert(&priv->pipe_rst); if (ret) { dev_err(dev, "failed to deassert pipe reset (ret=%d)\n", ret); - return ret; + goto err_power_off_phy; } /* Enable Gen1 training */ @@ -271,7 +285,7 @@ static int rockchip_pcie_init_port(struct udevice *dev) status, PCIE_LINK_UP(status), 20, 500 * 1000); if (ret) { dev_err(dev, "PCIe link training gen1 timeout!\n"); - return ret; + goto err_power_off_phy; } /* Initialize Root Complex registers. */ @@ -291,10 +305,16 @@ static int rockchip_pcie_init_port(struct udevice *dev) ret = rockchip_pcie_atr_init(priv); if (ret) { dev_err(dev, "PCIE-%d: ATR init failed\n", dev->seq); - return ret; + goto err_power_off_phy; } return 0; + +err_power_off_phy: + ops->power_off(phy); +err_exit_phy: + ops->exit(phy); + return ret; } static int rockchip_pcie_set_vpcie(struct udevice *dev) @@ -433,6 +453,10 @@ static int rockchip_pcie_probe(struct udevice *dev) if (ret) return ret; + ret = rockchip_pcie_phy_get(dev); + if (ret) + return ret; + ret = rockchip_pcie_set_vpcie(dev); if (ret) return ret; diff --git a/drivers/pci/pcie_rockchip.h b/drivers/pci/pcie_rockchip.h index 6ded5c9553..c3a0a2846d 100644 --- a/drivers/pci/pcie_rockchip.h +++ b/drivers/pci/pcie_rockchip.h @@ -53,11 +53,61 @@ #define PCIE_ATR_OB_REGION0_SIZE (32 * 1024 * 1024) #define PCIE_ATR_OB_REGION_SIZE (1 * 1024 * 1024) +/* + * The higher 16-bit of this register is used for write protection + * only if BIT(x + 16) set to 1 the BIT(x) can be written. + */ +#define HIWORD_UPDATE_MASK(val, mask, shift) \ + ((val) << (shift) | (mask) << ((shift) + 16)) + +#define PHY_CFG_DATA_SHIFT 7 +#define PHY_CFG_ADDR_SHIFT 1 +#define PHY_CFG_DATA_MASK 0xf +#define PHY_CFG_ADDR_MASK 0x3f +#define PHY_CFG_RD_MASK 0x3ff +#define PHY_CFG_WR_ENABLE 1 +#define PHY_CFG_WR_DISABLE 1 +#define PHY_CFG_WR_SHIFT 0 +#define PHY_CFG_WR_MASK 1 +#define PHY_CFG_PLL_LOCK 0x10 +#define PHY_CFG_CLK_TEST 0x10 +#define PHY_CFG_CLK_SCC 0x12 +#define PHY_CFG_SEPE_RATE BIT(3) +#define PHY_CFG_PLL_100M BIT(3) +#define PHY_PLL_LOCKED BIT(9) +#define PHY_PLL_OUTPUT BIT(10) +#define PHY_LANE_IDLE_OFF 0x1 +#define PHY_LANE_IDLE_MASK 0x1 +#define PHY_LANE_IDLE_A_SHIFT 3 +#define PHY_LANE_IDLE_B_SHIFT 4 +#define PHY_LANE_IDLE_C_SHIFT 5 +#define PHY_LANE_IDLE_D_SHIFT 6 + +#define PCIE_PHY_CONF 0xe220 +#define PCIE_PHY_STATUS 0xe2a4 +#define PCIE_PHY_LANEOFF 0xe214 + +struct rockchip_pcie_phy { + void *reg_base; + struct clk refclk; + struct reset_ctl phy_rst; + struct rockchip_pcie_phy_ops *ops; +}; + +struct rockchip_pcie_phy_ops { + int (*init)(struct rockchip_pcie_phy *phy); + int (*exit)(struct rockchip_pcie_phy *phy); + int (*power_on)(struct rockchip_pcie_phy *phy); + int (*power_off)(struct rockchip_pcie_phy *phy); +}; + struct rockchip_pcie { fdt_addr_t axi_base; fdt_addr_t apb_base; int first_busno; struct udevice *dev; + struct rockchip_pcie_phy rk_phy; + struct rockchip_pcie_phy *phy; /* resets */ struct reset_ctl core_rst; @@ -77,3 +127,16 @@ struct rockchip_pcie { struct udevice *vpcie1v8; struct udevice *vpcie0v9; }; + +int rockchip_pcie_phy_get(struct udevice *dev); + +inline struct rockchip_pcie_phy *pcie_get_phy(struct rockchip_pcie *pcie) +{ + return pcie->phy; +} + +inline +struct rockchip_pcie_phy_ops *phy_get_ops(struct rockchip_pcie_phy *phy) +{ + return (struct rockchip_pcie_phy_ops *)phy->ops; +} diff --git a/drivers/pci/pcie_rockchip_phy.c b/drivers/pci/pcie_rockchip_phy.c new file mode 100644 index 0000000000..47f5d6c7e3 --- /dev/null +++ b/drivers/pci/pcie_rockchip_phy.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Rockchip PCIe PHY driver + * + * Copyright (c) 2016 Rockchip, Inc. + * Copyright (c) 2020 Amarula Solutions(India) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie_rockchip.h" + +DECLARE_GLOBAL_DATA_PTR; + +static void phy_wr_cfg(struct rockchip_pcie_phy *phy, u32 addr, u32 data) +{ + u32 reg; + + reg = HIWORD_UPDATE_MASK(data, PHY_CFG_DATA_MASK, PHY_CFG_DATA_SHIFT); + reg |= HIWORD_UPDATE_MASK(addr, PHY_CFG_ADDR_MASK, PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + udelay(1); + + reg = HIWORD_UPDATE_MASK(PHY_CFG_WR_ENABLE, + PHY_CFG_WR_MASK, + PHY_CFG_WR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + udelay(1); + + reg = HIWORD_UPDATE_MASK(PHY_CFG_WR_DISABLE, + PHY_CFG_WR_MASK, + PHY_CFG_WR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); +} + +static int rockchip_pcie_phy_power_on(struct rockchip_pcie_phy *phy) +{ + int ret = 0; + u32 reg, status; + + ret = reset_deassert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + return ret; + } + + reg = HIWORD_UPDATE_MASK(PHY_CFG_PLL_LOCK, + PHY_CFG_ADDR_MASK, + PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + reg = HIWORD_UPDATE_MASK(!PHY_LANE_IDLE_OFF, + PHY_LANE_IDLE_MASK, + PHY_LANE_IDLE_A_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_LANEOFF); + + ret = -EINVAL; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + status & PHY_PLL_LOCKED, + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll lock timeout!\n"); + goto err_pll_lock; + } + + phy_wr_cfg(phy, PHY_CFG_CLK_TEST, PHY_CFG_SEPE_RATE); + phy_wr_cfg(phy, PHY_CFG_CLK_SCC, PHY_CFG_PLL_100M); + + ret = -ETIMEDOUT; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + !(status & PHY_PLL_OUTPUT), + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll output enable timeout!\n"); + goto err_pll_lock; + } + + reg = HIWORD_UPDATE_MASK(PHY_CFG_PLL_LOCK, + PHY_CFG_ADDR_MASK, + PHY_CFG_ADDR_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_CONF); + + ret = -EINVAL; + ret = readl_poll_sleep_timeout(phy->reg_base + PCIE_PHY_STATUS, + status, + status & PHY_PLL_LOCKED, + 20 * 1000, + 50); + if (ret) { + dev_err(&phy->dev, "pll relock timeout!\n"); + goto err_pll_lock; + } + + return 0; + +err_pll_lock: + reset_assert(&phy->phy_rst); + return ret; +} + +static int rockchip_pcie_phy_power_off(struct rockchip_pcie_phy *phy) +{ + int ret; + u32 reg; + + reg = HIWORD_UPDATE_MASK(PHY_LANE_IDLE_OFF, + PHY_LANE_IDLE_MASK, + PHY_LANE_IDLE_A_SHIFT); + writel(reg, phy->reg_base + PCIE_PHY_LANEOFF); + + ret = reset_assert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + return ret; + } + + return 0; +} + +static int rockchip_pcie_phy_init(struct rockchip_pcie_phy *phy) +{ + int ret; + + ret = clk_enable(&phy->refclk); + if (ret) { + dev_err(dev, "failed to enable refclk clock\n"); + return ret; + } + + ret = reset_assert(&phy->phy_rst); + if (ret) { + dev_err(dev, "failed to assert phy reset\n"); + goto err_reset; + } + + return 0; + +err_reset: + clk_disable(&phy->refclk); + return ret; +} + +static int rockchip_pcie_phy_exit(struct rockchip_pcie_phy *phy) +{ + clk_disable(&phy->refclk); + + return 0; +} + +static struct rockchip_pcie_phy_ops pcie_phy_ops = { + .init = rockchip_pcie_phy_init, + .power_on = rockchip_pcie_phy_power_on, + .power_off = rockchip_pcie_phy_power_off, + .exit = rockchip_pcie_phy_exit, +}; + +int rockchip_pcie_phy_get(struct udevice *dev) +{ + struct rockchip_pcie *priv = dev_get_priv(dev); + struct rockchip_pcie_phy *phy_priv = &priv->rk_phy; + ofnode phy_node; + u32 phandle; + int ret; + + phandle = dev_read_u32_default(dev, "phys", 0); + phy_node = ofnode_get_by_phandle(phandle); + if (!ofnode_valid(phy_node)) { + dev_err(dev, "failed to found pcie-phy\n"); + return -ENODEV; + } + + phy_priv->reg_base = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + + ret = clk_get_by_index_nodev(phy_node, 0, &phy_priv->refclk); + if (ret) { + dev_err(dev, "failed to get refclk clock phandle\n"); + return ret; + } + + ret = reset_get_by_index_nodev(phy_node, 0, &phy_priv->phy_rst); + if (ret) { + dev_err(dev, "failed to get phy reset phandle\n"); + return ret; + } + + phy_priv->ops = &pcie_phy_ops; + priv->phy = phy_priv; + + return 0; +} From patchwork Sat May 9 16:56:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1163 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 0BF5A3F08E for ; Sat, 9 May 2020 18:56:59 +0200 (CEST) Received: by mail-pl1-f199.google.com with SMTP id e9sf4158167pls.11 for ; Sat, 09 May 2020 09:56:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043418; cv=pass; d=google.com; s=arc-20160816; b=pE33+fFiAgDq4SuRsCRYyAI3SzZNOL2s0lF44Pf8538wfqZhAPmcx7Yh5Oi9w7y/4i 2JPK7rMhSu5+WEmWWJbDoG6aaNZsFrwgF6EIGMNIqngwwcFn75YlA78s2JjNgqgg3fhS zFI+E9rDMiN7rlxt5MXaKH4uDlTSMjQKi9r9fXW32m4z4sLXgohzz19KKjTEIWhLH0Dc z59KsMluYtqQ0Kyvmi1ttWJNHPSc1HijaPV1sqExGcBnTEKlZqVy/7Kbf9S/hksaQGQQ jUr1AfDhWBC2uvQLTzaqIErR+1YHZVn2VyHjv4d2ovyqhn8uV+Hk6IVsgGpqNdx9r9/4 43Ew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=ozanikP9DPXqo3ksKDqU8SQSpjDRygKHN1PQRj6PnAw=; b=ZOFH7VFf6LwaqKlDf/bSzCF8QOyfahs5ml36XkzNhTXApmGlk+PvLOgkw1H4lYph/H Sz+qtdfIoMoDaM6LptAAksbHbU8PqMqnT3vZdv+9Bw3E4CdQqXXD56HRWbLPWjrzYuJb QDOr3HECucTFtfOhaPyy01hQJmH5YqSn5gj7ZfzHcgorLmowkp6NUBymhvS5yzgavwyg qFZgAcPnoEM/WbXDykjlMInEqiLgcjqeN7X5IYdpntQFM/hDMYPptrihs/2kEyDR/9o0 XAMAFHYDlws+X4imL5Rf0GfthgF/dxYW1tFKb90gU476Nl7Umr13pfnpagkbF2SYa4eb BgIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PHZowljK; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=ozanikP9DPXqo3ksKDqU8SQSpjDRygKHN1PQRj6PnAw=; b=WMZounC0kw3tUFQIyBxkYg75mB2vljTvHMmkK6q0jyiSOL/Fw3aGSmNT1M2C2ZrXWE FTO8EVe9cNgigUiQ7c0NSDyf0jREFOM6ycTLZlpeE3JeSTq8Mdab1btKDjrUuudowDV/ j81ETsqgpmOTWg5PvRwqgXpimizUyFNPtlJRo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=ozanikP9DPXqo3ksKDqU8SQSpjDRygKHN1PQRj6PnAw=; b=dhg3L0ITc7bvk80qCNFYqhokxxHegi4n03tvuVIkmzb2oJBDaREVSXvuFDC11FOTRM OUfPgyHak64wyTIMysgsF3Diq6wy+bWHVGU17i0f8n7hXMFPjGehEDw5G8pwfx77BaIb QHtK9aVnysJZ2U9F+QByVhdvxCC2TJC5Xn07BJiX3xDxxiPKVgVsdXJcEQIcCEu2l/cE tVX3Tel1TAuNUMbj8SwlHM3zbMiBAsBpCRsufLfzAp6TWTihAngUGXfe5OdNw7Rz+b0M LHp5rR/h7hldfU2vGRbW+Jw1C0soziw8/BIiCICX3bZg7N/bLCxobZFzQb1HcaC+/eS7 dPWQ== X-Gm-Message-State: AGi0Pua9ooGv15/SB6Nh2ayIp19xc14LAhNYchIeGMP1xyKCYXK1865H FLhHCi1cBv6/YEF9G5lbifD7nFtb X-Google-Smtp-Source: APiQypItRnJQ+O9SS2PjKEyFKL/1lYvPJnTrHKOguQNPzDi5uu+KPrp4KpiCmymJTgXCEOUFR98MPA== X-Received: by 2002:a17:90a:cb09:: with SMTP id z9mr12754001pjt.120.1589043417832; Sat, 09 May 2020 09:56:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:54:: with SMTP id 81ls3234576pfa.10.gmail; Sat, 09 May 2020 09:56:57 -0700 (PDT) X-Received: by 2002:a62:3383:: with SMTP id z125mr8500305pfz.271.1589043417394; Sat, 09 May 2020 09:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043417; cv=none; d=google.com; s=arc-20160816; b=gaWtCO9mYJXp/4cmhls/r0LLy0gRV28CmfAE6tyhaKZPrcUmBdCOZRRum6BNB4GFmQ yHQQ0exXplgV4lU7TmqEMKnV3rAmhIhzxROUcFKiP/7/k8/74abAjvur7x92qoy/sA/F rUxZHZByhax1K50J1tNW41wiagi0oZAZs5wUoUOxJV7EA861GPGu/rQ7dtKMHis8t9Bt KGW9u2EYkzff/5xY2lO1YCu8vU05unsaPXuG7AkScNBj2zUWfIgUBGg7kh07YY0EOgKz zCKmx51iBvla9CCBZ6d8PwbqF1ertDXwvbwHKr6IRfjZcKFeoThXd98OQm+glSG93rlX DC+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ii5Sn8J9fYkrnAk20hsnlM7A2tcOzMzExjTK6/tjUZE=; b=nMVzdBEEg8vhqs1RC6C0t3ZHgZ282MN61CKGHpHWIWZJl2FWmVY+qfqtpAmGbWZgJ3 G5LmSwy4FRjrEHpFMKjScwmiZsL8lbShk80hncY3pBzF6Cv1PWUuOPb2ugh94FGPAFnq u8mTP+r//E4YBwVVHk81CqlARIMTkqQdpq8NP800Sm4J6bYGDq75FSLoS2uIakDJaRV4 nAc0mRr116xvx0tR50cKLbHLIbG3B02L2pZFZYQIU5MCHTZYhq9P8Mef/2UXM9dyC3bf uwlfQlIxJGvirAH+bBLH/dROlhe2p1lPp56B1eHE3uiWiJxpJoGkERNOOq+fDya66zdi 1nJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PHZowljK; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i2sor6945818pfq.47.2020.05.09.09.56.57 for (Google Transport Security); Sat, 09 May 2020 09:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a62:6385:: with SMTP id x127mr9026745pfb.276.1589043417095; Sat, 09 May 2020 09:56:57 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:56:56 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 5/6] rockchip: Enable PCIe/M.2 on rk3399 board w/ M.2 Date: Sat, 9 May 2020 22:26:23 +0530 Message-Id: <20200509165624.20791-6-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PHZowljK; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Enable PCIe/M.2 support on - NanoPC-T4 - ROC-RK3399-PC Mezzanine boards. Signed-off-by: Jagan Teki Tested-by: Suniel Mahesh #roc-rk3399-pc Reviewed-by: Kever Yang --- Changes for v3: - none arch/arm/dts/rk3399-u-boot.dtsi | 1 + configs/nanopc-t4-rk3399_defconfig | 4 ++++ configs/roc-pc-mezzanine-rk3399_defconfig | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/arch/arm/dts/rk3399-u-boot.dtsi b/arch/arm/dts/rk3399-u-boot.dtsi index 9bb130a92a..d66d5b6a38 100644 --- a/arch/arm/dts/rk3399-u-boot.dtsi +++ b/arch/arm/dts/rk3399-u-boot.dtsi @@ -8,6 +8,7 @@ aliases { mmc0 = &sdhci; mmc1 = &sdmmc; + pci0 = &pcie0; }; cic: syscon@ff620000 { diff --git a/configs/nanopc-t4-rk3399_defconfig b/configs/nanopc-t4-rk3399_defconfig index ae865908d8..3bb5b498f2 100644 --- a/configs/nanopc-t4-rk3399_defconfig +++ b/configs/nanopc-t4-rk3399_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_SPL_OF_CONTROL=y @@ -34,10 +35,13 @@ CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_DM_ETH=y CONFIG_ETH_DESIGNWARE=y CONFIG_GMAC_ROCKCHIP=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYSRESET=y diff --git a/configs/roc-pc-mezzanine-rk3399_defconfig b/configs/roc-pc-mezzanine-rk3399_defconfig index 5a694edc03..0b853805f3 100644 --- a/configs/roc-pc-mezzanine-rk3399_defconfig +++ b/configs/roc-pc-mezzanine-rk3399_defconfig @@ -19,6 +19,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_SPL_OF_CONTROL=y @@ -36,11 +37,14 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_ETH_DESIGNWARE=y CONFIG_GMAC_ROCKCHIP=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y CONFIG_RAM_RK3399_LPDDR4=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_ROCKCHIP_SPI=y From patchwork Sat May 9 16:56:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1164 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 34B523F08E for ; Sat, 9 May 2020 18:57:03 +0200 (CEST) Received: by mail-pj1-f70.google.com with SMTP id k10sf12615539pjj.4 for ; Sat, 09 May 2020 09:57:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1589043422; cv=pass; d=google.com; s=arc-20160816; b=P4e9PXqAM+3/zAbkxx0fhu+URkxDUY96G3okfCeJ7XnY78YFTgqoJ3LLgRjuEXYXfc PP4CFDrjBELcTr1/yOoTH+xJtqfweP7MQFjDOsEv+jf9dKg79figaea6hruYIYaqQaIh 1TvsOKpaSG36uuwfOsiSrGHWL+bboVkroHE4VXiD5WbfZVmIIOp4BQ+GVyCDjvvr+OPK lXwU1BI7R3Der1eMzA/sCfwfU37TzzXJPAoFktHgqHkD63AJj+efwWUs/jjMV+/ZJjCc AlvF3AftsskybDbp1HeJ6GhopuNvRX1ltyD5o4iPhaP8Dj64Fzf7/5XY1BI44CZnes0Z V7kA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=PLNLRR2sqZsjX6Qf7Lxs8MU003fu+KYp5Y8ywijp8WE=; b=mcLhERzxT3zGWOo+G0bjK1QVyk1NiWQmS5LhOAJjyYhHBEhOqLd01yaO4pEt/VNJVX ZHzD3EZXKPf4jZKXoIZQFIlbrUslB0ppsy6pN5wsQ+KJFDHkO0LbdNHl+HmoeqrVlCW3 GDwv/4o2/2N55XnZgSZiJxJlXmHRR6lEs6xwzd6csCau4q41hYrZxjdy1AMdlhfAQmOy LhrgrYxp7ME0JaKDSKNp2EdtR2ewMDQTzRPVyeo+Abhy3pF4KscLChLIi3I9o/Rnd1yI WBA9bkWs3s98s6vCmR8h3e+GqWtrK1oLj/vLf/Pbrxws/A52lLUiiFBYELNoHzoeREp/ qj3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZqH+XTOL; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=PLNLRR2sqZsjX6Qf7Lxs8MU003fu+KYp5Y8ywijp8WE=; b=nHoaL72xtnPdJY2WvzpV+oVvOTlshXpIMoVg2c/dRhCb9VTm5TzW+54//KkkjCe2h7 b8SRFH5PftsTPPptyY/zkrP6mt2FxlZmWt5CtOLMtHc7o9h1fQMdT/bCnJP7T0qGhbSH V/7bHMDpHzwc8KgB8mxCWipIL4K5aSFBe1KZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=PLNLRR2sqZsjX6Qf7Lxs8MU003fu+KYp5Y8ywijp8WE=; b=ivQY0Kl1apqKJDSDoXModPRym/yUwFdMUTqUzIg3ajOcEHYq68LJFWqA/JkEMF6jFr z0d5gpWRcbNzstkIL6YyEGnStaIbGaJDjxb4z8N49MB2lCtenprTElpSxflg7Ic3jyHK 1J0GhO3tSafPQXBK5Tx6VDyy3dSGSCSR0ZmRNHBrqpgJWoJCIFX5TSAMhxly8AQR0orA zXuJNIgSWCCuIvRlJRfw5qpAmiJv818WIr+k7flgQ+6AJVQ3VF/i87Lsw7MsrQ12ab3E X7XAViZpqyb2cUoEPRNaCpw5AHwL3fpu/kCw2a6MmfY80uJpNRaBzEd2fvlZ4bW9Gd5E gR3g== X-Gm-Message-State: AGi0PuY7m5HBE7gDo9B5hWy59cQ9RR8pmtIFE3Zn5gbIHPwQgZbBVBv2 4V6Q2YxOazGBG/sJ8hSi6gYXaCDb X-Google-Smtp-Source: APiQypIq0teR1dqbI017hMAPArLX1YQcSJL582+k6ndZbsm5yk1fNXn7hqZtHHwT4Fzm15VxTjIr9Q== X-Received: by 2002:aa7:8091:: with SMTP id v17mr8804803pff.93.1589043422005; Sat, 09 May 2020 09:57:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:370c:: with SMTP id u12ls14082780pjb.2.gmail; Sat, 09 May 2020 09:57:01 -0700 (PDT) X-Received: by 2002:a17:90a:df88:: with SMTP id p8mr12706465pjv.119.1589043421490; Sat, 09 May 2020 09:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589043421; cv=none; d=google.com; s=arc-20160816; b=qgoNa3TQpYKDN5EXvd+T7Pj2Rw5RtRcA/AFlYV5dD+gZu4FE7P7f+ar53ge7bwiOw2 wajFvUvu7S48mw8j+XP6Q9JRSWfRA0e/iewo24L5VueyRQos0eO4Le//2subWiAaO4F4 Fs5rReZkyQalWr9ueU2MyYg14xkAVEQargDOfY+O4cu+ihb0drbPbti6q7t8z1qRjROc yJ4+TnJ6lVb/Puy5IPYyrZcenUHtGsQzukBs34tT2ZWjHpuhyiVgtBFLXenGkrSMTloc eZx+4mylqD8em9mvYLPINPIrLH3ovJSrg10itIwieK6uF06a8ZXEd0CYTqTR9SFXsq1w rJJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w1+4+CJrzNg5N4mpMXT03HS2s/9IoOPydovCrS5cuzQ=; b=JaqELorOGBhHzwPk0bPg6wkGrXz8ZJuK6TdgzAa3HutvkwQFlca1Xb94vBGNUBSa0f AAzbjepkk32ACIUUocR0ELp0ApbjCk+baBDN7opfIRZ79Y8gr2NYVLjT9jOHRqSppmeW 0a7msLiuX6RQd3o0kOyY27cHclxw04L/dofd7amrqpd9LgyEh1OskcAvyFAnhbf1eEMG j2ANjrv9V6zEqqYl01y+1y22Lf7QWtuabvtRw0I9xOxHJyq9WD9bQ7Mbp0bzqaVeGU7f wYg+YVqTrZVfxf5SrVVH54Vg4P3URLmZzou1BqhO/qVKyk1bPzG6a6zDoXGMajs/Ac2r c1bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZqH+XTOL; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s1sor9244354pjo.29.2020.05.09.09.57.01 for (Google Transport Security); Sat, 09 May 2020 09:57:01 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90b:4d09:: with SMTP id mw9mr13052220pjb.55.1589043421225; Sat, 09 May 2020 09:57:01 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:21f6:1c8f:ae94:fb04]) by smtp.gmail.com with ESMTPSA id x195sm4977098pfc.0.2020.05.09.09.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 09:57:00 -0700 (PDT) From: Jagan Teki To: Kever Yang , Simon Glass , Philipp Tomsich Cc: shawn.lin@rock-chips.com, patrick@blueri.se, sunil@amarulasolutions.com, u-boot@lists.denx.de, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki , Tom Cubie Subject: [PATCH v3 6/6] rockchip: Enable PCIe/M.2 on rock960 board Date: Sat, 9 May 2020 22:26:24 +0530 Message-Id: <20200509165624.20791-7-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200509165624.20791-1-jagan@amarulasolutions.com> References: <20200509165624.20791-1-jagan@amarulasolutions.com> X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZqH+XTOL; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Due to board limitation some SSD's would work on rock960 PCIe M.2 only with 1.8V IO domain. So, this patch enables grf io_sel explicitly to make PCIe/M.2 to work. Cc: Tom Cubie Signed-off-by: Jagan Teki Acked-by: Manivannan Sadhasivam Reviewed-by: Kever Yang --- Changes for v3: - collect mani a-b - add comments board/vamrs/rock960_rk3399/rock960-rk3399.c | 23 +++++++++++++++++++++ configs/rock960-rk3399_defconfig | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/board/vamrs/rock960_rk3399/rock960-rk3399.c b/board/vamrs/rock960_rk3399/rock960-rk3399.c index 68a127b9ac..ef1eb2d0b7 100644 --- a/board/vamrs/rock960_rk3399/rock960-rk3399.c +++ b/board/vamrs/rock960_rk3399/rock960-rk3399.c @@ -2,3 +2,26 @@ /* * Copyright (C) 2018 Manivannan Sadhasivam */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_MISC_INIT_R +int misc_init_r(void) +{ + struct rk3399_grf_regs *grf = + syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + + /** + * Some SSD's to work on rock960 would require explicit + * domain voltage change, so BT565 is in 1.8v domain + */ + rk_setreg(&grf->io_vsel, BIT(0)); + + return 0; +} +#endif diff --git a/configs/rock960-rk3399_defconfig b/configs/rock960-rk3399_defconfig index 045d989a19..64517f9623 100644 --- a/configs/rock960-rk3399_defconfig +++ b/configs/rock960-rk3399_defconfig @@ -9,6 +9,7 @@ CONFIG_DEBUG_UART_BASE=0xFF1A0000 CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_DEBUG_UART=y CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-rock960.dtb" +CONFIG_MISC_INIT_R=y CONFIG_DISPLAY_BOARDINFO_LATE=y # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set CONFIG_SPL_STACK_R=y @@ -19,6 +20,7 @@ CONFIG_CMD_BOOTZ=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_USB=y +CONFIG_CMD_PCI=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_CMD_PMIC=y @@ -36,10 +38,13 @@ CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_SDMA=y CONFIG_MMC_SDHCI_ROCKCHIP=y CONFIG_DM_ETH=y +CONFIG_NVME=y +CONFIG_PCI=y CONFIG_PMIC_RK8XX=y CONFIG_REGULATOR_PWM=y CONFIG_REGULATOR_RK8XX=y CONFIG_PWM_ROCKCHIP=y +CONFIG_DM_RESET=y CONFIG_BAUDRATE=1500000 CONFIG_DEBUG_UART_SHIFT=2 CONFIG_SYSRESET=y