Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp413339pxt; Thu, 12 Aug 2021 01:08:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8e0Uuf0yBQr5+ieKTu0oEDH9CJ7z7jrF6uysSPZGiXSozUpzhzyBjyYNVNprb2JtIo7Nf X-Received: by 2002:a92:440c:: with SMTP id r12mr1955403ila.174.1628755697074; Thu, 12 Aug 2021 01:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628755697; cv=none; d=google.com; s=arc-20160816; b=xcbJX9JeZ7ThPkG9EdgvgMnr4VkvGomlfdx1t/lip6YMASkCM/HlPCIuoSuHJau2Dr WZW1F/iJT++EAhgL750snaH3Gsiz5EHxwK9h75ZRmKjPKsS4ME9dtG0SZ+Yqcw4M/Ko8 OfiCE60gervjqYosauGNVFJz0aBlDLGiWja7qyMrMWwTmfaOakUu2TfycA+aLqzkvcW1 UeafpSGcBRiL3z9slLWNoQqGxOo+MrhT73FsopxS13qx/p0Hj4MuRYWBx6XMKIllIdWI nl8X6ImFMdlfYiiXdi/1StZxw390lxtAok0wJyf417X/nolzTFhrrirlx9q+yuDlmHAO YVHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4/p+Rr/OqIl2m0S3yF+tdZf+7MJzP3RHFn3NTuKKq9c=; b=gJASztVns7wx66Yx13pCg1RX9uMpJsarOKAaGLmuKeLD4kXNdAKveAZxAO3FmcbcwJ mqdczhmi+3XYwqbjIk+Sl0ZcctCGcpjGP9uOHuaWwefEtkQQMrU53CYH/IaH0MAwkNBS o7FGKKHxHfRo4bJurNBlBz/sOH5GjfY7fBpZAxctqT7hpD3gcND0CpXgsayGCAc5gHvi rB/vW8ibjkCssVi6PbRqKc2tLtEr2EY1c2oa2lO1U9YGOPzZxsuXZBh4EwtOohTWa3tI t94N5xuIqQzqsokL7nVobD666bxjvgZra771joO5RukgDxr3bAFieKiFaQqeSsXN+/j/ SJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E6qEQ8YD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si1984260jar.80.2021.08.12.01.08.04; Thu, 12 Aug 2021 01:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E6qEQ8YD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235238AbhHLIEX (ORCPT + 99 others); Thu, 12 Aug 2021 04:04:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234573AbhHLICv (ORCPT ); Thu, 12 Aug 2021 04:02:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 821896104F; Thu, 12 Aug 2021 08:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628755345; bh=66pZf2o/BZ9yYQkTCPHEOmZBX2W7nSIdCxqcbr2roWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E6qEQ8YDkKEntxezDvhSa/u0vAaFFYAT0BFP1hikXCbSFpqGskVhrcYAFu229l+QC QMDEjWL5M4eyyySwldulIzQgRwx+iAgEGNyYLh0LAOWMRCwVjhBLiSK6EsOEg7C180 wZIdOxxvYAqZEiqBTXMjjJlTqD1xpggDbcsDmw1fhCYbU9Cy+tzga//dE33CjGPJfq Cu5wEcd5DTGTRt/T3HZBJ9RLE14h26BRzqGqNp3sxZ8cJRwP7otAiwoM2q5LST30HK DMjK2H6qp51lN3HPXm5OIiU8ACframoSB/uJ0v/W/rZK2Tm6OCap+YBDP8MkNp/Lyg EpwUc0zHNm0fg== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mE5fT-00DZCu-MT; Thu, 12 Aug 2021 10:02:23 +0200 From: Mauro Carvalho Chehab To: Vinod Koul , Bjorn Helgaas Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Binghui Wang , Lorenzo Pieralisi , Rob Herring , Xiaowei Song , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v11 04/11] PCI: kirin: Use regmap for APB registers Date: Thu, 12 Aug 2021 10:02:15 +0200 Message-Id: <15bd5aaeac54f0d9b5f7f5865116522013ec5d0d.1628755058.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The PHY layer need to access APB registers too, for Kirin 970. So, place them into a named regmap. Signed-off-by: Mauro Carvalho Chehab --- drivers/pci/controller/dwc/pcie-kirin.c | 49 +++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c index 31514a5d4bb4..0ea92a521e1c 100644 --- a/drivers/pci/controller/dwc/pcie-kirin.c +++ b/drivers/pci/controller/dwc/pcie-kirin.c @@ -61,8 +61,8 @@ struct kirin_pcie { enum pcie_kirin_phy_type type; struct dw_pcie *pci; + struct regmap *apb; struct phy *phy; - void __iomem *apb_base; void *phy_priv; /* only for PCIE_KIRIN_INTERNAL_PHY */ }; @@ -340,25 +340,27 @@ static int hi3660_pcie_phy_init(struct platform_device *pdev, * The non-PHY part starts here */ -/* Registers in PCIeCTRL */ -static inline void kirin_apb_ctrl_writel(struct kirin_pcie *kirin_pcie, - u32 val, u32 reg) -{ - writel(val, kirin_pcie->apb_base + reg); -} - -static inline u32 kirin_apb_ctrl_readl(struct kirin_pcie *kirin_pcie, u32 reg) -{ - return readl(kirin_pcie->apb_base + reg); -} +static const struct regmap_config pcie_kirin_regmap_conf = { + .name = "kirin_pcie_apb", + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, +}; static long kirin_pcie_get_resource(struct kirin_pcie *kirin_pcie, struct platform_device *pdev) { - kirin_pcie->apb_base = - devm_platform_ioremap_resource_byname(pdev, "apb"); - if (IS_ERR(kirin_pcie->apb_base)) - return PTR_ERR(kirin_pcie->apb_base); + struct device *dev = &pdev->dev; + void __iomem *apb_base; + + apb_base = devm_platform_ioremap_resource_byname(pdev, "apb"); + if (IS_ERR(apb_base)) + return PTR_ERR(apb_base); + + kirin_pcie->apb = devm_regmap_init_mmio(dev, apb_base, + &pcie_kirin_regmap_conf); + if (IS_ERR(kirin_pcie->apb)) + return PTR_ERR(kirin_pcie->apb); return 0; } @@ -368,13 +370,13 @@ static void kirin_pcie_sideband_dbi_w_mode(struct kirin_pcie *kirin_pcie, { u32 val; - val = kirin_apb_ctrl_readl(kirin_pcie, SOC_PCIECTRL_CTRL0_ADDR); + regmap_read(kirin_pcie->apb, SOC_PCIECTRL_CTRL0_ADDR, &val); if (on) val = val | PCIE_ELBI_SLV_DBI_ENABLE; else val = val & ~PCIE_ELBI_SLV_DBI_ENABLE; - kirin_apb_ctrl_writel(kirin_pcie, val, SOC_PCIECTRL_CTRL0_ADDR); + regmap_write(kirin_pcie->apb, SOC_PCIECTRL_CTRL0_ADDR, val); } static void kirin_pcie_sideband_dbi_r_mode(struct kirin_pcie *kirin_pcie, @@ -382,13 +384,13 @@ static void kirin_pcie_sideband_dbi_r_mode(struct kirin_pcie *kirin_pcie, { u32 val; - val = kirin_apb_ctrl_readl(kirin_pcie, SOC_PCIECTRL_CTRL1_ADDR); + regmap_read(kirin_pcie->apb, SOC_PCIECTRL_CTRL1_ADDR, &val); if (on) val = val | PCIE_ELBI_SLV_DBI_ENABLE; else val = val & ~PCIE_ELBI_SLV_DBI_ENABLE; - kirin_apb_ctrl_writel(kirin_pcie, val, SOC_PCIECTRL_CTRL1_ADDR); + regmap_write(kirin_pcie->apb, SOC_PCIECTRL_CTRL1_ADDR, val); } static int kirin_pcie_rd_own_conf(struct pci_bus *bus, unsigned int devfn, @@ -448,8 +450,9 @@ static void kirin_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, static int kirin_pcie_link_up(struct dw_pcie *pci) { struct kirin_pcie *kirin_pcie = to_kirin_pcie(pci); - u32 val = kirin_apb_ctrl_readl(kirin_pcie, PCIE_APB_PHY_STATUS0); + u32 val; + regmap_read(kirin_pcie->apb, PCIE_APB_PHY_STATUS0, &val); if ((val & PCIE_LINKUP_ENABLE) == PCIE_LINKUP_ENABLE) return 1; @@ -461,8 +464,8 @@ static int kirin_pcie_start_link(struct dw_pcie *pci) struct kirin_pcie *kirin_pcie = to_kirin_pcie(pci); /* assert LTSSM enable */ - kirin_apb_ctrl_writel(kirin_pcie, PCIE_LTSSM_ENABLE_BIT, - PCIE_APP_LTSSM_ENABLE); + regmap_write(kirin_pcie->apb, PCIE_APP_LTSSM_ENABLE, + PCIE_LTSSM_ENABLE_BIT); return 0; } -- 2.31.1