From patchwork Mon Mar 25 09:39:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 161067 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3750608jan; Mon, 25 Mar 2019 02:43:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxXFsGXy8LyDZz6OxiqfCtuhSHXI4CN2qH5kR9VxNRBzW3Dr2h3e+ccIfFR+6e2jcfcbWG X-Received: by 2002:a17:902:7c0f:: with SMTP id x15mr23624056pll.98.1553507021937; Mon, 25 Mar 2019 02:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553507021; cv=none; d=google.com; s=arc-20160816; b=NB5PUH+Bg2EyVV7QOqtSyHNwx8QH/Nl0McVcmSKrytAU5p+NP3ui1fQHQXyVeSIrFq X/3ZS8G9Sqa/ok4BcfXuJHPx+TFkI5HUqZXEKPvoPj9VTLsBADCo2xEpY42cfPZeUDTc CwFnzXRGQsIY8on7tNStmSli/ZQPnMrep74cE1FF2lCaHN6vNQfAd2lM7xZgCdItZEx8 X/uUO9ujEfiduWTxVtbgPAxM8fa+neoP4y3scggRkcC9qqgfB8ltcVNBwZhsHvjTVmke UiAwxRhrCaCP414gLvwC6JUbCB0Ey0Rri+7ZGBdLixVLPMXGNusT0KcX8priCTvcvYob lpDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=chMDM1S73N5348Ke4wiey3wF6sgdC3UveRlW6BwAUuY=; b=yjv7+LBi4w+sDKKGF+OgLRpW0tZ9Pj5VciljrGMtvhKLQRDXd3mU21qiaFI2sykf0t YMW4BG+1GlIIJXygvg7wxb5kB2v/ZBmyfJECe08zUx6zFfvgOZsmKDREoyZFKYxVAe6b /k2fcWVxwBTFujwgupFyrzlJKn+iAWJ4dgM3Tk346ZiiyQ4QjZwzxVljhh6X2wkak3o2 8gv15Bd7Vd5mBNGruVmOPtzbw27CYEtfFfVtbTQmAxZ4XyHunr98YVcIT2bd96fjFMn/ 9eFq8NYLjJgpEKizDAOdUEN4K4UGVezRH9JvXKqvq7wDch94UKi0CMmWN44ixVHKHsxy xxAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="XocAwBs/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si14578030pla.80.2019.03.25.02.43.41; Mon, 25 Mar 2019 02:43:41 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b="XocAwBs/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730711AbfCYJnk (ORCPT + 31 others); Mon, 25 Mar 2019 05:43:40 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:37620 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730377AbfCYJni (ORCPT ); Mon, 25 Mar 2019 05:43:38 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x2P9hJiE013307; Mon, 25 Mar 2019 04:43:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1553506999; bh=chMDM1S73N5348Ke4wiey3wF6sgdC3UveRlW6BwAUuY=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XocAwBs/92tYgDwGP41RltrF4uz0r5BUbqpDCAG58QkcqXggkGCKzL82SH9nYC73A Lm4dQP2MnHhaFAI5buWz/mMs4xXjXTkn3JFzwcnmxSEztoL58AnXevIN2J6bFZ0y5W eyGqvnHdLmiD3W3nd+U0xQiqifw72L6AGmRRNgn8= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x2P9hJLt015902 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 25 Mar 2019 04:43:19 -0500 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Mon, 25 Mar 2019 04:43:19 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5 via Frontend Transport; Mon, 25 Mar 2019 04:43:19 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x2P9feaW028077; Mon, 25 Mar 2019 04:43:14 -0500 From: Kishon Vijay Abraham I To: Gustavo Pimentel , Bjorn Helgaas , Rob Herring , Lorenzo Pieralisi , Arnd Bergmann , Murali Karicheri CC: Kishon Vijay Abraham I , Jingoo Han , Greg Kroah-Hartman , , , , , , , Minghuan Lian , Mingkai Hu , Roy Zang , Jesper Nilsson Subject: [PATCH v3 17/26] PCI: keystone: Add support to set the max link speed from DT Date: Mon, 25 Mar 2019 15:09:38 +0530 Message-ID: <20190325093947.32633-18-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325093947.32633-1-kishon@ti.com> References: <20190325093947.32633-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PCIe in TI's AM654 devices is by default configured to work in GEN3 mode. However PCIe doesn't work reliably in GEN3 mode because of SERDES configuration. Add support to set the link speed to GEN1, GEN2 or GEN3 based on "max-link-speed" dt property with GEN2 as the default speed if "max-link-speed" is absent. Signed-off-by: Kishon Vijay Abraham I --- drivers/pci/controller/dwc/pci-keystone.c | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) -- 2.17.1 diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c index e4a816f53b8e..312fd0c49bbb 100644 --- a/drivers/pci/controller/dwc/pci-keystone.c +++ b/drivers/pci/controller/dwc/pci-keystone.c @@ -28,6 +28,7 @@ #include #include +#include "../../pci.h" #include "pcie-designware.h" #define PCIE_VENDORID_MASK 0xffff @@ -89,6 +90,8 @@ #define LEG_EP 0x1 #define RC 0x2 +#define EXP_CAP_ID_OFFSET 0x70 + #define KS_PCIE_SYSCLOCKOUTEN BIT(0) #define AM654_PCIE_DEV_TYPE_MASK 0x3 @@ -971,6 +974,31 @@ static int ks_pcie_am654_set_mode(struct device *dev) return 0; } +static void ks_pcie_set_link_speed(struct dw_pcie *pci, int link_speed) +{ + u32 val; + + dw_pcie_dbi_ro_wr_en(pci); + + val = dw_pcie_readl_dbi(pci, EXP_CAP_ID_OFFSET + PCI_EXP_LNKCAP); + if ((val & PCI_EXP_LNKCAP_SLS) != link_speed) { + val &= ~((u32)PCI_EXP_LNKCAP_SLS); + val |= link_speed; + dw_pcie_writel_dbi(pci, EXP_CAP_ID_OFFSET + PCI_EXP_LNKCAP, + val); + } + + val = dw_pcie_readl_dbi(pci, EXP_CAP_ID_OFFSET + PCI_EXP_LNKCTL2); + if ((val & PCI_EXP_LNKCAP_SLS) != link_speed) { + val &= ~((u32)PCI_EXP_LNKCAP_SLS); + val |= link_speed; + dw_pcie_writel_dbi(pci, EXP_CAP_ID_OFFSET + PCI_EXP_LNKCTL2, + val); + } + + dw_pcie_dbi_ro_wr_dis(pci); +} + static const struct ks_pcie_of_data ks_pcie_rc_of_data = { .host_ops = &ks_pcie_host_ops, .version = 0x365A, @@ -1011,6 +1039,7 @@ static int __init ks_pcie_probe(struct platform_device *pdev) void __iomem *base; u32 num_viewport; struct phy **phy; + int link_speed; u32 num_lanes; char name[10]; int ret; @@ -1165,6 +1194,12 @@ static int __init ks_pcie_probe(struct platform_device *pdev) gpiod_set_value_cansleep(gpiod, 1); } + link_speed = of_pci_get_max_link_speed(np); + if (link_speed < 0) + link_speed = 2; + + ks_pcie_set_link_speed(pci, link_speed); + pci->pp.ops = host_ops; ret = ks_pcie_add_pcie_port(ks_pcie, pdev); if (ret < 0)