Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp205430pxt; Wed, 4 Aug 2021 09:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9TKLlggQjxUlUQdRVuYqUnZ2rON5SZ9kooWwxeZS4co59+M30bICmwyGv+x4KKIes6Tmq X-Received: by 2002:a17:906:c251:: with SMTP id bl17mr26594429ejb.219.1628093128015; Wed, 04 Aug 2021 09:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628093128; cv=none; d=google.com; s=arc-20160816; b=tbWcCZd5TLh0Oqz0iOVfHoy5W4GvAX3ciyeTxuCKuq1veUn8WqWL525vaofeZc6usf jg5/sHZII9piU0OqKk4Gyfn1ReoPqKxCkDqtPm9YV9M0G1moc8/cyavMpp5Ia1fdxQ7z n5vsl4IfOUmbw1yXno+tP7KpiRKYfvaPyoEiWBdnmsPJJpid7UrPGxVdX/Ljsa5bI8NH +Ev7OzU5n0JlOAr3bs2SR4TDYQsXmedmGLNz6SkG3VOlnBKXiQivhdbGZqCoMjoAfbEC 2Yl5MVy+Ep4PcFbtoTBaQV5Cu5hwpa5+gN8v82FxHu6+yuYxhH3T3M7psckrRtl2wYAF vKgQ== 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=GSdtMZE5A5FAyS8P667Xv+Pjd99pDdXzbLoc7sDQYqZAWfzMZQ1RPr9mAYRqIi3s/U hpN0wXfMawLqA0luZ9hi5T2IeYQZuvyxhfnzu6FV07dy+myjBDOEiSobqpA25ywdoMU9 F0IBKnhxrIiR0J9HPLKi3rMgyeQeSPqyCdE5KcjguNGBYoaxcWM03bADWUFxQDiz4Srr 15DEOSqGpmRT/5pV39UiVWb15ajFucABkJ5dCHJmd4HBVhtePaJsbY4BYIqjZV7aqClH 0ZNz7gsmrNbn3b3jjNCUAOmFg5YR5P5G4/aJHitdyv96zrLcq3NgoaExscfUgYBtQAzq Hicw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gH+gp0tH; 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 mp36si2500850ejc.478.2021.08.04.09.04.58; Wed, 04 Aug 2021 09:05:28 -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=gH+gp0tH; 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 S233399AbhHDQDb (ORCPT + 99 others); Wed, 4 Aug 2021 12:03:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:58886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbhHDQDX (ORCPT ); Wed, 4 Aug 2021 12:03:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 68E4461004; Wed, 4 Aug 2021 16:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628092990; bh=66pZf2o/BZ9yYQkTCPHEOmZBX2W7nSIdCxqcbr2roWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gH+gp0tHKb95KTVM8eVGNEnJOrp393fC9IYy1dYGm8wZF10KoEolL+XDDlmZG8xgp 66BR8/+sd6pR+lh+qAKUib6Pt+AAUV+uNfQDRvq3Oi6C8qO1JoU7ffIDFiaAh4hA3d Zbezall36QWGVu/PnmuvjaIl3Izxh4ECq0yXZMOeUkdA3wFGBiW6bPAql9ftARAsjf C6wa/Bq37RgOvdW4TyfS/1D+zvE1q3HZ/u9XeaOWErrYD/nalHQGlndRtvho85Qgin 590LsPZX17jR14tbGFVetrwva1pd7f64nWOWxvefRvuWkpU9848UjWV3fYvyOLvawz n+rtnXu7KKxtg== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mBJMK-000PzX-Gk; Wed, 04 Aug 2021 18:03:08 +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?= , "Rob Herring" , Binghui Wang , Lorenzo Pieralisi , Xiaowei Song , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v9 04/11] PCI: kirin: Use regmap for APB registers Date: Wed, 4 Aug 2021 18:03:00 +0200 Message-Id: <5367172faed3dbd29987db733998fded2a307297.1628092716.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