From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gabriele Paoloni Subject: [RFC PATCH v2 1/3] PCI: hisi: re-architect Hip05/Hip06 controllers driver to preapare for ACPI Date: Mon, 8 Feb 2016 12:41:02 +0000 Message-ID: <1454935264-6076-2-git-send-email-gabriele.paoloni@huawei.com> References: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> Sender: linux-pci-owner@vger.kernel.org To: guohanjun@huawei.com, wangzhou1@hisilicon.com, liudongdong3@huawei.com, linuxarm@huawei.com, qiujiang@huawei.com, bhelgaas@google.com, arnd@arndb.de, Lorenzo.Pieralisi@arm.com, tn@semihalf.com Cc: gabriele.paoloni@huawei.com, zhangjukuo@huawei.com, xuwei5@hisilicon.com, liguozhu@hisilicon.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, jcm@redhat.com List-Id: linux-acpi@vger.kernel.org From: gabriele paoloni re-architect the Hip05/Hip06 host controllers driver to prepare for the ACPI based driver. The common functions used also by the ACPI driver have been grouped into a new "common" file Signed-off-by: Gabriele Paoloni --- MAINTAINERS | 2 + drivers/pci/host/Makefile | 2 +- drivers/pci/host/pcie-hisi-common.c | 73 ++++++++++++++++++++++ drivers/pci/host/pcie-hisi.c | 119 +++++++++++------------------------- drivers/pci/host/pcie-hisi.h | 23 +++++++ 5 files changed, 135 insertions(+), 84 deletions(-) create mode 100644 drivers/pci/host/pcie-hisi-common.c create mode 100644 drivers/pci/host/pcie-hisi.h diff --git a/MAINTAINERS b/MAINTAINERS index 30aca4a..d69f436 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8409,7 +8409,9 @@ M: Gabriele Paoloni L: linux-pci@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/pci/hisilicon-pcie.txt +F: drivers/pci/host/pcie-hisi.h F: drivers/pci/host/pcie-hisi.c +F: drivers/pci/host/pcie-hisi-common.c PCIE DRIVER FOR QUALCOMM MSM M: Stanimir Varbanov diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile index 7b2f20c..8c93c0f 100644 --- a/drivers/pci/host/Makefile +++ b/drivers/pci/host/Makefile @@ -20,5 +20,5 @@ obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o -obj-$(CONFIG_PCI_HISI) += pcie-hisi.o +obj-$(CONFIG_PCI_HISI) += pcie-hisi.o pcie-hisi-common.o obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o diff --git a/drivers/pci/host/pcie-hisi-common.c b/drivers/pci/host/pcie-hisi-common.c new file mode 100644 index 0000000..6dfb4c3 --- /dev/null +++ b/drivers/pci/host/pcie-hisi-common.c @@ -0,0 +1,73 @@ +/* + * PCIe host controller common functions for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" +#include "pcie-hisi.h" + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val) +{ + u32 reg; + u32 reg_val; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + reg_val = readl(reg_base + reg); + + if (size == 1) + *val = *(u8 __force *) walker; + else if (size == 2) + *val = *(u16 __force *) walker; + else if (size == 4) + *val = reg_val; + else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val) +{ + u32 reg_val; + u32 reg; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + if (size == 4) + writel(val, reg_base + reg); + else if (size == 2) { + reg_val = readl(reg_base + reg); + *(u16 __force *) walker = val; + writel(val, reg_base + reg); + } else if (size == 1) { + reg_val = readl(reg_base + reg); + *(u8 __force *) walker = val; + writel(val, reg_base + reg); + } else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} diff --git a/drivers/pci/host/pcie-hisi.c b/drivers/pci/host/pcie-hisi.c index 3e98d4e..458d0f8 100644 --- a/drivers/pci/host/pcie-hisi.c +++ b/drivers/pci/host/pcie-hisi.c @@ -21,6 +21,7 @@ #include #include "pcie-designware.h" +#include "pcie-hisi.h" #define PCIE_LTSSM_LINKUP_STATE 0x11 #define PCIE_LTSSM_STATE_MASK 0x3F @@ -30,12 +31,6 @@ #define to_hisi_pcie(x) container_of(x, struct hisi_pcie, pp) -struct hisi_pcie; - -struct pcie_soc_ops { - int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); -}; - struct hisi_pcie { struct regmap *subctrl; void __iomem *reg_base; @@ -44,87 +39,24 @@ struct hisi_pcie { struct pcie_soc_ops *soc_ops; }; -static inline void hisi_pcie_apb_writel(struct hisi_pcie *pcie, - u32 val, u32 reg) -{ - writel(val, pcie->reg_base + reg); -} - -static inline u32 hisi_pcie_apb_readl(struct hisi_pcie *pcie, u32 reg) -{ - return readl(pcie->reg_base + reg); -} - -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_read(struct pcie_port *pp, int where, int size, - u32 *val) -{ - u32 reg; - u32 reg_val; - struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - reg_val = hisi_pcie_apb_readl(pcie, reg); - - if (size == 1) - *val = *(u8 __force *) walker; - else if (size == 2) - *val = *(u16 __force *) walker; - else if (size == 4) - *val = reg_val; - else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} +struct pcie_soc_ops { + int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); +}; -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_write(struct pcie_port *pp, int where, int size, - u32 val) +static inline int hisi_pcie_cfg_read(struct pcie_port *pp, int where, + int size, u32 *val) { - u32 reg_val; - u32 reg; struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - if (size == 4) - hisi_pcie_apb_writel(pcie, val, reg); - else if (size == 2) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u16 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else if (size == 1) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u8 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} -static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) -{ - u32 val; - - regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + - 0x100 * hisi_pcie->port_id, &val); - - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_read(pcie->reg_base, where, size, val); } -static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +static inline int hisi_pcie_cfg_write(struct pcie_port *pp, int where, + int size, u32 val) { - u32 val; - - val = hisi_pcie_apb_readl(hisi_pcie, PCIE_HIP06_CTRL_OFF + - PCIE_SYS_STATE4); + struct hisi_pcie *pcie = to_hisi_pcie(pp); - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_write(pcie->reg_base, where, size, val); } static int hisi_pcie_link_up(struct pcie_port *pp) @@ -134,12 +66,13 @@ static int hisi_pcie_link_up(struct pcie_port *pp) return hisi_pcie->soc_ops->hisi_pcie_link_up(hisi_pcie); } -static struct pcie_host_ops hisi_pcie_host_ops = { - .rd_own_conf = hisi_pcie_cfg_read, - .wr_own_conf = hisi_pcie_cfg_write, - .link_up = hisi_pcie_link_up, +struct pcie_host_ops hisi_pcie_host_ops = { + .rd_own_conf = hisi_pcie_cfg_read, + .wr_own_conf = hisi_pcie_cfg_write, + .link_up = hisi_pcie_link_up, }; + static int hisi_add_pcie_port(struct pcie_port *pp, struct platform_device *pdev) { @@ -215,6 +148,26 @@ static int hisi_pcie_probe(struct platform_device *pdev) return 0; } +static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + + 0x100 * hisi_pcie->port_id, &val); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + +static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + val = readl(hisi_pcie->reg_base + PCIE_HIP06_CTRL_OFF + + PCIE_SYS_STATE4); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + static struct pcie_soc_ops hip05_ops = { &hisi_pcie_link_up_hip05 }; diff --git a/drivers/pci/host/pcie-hisi.h b/drivers/pci/host/pcie-hisi.h new file mode 100644 index 0000000..29e0790 --- /dev/null +++ b/drivers/pci/host/pcie-hisi.h @@ -0,0 +1,23 @@ +/* + * PCIe host controller driver for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef PCIE_HISI_H_ +#define PCIE_HISI_H_ + + +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val); +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val); + +#endif /* PCIE_HISI_H_ */ -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751327AbcBHMm0 (ORCPT ); Mon, 8 Feb 2016 07:42:26 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:9044 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750781AbcBHMmX (ORCPT ); Mon, 8 Feb 2016 07:42:23 -0500 From: Gabriele Paoloni To: , , , , , , , , CC: , , , , , , , , Subject: [RFC PATCH v2 1/3] PCI: hisi: re-architect Hip05/Hip06 controllers driver to preapare for ACPI Date: Mon, 8 Feb 2016 12:41:02 +0000 Message-ID: <1454935264-6076-2-git-send-email-gabriele.paoloni@huawei.com> X-Mailer: git-send-email 2.7.1.windows.1 In-Reply-To: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> References: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.203.181.156] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.56B88D1A.00EB,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 1b48228dcc5ec2dda0d5f1636b69e3dd Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: gabriele paoloni re-architect the Hip05/Hip06 host controllers driver to prepare for the ACPI based driver. The common functions used also by the ACPI driver have been grouped into a new "common" file Signed-off-by: Gabriele Paoloni --- MAINTAINERS | 2 + drivers/pci/host/Makefile | 2 +- drivers/pci/host/pcie-hisi-common.c | 73 ++++++++++++++++++++++ drivers/pci/host/pcie-hisi.c | 119 +++++++++++------------------------- drivers/pci/host/pcie-hisi.h | 23 +++++++ 5 files changed, 135 insertions(+), 84 deletions(-) create mode 100644 drivers/pci/host/pcie-hisi-common.c create mode 100644 drivers/pci/host/pcie-hisi.h diff --git a/MAINTAINERS b/MAINTAINERS index 30aca4a..d69f436 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8409,7 +8409,9 @@ M: Gabriele Paoloni L: linux-pci@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/pci/hisilicon-pcie.txt +F: drivers/pci/host/pcie-hisi.h F: drivers/pci/host/pcie-hisi.c +F: drivers/pci/host/pcie-hisi-common.c PCIE DRIVER FOR QUALCOMM MSM M: Stanimir Varbanov diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile index 7b2f20c..8c93c0f 100644 --- a/drivers/pci/host/Makefile +++ b/drivers/pci/host/Makefile @@ -20,5 +20,5 @@ obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o -obj-$(CONFIG_PCI_HISI) += pcie-hisi.o +obj-$(CONFIG_PCI_HISI) += pcie-hisi.o pcie-hisi-common.o obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o diff --git a/drivers/pci/host/pcie-hisi-common.c b/drivers/pci/host/pcie-hisi-common.c new file mode 100644 index 0000000..6dfb4c3 --- /dev/null +++ b/drivers/pci/host/pcie-hisi-common.c @@ -0,0 +1,73 @@ +/* + * PCIe host controller common functions for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" +#include "pcie-hisi.h" + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val) +{ + u32 reg; + u32 reg_val; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + reg_val = readl(reg_base + reg); + + if (size == 1) + *val = *(u8 __force *) walker; + else if (size == 2) + *val = *(u16 __force *) walker; + else if (size == 4) + *val = reg_val; + else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val) +{ + u32 reg_val; + u32 reg; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + if (size == 4) + writel(val, reg_base + reg); + else if (size == 2) { + reg_val = readl(reg_base + reg); + *(u16 __force *) walker = val; + writel(val, reg_base + reg); + } else if (size == 1) { + reg_val = readl(reg_base + reg); + *(u8 __force *) walker = val; + writel(val, reg_base + reg); + } else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} diff --git a/drivers/pci/host/pcie-hisi.c b/drivers/pci/host/pcie-hisi.c index 3e98d4e..458d0f8 100644 --- a/drivers/pci/host/pcie-hisi.c +++ b/drivers/pci/host/pcie-hisi.c @@ -21,6 +21,7 @@ #include #include "pcie-designware.h" +#include "pcie-hisi.h" #define PCIE_LTSSM_LINKUP_STATE 0x11 #define PCIE_LTSSM_STATE_MASK 0x3F @@ -30,12 +31,6 @@ #define to_hisi_pcie(x) container_of(x, struct hisi_pcie, pp) -struct hisi_pcie; - -struct pcie_soc_ops { - int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); -}; - struct hisi_pcie { struct regmap *subctrl; void __iomem *reg_base; @@ -44,87 +39,24 @@ struct hisi_pcie { struct pcie_soc_ops *soc_ops; }; -static inline void hisi_pcie_apb_writel(struct hisi_pcie *pcie, - u32 val, u32 reg) -{ - writel(val, pcie->reg_base + reg); -} - -static inline u32 hisi_pcie_apb_readl(struct hisi_pcie *pcie, u32 reg) -{ - return readl(pcie->reg_base + reg); -} - -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_read(struct pcie_port *pp, int where, int size, - u32 *val) -{ - u32 reg; - u32 reg_val; - struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - reg_val = hisi_pcie_apb_readl(pcie, reg); - - if (size == 1) - *val = *(u8 __force *) walker; - else if (size == 2) - *val = *(u16 __force *) walker; - else if (size == 4) - *val = reg_val; - else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} +struct pcie_soc_ops { + int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); +}; -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_write(struct pcie_port *pp, int where, int size, - u32 val) +static inline int hisi_pcie_cfg_read(struct pcie_port *pp, int where, + int size, u32 *val) { - u32 reg_val; - u32 reg; struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - if (size == 4) - hisi_pcie_apb_writel(pcie, val, reg); - else if (size == 2) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u16 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else if (size == 1) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u8 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} -static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) -{ - u32 val; - - regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + - 0x100 * hisi_pcie->port_id, &val); - - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_read(pcie->reg_base, where, size, val); } -static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +static inline int hisi_pcie_cfg_write(struct pcie_port *pp, int where, + int size, u32 val) { - u32 val; - - val = hisi_pcie_apb_readl(hisi_pcie, PCIE_HIP06_CTRL_OFF + - PCIE_SYS_STATE4); + struct hisi_pcie *pcie = to_hisi_pcie(pp); - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_write(pcie->reg_base, where, size, val); } static int hisi_pcie_link_up(struct pcie_port *pp) @@ -134,12 +66,13 @@ static int hisi_pcie_link_up(struct pcie_port *pp) return hisi_pcie->soc_ops->hisi_pcie_link_up(hisi_pcie); } -static struct pcie_host_ops hisi_pcie_host_ops = { - .rd_own_conf = hisi_pcie_cfg_read, - .wr_own_conf = hisi_pcie_cfg_write, - .link_up = hisi_pcie_link_up, +struct pcie_host_ops hisi_pcie_host_ops = { + .rd_own_conf = hisi_pcie_cfg_read, + .wr_own_conf = hisi_pcie_cfg_write, + .link_up = hisi_pcie_link_up, }; + static int hisi_add_pcie_port(struct pcie_port *pp, struct platform_device *pdev) { @@ -215,6 +148,26 @@ static int hisi_pcie_probe(struct platform_device *pdev) return 0; } +static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + + 0x100 * hisi_pcie->port_id, &val); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + +static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + val = readl(hisi_pcie->reg_base + PCIE_HIP06_CTRL_OFF + + PCIE_SYS_STATE4); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + static struct pcie_soc_ops hip05_ops = { &hisi_pcie_link_up_hip05 }; diff --git a/drivers/pci/host/pcie-hisi.h b/drivers/pci/host/pcie-hisi.h new file mode 100644 index 0000000..29e0790 --- /dev/null +++ b/drivers/pci/host/pcie-hisi.h @@ -0,0 +1,23 @@ +/* + * PCIe host controller driver for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef PCIE_HISI_H_ +#define PCIE_HISI_H_ + + +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val); +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val); + +#endif /* PCIE_HISI_H_ */ -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: gabriele.paoloni@huawei.com (Gabriele Paoloni) Date: Mon, 8 Feb 2016 12:41:02 +0000 Subject: [RFC PATCH v2 1/3] PCI: hisi: re-architect Hip05/Hip06 controllers driver to preapare for ACPI In-Reply-To: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> References: <1454935264-6076-1-git-send-email-gabriele.paoloni@huawei.com> Message-ID: <1454935264-6076-2-git-send-email-gabriele.paoloni@huawei.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org From: gabriele paoloni re-architect the Hip05/Hip06 host controllers driver to prepare for the ACPI based driver. The common functions used also by the ACPI driver have been grouped into a new "common" file Signed-off-by: Gabriele Paoloni --- MAINTAINERS | 2 + drivers/pci/host/Makefile | 2 +- drivers/pci/host/pcie-hisi-common.c | 73 ++++++++++++++++++++++ drivers/pci/host/pcie-hisi.c | 119 +++++++++++------------------------- drivers/pci/host/pcie-hisi.h | 23 +++++++ 5 files changed, 135 insertions(+), 84 deletions(-) create mode 100644 drivers/pci/host/pcie-hisi-common.c create mode 100644 drivers/pci/host/pcie-hisi.h diff --git a/MAINTAINERS b/MAINTAINERS index 30aca4a..d69f436 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8409,7 +8409,9 @@ M: Gabriele Paoloni L: linux-pci at vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/pci/hisilicon-pcie.txt +F: drivers/pci/host/pcie-hisi.h F: drivers/pci/host/pcie-hisi.c +F: drivers/pci/host/pcie-hisi-common.c PCIE DRIVER FOR QUALCOMM MSM M: Stanimir Varbanov diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile index 7b2f20c..8c93c0f 100644 --- a/drivers/pci/host/Makefile +++ b/drivers/pci/host/Makefile @@ -20,5 +20,5 @@ obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o -obj-$(CONFIG_PCI_HISI) += pcie-hisi.o +obj-$(CONFIG_PCI_HISI) += pcie-hisi.o pcie-hisi-common.o obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o diff --git a/drivers/pci/host/pcie-hisi-common.c b/drivers/pci/host/pcie-hisi-common.c new file mode 100644 index 0000000..6dfb4c3 --- /dev/null +++ b/drivers/pci/host/pcie-hisi-common.c @@ -0,0 +1,73 @@ +/* + * PCIe host controller common functions for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" +#include "pcie-hisi.h" + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val) +{ + u32 reg; + u32 reg_val; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + reg_val = readl(reg_base + reg); + + if (size == 1) + *val = *(u8 __force *) walker; + else if (size == 2) + *val = *(u16 __force *) walker; + else if (size == 4) + *val = reg_val; + else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} + +/* HipXX PCIe host only supports 32-bit config access */ +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val) +{ + u32 reg_val; + u32 reg; + void *walker = ®_val; + + walker += (where & 0x3); + reg = where & ~0x3; + if (size == 4) + writel(val, reg_base + reg); + else if (size == 2) { + reg_val = readl(reg_base + reg); + *(u16 __force *) walker = val; + writel(val, reg_base + reg); + } else if (size == 1) { + reg_val = readl(reg_base + reg); + *(u8 __force *) walker = val; + writel(val, reg_base + reg); + } else + return PCIBIOS_BAD_REGISTER_NUMBER; + + return PCIBIOS_SUCCESSFUL; +} diff --git a/drivers/pci/host/pcie-hisi.c b/drivers/pci/host/pcie-hisi.c index 3e98d4e..458d0f8 100644 --- a/drivers/pci/host/pcie-hisi.c +++ b/drivers/pci/host/pcie-hisi.c @@ -21,6 +21,7 @@ #include #include "pcie-designware.h" +#include "pcie-hisi.h" #define PCIE_LTSSM_LINKUP_STATE 0x11 #define PCIE_LTSSM_STATE_MASK 0x3F @@ -30,12 +31,6 @@ #define to_hisi_pcie(x) container_of(x, struct hisi_pcie, pp) -struct hisi_pcie; - -struct pcie_soc_ops { - int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); -}; - struct hisi_pcie { struct regmap *subctrl; void __iomem *reg_base; @@ -44,87 +39,24 @@ struct hisi_pcie { struct pcie_soc_ops *soc_ops; }; -static inline void hisi_pcie_apb_writel(struct hisi_pcie *pcie, - u32 val, u32 reg) -{ - writel(val, pcie->reg_base + reg); -} - -static inline u32 hisi_pcie_apb_readl(struct hisi_pcie *pcie, u32 reg) -{ - return readl(pcie->reg_base + reg); -} - -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_read(struct pcie_port *pp, int where, int size, - u32 *val) -{ - u32 reg; - u32 reg_val; - struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - reg_val = hisi_pcie_apb_readl(pcie, reg); - - if (size == 1) - *val = *(u8 __force *) walker; - else if (size == 2) - *val = *(u16 __force *) walker; - else if (size == 4) - *val = reg_val; - else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} +struct pcie_soc_ops { + int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); +}; -/* HipXX PCIe host only supports 32-bit config access */ -static int hisi_pcie_cfg_write(struct pcie_port *pp, int where, int size, - u32 val) +static inline int hisi_pcie_cfg_read(struct pcie_port *pp, int where, + int size, u32 *val) { - u32 reg_val; - u32 reg; struct hisi_pcie *pcie = to_hisi_pcie(pp); - void *walker = ®_val; - - walker += (where & 0x3); - reg = where & ~0x3; - if (size == 4) - hisi_pcie_apb_writel(pcie, val, reg); - else if (size == 2) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u16 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else if (size == 1) { - reg_val = hisi_pcie_apb_readl(pcie, reg); - *(u8 __force *) walker = val; - hisi_pcie_apb_writel(pcie, reg_val, reg); - } else - return PCIBIOS_BAD_REGISTER_NUMBER; - - return PCIBIOS_SUCCESSFUL; -} -static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) -{ - u32 val; - - regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + - 0x100 * hisi_pcie->port_id, &val); - - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_read(pcie->reg_base, where, size, val); } -static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +static inline int hisi_pcie_cfg_write(struct pcie_port *pp, int where, + int size, u32 val) { - u32 val; - - val = hisi_pcie_apb_readl(hisi_pcie, PCIE_HIP06_CTRL_OFF + - PCIE_SYS_STATE4); + struct hisi_pcie *pcie = to_hisi_pcie(pp); - return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); + return hisi_pcie_common_cfg_write(pcie->reg_base, where, size, val); } static int hisi_pcie_link_up(struct pcie_port *pp) @@ -134,12 +66,13 @@ static int hisi_pcie_link_up(struct pcie_port *pp) return hisi_pcie->soc_ops->hisi_pcie_link_up(hisi_pcie); } -static struct pcie_host_ops hisi_pcie_host_ops = { - .rd_own_conf = hisi_pcie_cfg_read, - .wr_own_conf = hisi_pcie_cfg_write, - .link_up = hisi_pcie_link_up, +struct pcie_host_ops hisi_pcie_host_ops = { + .rd_own_conf = hisi_pcie_cfg_read, + .wr_own_conf = hisi_pcie_cfg_write, + .link_up = hisi_pcie_link_up, }; + static int hisi_add_pcie_port(struct pcie_port *pp, struct platform_device *pdev) { @@ -215,6 +148,26 @@ static int hisi_pcie_probe(struct platform_device *pdev) return 0; } +static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + regmap_read(hisi_pcie->subctrl, PCIE_SUBCTRL_SYS_STATE4_REG + + 0x100 * hisi_pcie->port_id, &val); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + +static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) +{ + u32 val; + + val = readl(hisi_pcie->reg_base + PCIE_HIP06_CTRL_OFF + + PCIE_SYS_STATE4); + + return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); +} + static struct pcie_soc_ops hip05_ops = { &hisi_pcie_link_up_hip05 }; diff --git a/drivers/pci/host/pcie-hisi.h b/drivers/pci/host/pcie-hisi.h new file mode 100644 index 0000000..29e0790 --- /dev/null +++ b/drivers/pci/host/pcie-hisi.h @@ -0,0 +1,23 @@ +/* + * PCIe host controller driver for HiSilicon SoCs + * + * Copyright (C) 2015 HiSilicon Co., Ltd. http://www.hisilicon.com + * + * Author: Zhou Wang + * Dacai Zhu + * Gabriele Paoloni + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef PCIE_HISI_H_ +#define PCIE_HISI_H_ + + +int hisi_pcie_common_cfg_read(void __iomem *reg_base, int where, int size, + u32 *val); +int hisi_pcie_common_cfg_write(void __iomem *reg_base, int where, int size, + u32 val); + +#endif /* PCIE_HISI_H_ */ -- 1.9.1