diff mbox series

[v2,03/20] drviers: crypto: meson: add platform data

Message ID 20240123165831.970023-4-avromanov@salutedevices.com (mailing list archive)
State Superseded
Headers show
Series Support more Amlogic SoC families in crypto driver | expand

Commit Message

Alexey Romanov Jan. 23, 2024, 4:58 p.m. UTC
To support other Amlogic SoC's we have to
use platform data: descriptors and status registers
offsets are individual for each SoC series.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
---
 drivers/crypto/amlogic/amlogic-gxl-cipher.c |  2 +-
 drivers/crypto/amlogic/amlogic-gxl-core.c   | 31 +++++++++++++++------
 drivers/crypto/amlogic/amlogic-gxl.h        | 11 ++++++++
 3 files changed, 35 insertions(+), 9 deletions(-)

Comments

Corentin Labbe Jan. 24, 2024, 7:30 a.m. UTC | #1
Le Tue, Jan 23, 2024 at 07:58:14PM +0300, Alexey Romanov a écrit :
> To support other Amlogic SoC's we have to
> use platform data: descriptors and status registers
> offsets are individual for each SoC series.
> 
> Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
> ---
>  drivers/crypto/amlogic/amlogic-gxl-cipher.c |  2 +-
>  drivers/crypto/amlogic/amlogic-gxl-core.c   | 31 +++++++++++++++------
>  drivers/crypto/amlogic/amlogic-gxl.h        | 11 ++++++++
>  3 files changed, 35 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> index b19032f92415..7eff3ae7356f 100644
> --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> @@ -225,7 +225,7 @@ static int meson_cipher(struct skcipher_request *areq)
>  
>  	reinit_completion(&mc->chanlist[flow].complete);
>  	mc->chanlist[flow].status = 0;
> -	writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2));
> +	writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2));
>  	wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
>  						  msecs_to_jiffies(500));
>  	if (mc->chanlist[flow].status == 0) {
> diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
> index a58644be76e9..2be381e157c4 100644
> --- a/drivers/crypto/amlogic/amlogic-gxl-core.c
> +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
> @@ -18,6 +18,7 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> +#include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  
>  #include "amlogic-gxl.h"
> @@ -30,9 +31,10 @@ static irqreturn_t meson_irq_handler(int irq, void *data)
>  
>  	for (flow = 0; flow < mc->flow_cnt; flow++) {
>  		if (mc->chanlist[flow].irq == irq) {
> -			p = readl(mc->base + ((0x04 + flow) << 2));
> +			p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2));
>  			if (p) {
> -				writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2));
> +				writel_relaxed(0xF, mc->base +
> +					      ((mc->pdata->status_reg + flow) << 2));
>  				mc->chanlist[flow].status = 1;
>  				complete(&mc->chanlist[flow].complete);
>  				return IRQ_HANDLED;
> @@ -245,15 +247,34 @@ static void meson_unregister_algs(struct meson_dev *mc)
>  	}
>  }
>  
> +static const struct meson_pdata meson_gxl_pdata = {
> +	.descs_reg = 0x0,
> +	.status_reg = 0x4,
> +};
> +
> +static const struct of_device_id meson_crypto_of_match_table[] = {
> +	{
> +		.compatible = "amlogic,gxl-crypto",
> +		.data = &meson_gxl_pdata,
> +	},
> +	{},
> +};
> +
>  static int meson_crypto_probe(struct platform_device *pdev)
>  {
> +	const struct of_device_id *match;
>  	struct meson_dev *mc;
>  	int err;
>  
> +	match = of_match_device(meson_crypto_of_match_table, &pdev->dev);
> +	if (!match)
> +		return -EINVAL;
> +
>  	mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
>  	if (!mc)
>  		return -ENOMEM;
>  
> +	mc->pdata = match->data;
>  	mc->dev = &pdev->dev;
>  	platform_set_drvdata(pdev, mc);
>  
> @@ -312,12 +333,6 @@ static void meson_crypto_remove(struct platform_device *pdev)
>  	clk_disable_unprepare(mc->busclk);
>  }
>  
> -static const struct of_device_id meson_crypto_of_match_table[] = {
> -	{ .compatible = "amlogic,gxl-crypto", },
> -	{}
> -};
> -MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table);

Hello

This patch breaks bisection, since it removes MODULE_DEVICE_TABLE.
After applying patchs 1,2,3 the driver does not load anymore on lepotato board.

Regards
Alexey Romanov Feb. 1, 2024, 5:13 p.m. UTC | #2
Hello,

On Wed, Jan 24, 2024 at 08:30:48AM +0100, Corentin Labbe wrote:
> Le Tue, Jan 23, 2024 at 07:58:14PM +0300, Alexey Romanov a 'ecrit :
> > To support other Amlogic SoC's we have to
> > use platform data: descriptors and status registers
> > offsets are individual for each SoC series.
> > 
> > Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
> > ---
> >  drivers/crypto/amlogic/amlogic-gxl-cipher.c |  2 +-
> >  drivers/crypto/amlogic/amlogic-gxl-core.c   | 31 +++++++++++++++------
> >  drivers/crypto/amlogic/amlogic-gxl.h        | 11 ++++++++
> >  3 files changed, 35 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > index b19032f92415..7eff3ae7356f 100644
> > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > @@ -225,7 +225,7 @@ static int meson_cipher(struct skcipher_request *areq)
> >  
> >  	reinit_completion(&mc->chanlist[flow].complete);
> >  	mc->chanlist[flow].status = 0;
> > -	writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2));
> > +	writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2));
> >  	wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
> >  						  msecs_to_jiffies(500));
> >  	if (mc->chanlist[flow].status == 0) {
> > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
> > index a58644be76e9..2be381e157c4 100644
> > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c
> > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
> > @@ -18,6 +18,7 @@
> >  #include <linux/kernel.h>
> >  #include <linux/module.h>
> >  #include <linux/of.h>
> > +#include <linux/of_device.h>
> >  #include <linux/platform_device.h>
> >  
> >  #include "amlogic-gxl.h"
> > @@ -30,9 +31,10 @@ static irqreturn_t meson_irq_handler(int irq, void *data)
> >  
> >  	for (flow = 0; flow < mc->flow_cnt; flow++) {
> >  		if (mc->chanlist[flow].irq == irq) {
> > -			p = readl(mc->base + ((0x04 + flow) << 2));
> > +			p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2));
> >  			if (p) {
> > -				writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2));
> > +				writel_relaxed(0xF, mc->base +
> > +					      ((mc->pdata->status_reg + flow) << 2));
> >  				mc->chanlist[flow].status = 1;
> >  				complete(&mc->chanlist[flow].complete);
> >  				return IRQ_HANDLED;
> > @@ -245,15 +247,34 @@ static void meson_unregister_algs(struct meson_dev *mc)
> >  	}
> >  }
> >  
> > +static const struct meson_pdata meson_gxl_pdata = {
> > +	.descs_reg = 0x0,
> > +	.status_reg = 0x4,
> > +};
> > +
> > +static const struct of_device_id meson_crypto_of_match_table[] = {
> > +	{
> > +		.compatible = "amlogic,gxl-crypto",
> > +		.data = &meson_gxl_pdata,
> > +	},
> > +	{},
> > +};
> > +
> >  static int meson_crypto_probe(struct platform_device *pdev)
> >  {
> > +	const struct of_device_id *match;
> >  	struct meson_dev *mc;
> >  	int err;
> >  
> > +	match = of_match_device(meson_crypto_of_match_table, &pdev->dev);
> > +	if (!match)
> > +		return -EINVAL;
> > +
> >  	mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
> >  	if (!mc)
> >  		return -ENOMEM;
> >  
> > +	mc->pdata = match->data;
> >  	mc->dev = &pdev->dev;
> >  	platform_set_drvdata(pdev, mc);
> >  
> > @@ -312,12 +333,6 @@ static void meson_crypto_remove(struct platform_device *pdev)
> >  	clk_disable_unprepare(mc->busclk);
> >  }
> >  
> > -static const struct of_device_id meson_crypto_of_match_table[] = {
> > -	{ .compatible = "amlogic,gxl-crypto", },
> > -	{}
> > -};
> > -MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table);
> 
> Hello
> 
> This patch breaks bisection, since it removes MODULE_DEVICE_TABLE.
> After applying patchs 1,2,3 the driver does not load anymore on lepotato board.

Please, give more information. 

I applied the first 3 patches and the driver probes correctly.

> 
> Regards
Corentin Labbe Feb. 1, 2024, 7:45 p.m. UTC | #3
Le Thu, Feb 01, 2024 at 05:13:56PM +0000, Alexey Romanov a écrit :
> Hello,
> 
> On Wed, Jan 24, 2024 at 08:30:48AM +0100, Corentin Labbe wrote:
> > Le Tue, Jan 23, 2024 at 07:58:14PM +0300, Alexey Romanov a 'ecrit :
> > > To support other Amlogic SoC's we have to
> > > use platform data: descriptors and status registers
> > > offsets are individual for each SoC series.
> > > 
> > > Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
> > > ---
> > >  drivers/crypto/amlogic/amlogic-gxl-cipher.c |  2 +-
> > >  drivers/crypto/amlogic/amlogic-gxl-core.c   | 31 +++++++++++++++------
> > >  drivers/crypto/amlogic/amlogic-gxl.h        | 11 ++++++++
> > >  3 files changed, 35 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > > index b19032f92415..7eff3ae7356f 100644
> > > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
> > > @@ -225,7 +225,7 @@ static int meson_cipher(struct skcipher_request *areq)
> > >  
> > >  	reinit_completion(&mc->chanlist[flow].complete);
> > >  	mc->chanlist[flow].status = 0;
> > > -	writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2));
> > > +	writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2));
> > >  	wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
> > >  						  msecs_to_jiffies(500));
> > >  	if (mc->chanlist[flow].status == 0) {
> > > diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
> > > index a58644be76e9..2be381e157c4 100644
> > > --- a/drivers/crypto/amlogic/amlogic-gxl-core.c
> > > +++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
> > > @@ -18,6 +18,7 @@
> > >  #include <linux/kernel.h>
> > >  #include <linux/module.h>
> > >  #include <linux/of.h>
> > > +#include <linux/of_device.h>
> > >  #include <linux/platform_device.h>
> > >  
> > >  #include "amlogic-gxl.h"
> > > @@ -30,9 +31,10 @@ static irqreturn_t meson_irq_handler(int irq, void *data)
> > >  
> > >  	for (flow = 0; flow < mc->flow_cnt; flow++) {
> > >  		if (mc->chanlist[flow].irq == irq) {
> > > -			p = readl(mc->base + ((0x04 + flow) << 2));
> > > +			p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2));
> > >  			if (p) {
> > > -				writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2));
> > > +				writel_relaxed(0xF, mc->base +
> > > +					      ((mc->pdata->status_reg + flow) << 2));
> > >  				mc->chanlist[flow].status = 1;
> > >  				complete(&mc->chanlist[flow].complete);
> > >  				return IRQ_HANDLED;
> > > @@ -245,15 +247,34 @@ static void meson_unregister_algs(struct meson_dev *mc)
> > >  	}
> > >  }
> > >  
> > > +static const struct meson_pdata meson_gxl_pdata = {
> > > +	.descs_reg = 0x0,
> > > +	.status_reg = 0x4,
> > > +};
> > > +
> > > +static const struct of_device_id meson_crypto_of_match_table[] = {
> > > +	{
> > > +		.compatible = "amlogic,gxl-crypto",
> > > +		.data = &meson_gxl_pdata,
> > > +	},
> > > +	{},
> > > +};
> > > +
> > >  static int meson_crypto_probe(struct platform_device *pdev)
> > >  {
> > > +	const struct of_device_id *match;
> > >  	struct meson_dev *mc;
> > >  	int err;
> > >  
> > > +	match = of_match_device(meson_crypto_of_match_table, &pdev->dev);
> > > +	if (!match)
> > > +		return -EINVAL;
> > > +
> > >  	mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
> > >  	if (!mc)
> > >  		return -ENOMEM;
> > >  
> > > +	mc->pdata = match->data;
> > >  	mc->dev = &pdev->dev;
> > >  	platform_set_drvdata(pdev, mc);
> > >  
> > > @@ -312,12 +333,6 @@ static void meson_crypto_remove(struct platform_device *pdev)
> > >  	clk_disable_unprepare(mc->busclk);
> > >  }
> > >  
> > > -static const struct of_device_id meson_crypto_of_match_table[] = {
> > > -	{ .compatible = "amlogic,gxl-crypto", },
> > > -	{}
> > > -};
> > > -MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table);
> > 
> > Hello
> > 
> > This patch breaks bisection, since it removes MODULE_DEVICE_TABLE.
> > After applying patchs 1,2,3 the driver does not load anymore on lepotato board.
> 
> Please, give more information. 
> 
> I applied the first 3 patches and the driver probes correctly.
> 

Did you tried to set the driver as module ?
The breakage is when the driver is set as module.

Regards
diff mbox series

Patch

diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index b19032f92415..7eff3ae7356f 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -225,7 +225,7 @@  static int meson_cipher(struct skcipher_request *areq)
 
 	reinit_completion(&mc->chanlist[flow].complete);
 	mc->chanlist[flow].status = 0;
-	writel(mc->chanlist[flow].t_phy | 2, mc->base + (flow << 2));
+	writel(mc->chanlist[flow].t_phy | 2, mc->base + ((mc->pdata->descs_reg + flow) << 2));
 	wait_for_completion_interruptible_timeout(&mc->chanlist[flow].complete,
 						  msecs_to_jiffies(500));
 	if (mc->chanlist[flow].status == 0) {
diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
index a58644be76e9..2be381e157c4 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-core.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
@@ -18,6 +18,7 @@ 
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 
 #include "amlogic-gxl.h"
@@ -30,9 +31,10 @@  static irqreturn_t meson_irq_handler(int irq, void *data)
 
 	for (flow = 0; flow < mc->flow_cnt; flow++) {
 		if (mc->chanlist[flow].irq == irq) {
-			p = readl(mc->base + ((0x04 + flow) << 2));
+			p = readl(mc->base + ((mc->pdata->status_reg + flow) << 2));
 			if (p) {
-				writel_relaxed(0xF, mc->base + ((0x4 + flow) << 2));
+				writel_relaxed(0xF, mc->base +
+					      ((mc->pdata->status_reg + flow) << 2));
 				mc->chanlist[flow].status = 1;
 				complete(&mc->chanlist[flow].complete);
 				return IRQ_HANDLED;
@@ -245,15 +247,34 @@  static void meson_unregister_algs(struct meson_dev *mc)
 	}
 }
 
+static const struct meson_pdata meson_gxl_pdata = {
+	.descs_reg = 0x0,
+	.status_reg = 0x4,
+};
+
+static const struct of_device_id meson_crypto_of_match_table[] = {
+	{
+		.compatible = "amlogic,gxl-crypto",
+		.data = &meson_gxl_pdata,
+	},
+	{},
+};
+
 static int meson_crypto_probe(struct platform_device *pdev)
 {
+	const struct of_device_id *match;
 	struct meson_dev *mc;
 	int err;
 
+	match = of_match_device(meson_crypto_of_match_table, &pdev->dev);
+	if (!match)
+		return -EINVAL;
+
 	mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
 	if (!mc)
 		return -ENOMEM;
 
+	mc->pdata = match->data;
 	mc->dev = &pdev->dev;
 	platform_set_drvdata(pdev, mc);
 
@@ -312,12 +333,6 @@  static void meson_crypto_remove(struct platform_device *pdev)
 	clk_disable_unprepare(mc->busclk);
 }
 
-static const struct of_device_id meson_crypto_of_match_table[] = {
-	{ .compatible = "amlogic,gxl-crypto", },
-	{}
-};
-MODULE_DEVICE_TABLE(of, meson_crypto_of_match_table);
-
 static struct platform_driver meson_crypto_driver = {
 	.probe		 = meson_crypto_probe,
 	.remove_new	 = meson_crypto_remove,
diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h
index 79177cfa8b88..9ad75da214ff 100644
--- a/drivers/crypto/amlogic/amlogic-gxl.h
+++ b/drivers/crypto/amlogic/amlogic-gxl.h
@@ -78,6 +78,16 @@  struct meson_flow {
 #endif
 };
 
+/*
+ * struct meson_pdata - SoC series dependent data.
+ * @reg_descs:	offset to descriptors register
+ * @reg_status:	offset to status register
+ */
+struct meson_pdata {
+	u32 descs_reg;
+	u32 status_reg;
+};
+
 /*
  * struct meson_dev - main container for all this driver information
  * @base:	base address of amlogic-crypto
@@ -93,6 +103,7 @@  struct meson_dev {
 	void __iomem *base;
 	struct clk *busclk;
 	struct device *dev;
+	const struct meson_pdata *pdata;
 	struct meson_flow *chanlist;
 	atomic_t flow;
 	int flow_cnt;