diff mbox series

[2/4] PCI: mediatek-gen3: Add mtk_pcie_soc data structure

Message ID a49a36c4ca336dee909e16865d6fec0dd83b3f38.1718980864.git.lorenzo@kernel.org
State New
Headers show
Series Add Airoha EN7581 PCIE support | expand

Commit Message

lorenzo@kernel.org June 21, 2024, 2:48 p.m. UTC
Introduce mtk_pcie_soc data structure in order to define multiple
callbacks for each supported SoC. This is a preliminary patch to
introduce EN7581 pcie support.

Tested-by: Zhengping Zhang <zhengping.zhang@airoha.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/pci/controller/pcie-mediatek-gen3.c | 24 ++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

AngeloGioacchino Del Regno June 24, 2024, 7:57 a.m. UTC | #1
Il 21/06/24 16:48, Lorenzo Bianconi ha scritto:
> Introduce mtk_pcie_soc data structure in order to define multiple
> callbacks for each supported SoC. This is a preliminary patch to
> introduce EN7581 pcie support.
> 
> Tested-by: Zhengping Zhang <zhengping.zhang@airoha.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>   drivers/pci/controller/pcie-mediatek-gen3.c | 24 ++++++++++++++++++---
>   1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
> index 975b3024fb08..4859bd875bc4 100644
> --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> +++ b/drivers/pci/controller/pcie-mediatek-gen3.c
> @@ -100,6 +100,16 @@
>   #define PCIE_ATR_TLP_TYPE_MEM		PCIE_ATR_TLP_TYPE(0)
>   #define PCIE_ATR_TLP_TYPE_IO		PCIE_ATR_TLP_TYPE(2)
>   
> +struct mtk_gen3_pcie;
> +
> +/**
> + * struct mtk_pcie_soc - differentiate between host generations

mtk_gen3_pcie_pdata ?

> + * @power_up: pcie power_up callback
> + */
> +struct mtk_pcie_soc {
> +	int (*power_up)(struct mtk_gen3_pcie *pcie);
> +};
> +
>   /**
>    * struct mtk_msi_set - MSI information for each set
>    * @base: IO mapped register base
> @@ -131,6 +141,7 @@ struct mtk_msi_set {
>    * @msi_sets: MSI sets information
>    * @lock: lock protecting IRQ bit map
>    * @msi_irq_in_use: bit map for assigned MSI IRQ
> + * @soc: pointer to SoC-dependent operations
>    */
>   struct mtk_gen3_pcie {
>   	struct device *dev;
> @@ -151,6 +162,8 @@ struct mtk_gen3_pcie {
>   	struct mtk_msi_set msi_sets[PCIE_MSI_SET_NUM];
>   	struct mutex lock;
>   	DECLARE_BITMAP(msi_irq_in_use, PCIE_MSI_IRQS_NUM);
> +
> +	const struct mtk_pcie_soc *soc;
>   };
>   
>   /* LTSSM state in PCIE_LTSSM_STATUS_REG bit[28:24] */
> @@ -904,7 +917,7 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie)
>   	usleep_range(10, 20);
>   
>   	/* Don't touch the hardware registers before power up */
> -	err = mtk_pcie_power_up(pcie);
> +	err = pcie->soc->power_up(pcie);
>   	if (err)
>   		return err;
>   
> @@ -939,6 +952,7 @@ static int mtk_pcie_probe(struct platform_device *pdev)
>   	pcie = pci_host_bridge_priv(host);
>   
>   	pcie->dev = dev;
> +	pcie->soc = of_device_get_match_data(dev);

device_get_match_data() can also be used here :-)

Cheers,
Angelo
lorenzo@kernel.org June 27, 2024, 6:50 a.m. UTC | #2
> Il 21/06/24 16:48, Lorenzo Bianconi ha scritto:
> > Introduce mtk_pcie_soc data structure in order to define multiple
> > callbacks for each supported SoC. This is a preliminary patch to
> > introduce EN7581 pcie support.
> > 
> > Tested-by: Zhengping Zhang <zhengping.zhang@airoha.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> >   drivers/pci/controller/pcie-mediatek-gen3.c | 24 ++++++++++++++++++---
> >   1 file changed, 21 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
> > index 975b3024fb08..4859bd875bc4 100644
> > --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> > +++ b/drivers/pci/controller/pcie-mediatek-gen3.c
> > @@ -100,6 +100,16 @@
> >   #define PCIE_ATR_TLP_TYPE_MEM		PCIE_ATR_TLP_TYPE(0)
> >   #define PCIE_ATR_TLP_TYPE_IO		PCIE_ATR_TLP_TYPE(2)
> > +struct mtk_gen3_pcie;
> > +
> > +/**
> > + * struct mtk_pcie_soc - differentiate between host generations
> 
> mtk_gen3_pcie_pdata ?

ack, I will fix it in v2.

> 
> > + * @power_up: pcie power_up callback
> > + */
> > +struct mtk_pcie_soc {
> > +	int (*power_up)(struct mtk_gen3_pcie *pcie);
> > +};
> > +
> >   /**
> >    * struct mtk_msi_set - MSI information for each set
> >    * @base: IO mapped register base
> > @@ -131,6 +141,7 @@ struct mtk_msi_set {
> >    * @msi_sets: MSI sets information
> >    * @lock: lock protecting IRQ bit map
> >    * @msi_irq_in_use: bit map for assigned MSI IRQ
> > + * @soc: pointer to SoC-dependent operations
> >    */
> >   struct mtk_gen3_pcie {
> >   	struct device *dev;
> > @@ -151,6 +162,8 @@ struct mtk_gen3_pcie {
> >   	struct mtk_msi_set msi_sets[PCIE_MSI_SET_NUM];
> >   	struct mutex lock;
> >   	DECLARE_BITMAP(msi_irq_in_use, PCIE_MSI_IRQS_NUM);
> > +
> > +	const struct mtk_pcie_soc *soc;
> >   };
> >   /* LTSSM state in PCIE_LTSSM_STATUS_REG bit[28:24] */
> > @@ -904,7 +917,7 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie)
> >   	usleep_range(10, 20);
> >   	/* Don't touch the hardware registers before power up */
> > -	err = mtk_pcie_power_up(pcie);
> > +	err = pcie->soc->power_up(pcie);
> >   	if (err)
> >   		return err;
> > @@ -939,6 +952,7 @@ static int mtk_pcie_probe(struct platform_device *pdev)
> >   	pcie = pci_host_bridge_priv(host);
> >   	pcie->dev = dev;
> > +	pcie->soc = of_device_get_match_data(dev);
> 
> device_get_match_data() can also be used here :-)

ack, I will fix it in v2.

Regards,
Lorenzo

> 
> Cheers,
> Angelo
>
diff mbox series

Patch

diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index 975b3024fb08..4859bd875bc4 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -100,6 +100,16 @@ 
 #define PCIE_ATR_TLP_TYPE_MEM		PCIE_ATR_TLP_TYPE(0)
 #define PCIE_ATR_TLP_TYPE_IO		PCIE_ATR_TLP_TYPE(2)
 
+struct mtk_gen3_pcie;
+
+/**
+ * struct mtk_pcie_soc - differentiate between host generations
+ * @power_up: pcie power_up callback
+ */
+struct mtk_pcie_soc {
+	int (*power_up)(struct mtk_gen3_pcie *pcie);
+};
+
 /**
  * struct mtk_msi_set - MSI information for each set
  * @base: IO mapped register base
@@ -131,6 +141,7 @@  struct mtk_msi_set {
  * @msi_sets: MSI sets information
  * @lock: lock protecting IRQ bit map
  * @msi_irq_in_use: bit map for assigned MSI IRQ
+ * @soc: pointer to SoC-dependent operations
  */
 struct mtk_gen3_pcie {
 	struct device *dev;
@@ -151,6 +162,8 @@  struct mtk_gen3_pcie {
 	struct mtk_msi_set msi_sets[PCIE_MSI_SET_NUM];
 	struct mutex lock;
 	DECLARE_BITMAP(msi_irq_in_use, PCIE_MSI_IRQS_NUM);
+
+	const struct mtk_pcie_soc *soc;
 };
 
 /* LTSSM state in PCIE_LTSSM_STATUS_REG bit[28:24] */
@@ -904,7 +917,7 @@  static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie)
 	usleep_range(10, 20);
 
 	/* Don't touch the hardware registers before power up */
-	err = mtk_pcie_power_up(pcie);
+	err = pcie->soc->power_up(pcie);
 	if (err)
 		return err;
 
@@ -939,6 +952,7 @@  static int mtk_pcie_probe(struct platform_device *pdev)
 	pcie = pci_host_bridge_priv(host);
 
 	pcie->dev = dev;
+	pcie->soc = of_device_get_match_data(dev);
 	platform_set_drvdata(pdev, pcie);
 
 	err = mtk_pcie_setup(pcie);
@@ -1054,7 +1068,7 @@  static int mtk_pcie_resume_noirq(struct device *dev)
 	struct mtk_gen3_pcie *pcie = dev_get_drvdata(dev);
 	int err;
 
-	err = mtk_pcie_power_up(pcie);
+	err = pcie->soc->power_up(pcie);
 	if (err)
 		return err;
 
@@ -1074,8 +1088,12 @@  static const struct dev_pm_ops mtk_pcie_pm_ops = {
 				  mtk_pcie_resume_noirq)
 };
 
+static const struct mtk_pcie_soc mtk_pcie_soc_mt8192 = {
+	.power_up = mtk_pcie_power_up,
+};
+
 static const struct of_device_id mtk_pcie_of_match[] = {
-	{ .compatible = "mediatek,mt8192-pcie" },
+	{ .compatible = "mediatek,mt8192-pcie", .data = &mtk_pcie_soc_mt8192 },
 	{},
 };
 MODULE_DEVICE_TABLE(of, mtk_pcie_of_match);