Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4658611pxb; Tue, 28 Sep 2021 00:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRmNPojMH0Wd3zmv1SnsnI9ArWOBvIrAVjHNuQqIQ29r+q8SShVO/tKe07r8Dc89caF8YO X-Received: by 2002:a50:cf08:: with SMTP id c8mr5904432edk.86.1632814681784; Tue, 28 Sep 2021 00:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632814681; cv=none; d=google.com; s=arc-20160816; b=emNczaLF3omtWp3+OqR4QIN5ARGHfS+3/Ix65OpajJOtLU/20jLS2qhpfRseMC5iAB +cvuZtUNaOR8fgsap+A54TiCOEoZBpB5T2KQKvuwTm1Xg/tskZpNsVTT+m6wVCXp6RQU jv+i4cXr/qnV3jOT1LX/O4mvYQJU45PJhlXlX0Pv2dPgNxHqOQrcYtxfL/1qAV2gKg+B mGoED/MWmDXklnNVJIb7WRzGQJY/gJRbwdXSdnarY4yTnIuXYFQXQNL4y/RkdaPbke4I g4a5EaL4p1zWwUUqKm6iNHJVUpES6rMUrngGlYLn6hZ3bS5UNWBvQoYrWU1RJk/J2T1q c/CQ== 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=7IHZkVnfQFYQxTSxpm+pehG3AQQ0IqaDcEIO9WAcEks=; b=Foz0sU5pzI1DqwCczq7J77ykuTORIWQr44hnTzHrnzmE5flJU2s+fmW7XlGtH7sowE 1uGM9/FunDbVzC+kjFMLDqkBLkg/JwJKOtEKIbvDuqBuS1zwBML5gbkUwoUZb26kjJj4 fLyLS9vsgdoT4roliLRSxA9fcpXMai1Ek7m3ibgE7GHdwtxOQ1hWSc19gCF4jD1pD/uL FQFZeuLta23o8xZl4rMMUmlqg0lRkyY7h7ZdNQt00wFPDRgXVmTs6tF5HIJAzihW85VQ /yWC5umTLddrTwquW8+j2g6Qmny4tEtp1nvi3zm/ZiYpU84Mwubigq64OaD6iK3vO5vA R7vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ab5uYkek; 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 v28si5581767ejk.172.2021.09.28.00.37.29; Tue, 28 Sep 2021 00:38:01 -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=Ab5uYkek; 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 S239348AbhI1HgG (ORCPT + 99 others); Tue, 28 Sep 2021 03:36:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:55864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239302AbhI1HgF (ORCPT ); Tue, 28 Sep 2021 03:36:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C7CF61139; Tue, 28 Sep 2021 07:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632814466; bh=HM2jF1Oiv6j6EtqGQGanbOWpjTPphw0OuWrZCfat04M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ab5uYkekUEQ5vPG/k7uKlmrO6MMelYNG41ZO12XS8id2IlF+NjVi3QOoccRUtwI0E Xn4w3UuQHoooAJkX+5mZ60MAieN4LGzVl8CjV20zVYKZv8/qnCwxK5Pt33lhNYBNip 27Xq/YsPsxg0WEErkPWfAuc1FrxYePY6FcAUXRrC4EUcaQTRVCHpVokaEoqGBwsk7G MaGpc5OzYGjFmn04D2zBtMqabGA9plyM+zd0tlHhJw5wesmLta9keyHmb6PyYN2yQN BJ8gFq+yyhIHe3Vy6x5VNRTVYEcFIKl7fIEUwXmkxcC4OCc59AWLCljUgSkkbslXvD ZgbDzLv4yBRkA== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mV7dA-000RPn-GK; Tue, 28 Sep 2021 09:34:24 +0200 From: Mauro Carvalho Chehab To: 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 v12 04/11] PCI: kirin: Use regmap for APB registers Date: Tue, 28 Sep 2021 09:34:14 +0200 Message-Id: <93454e50acaefd98b3d3c76826ac1ac173ab96e7.1632814194.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 --- To mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH v12 00/11] at: https://lore.kernel.org/all/cover.1632814194.git.mchehab+huawei@kernel.org/ 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