linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data()
@ 2023-10-06 22:46 Rob Herring
  2023-10-07  7:43 ` Xu Yilun
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2023-10-06 22:46 UTC (permalink / raw)
  To: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix; +Cc: linux-fpga, linux-kernel

Use preferred spi_get_device_match_data() instead of of_match_device() and
spi_get_device_id() to get the driver match data. With this, adjust the
includes to explicitly include the correct headers.

Signed-off-by: Rob Herring <robh@kernel.org>
---
 drivers/fpga/altera-ps-spi.c | 44 ++++--------------------------------
 1 file changed, 5 insertions(+), 39 deletions(-)

diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c
index 5e1e009dba89..6be7410e4f09 100644
--- a/drivers/fpga/altera-ps-spi.c
+++ b/drivers/fpga/altera-ps-spi.c
@@ -18,8 +18,7 @@
 #include <linux/fpga/fpga-mgr.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
-#include <linux/of_gpio.h>
-#include <linux/of_device.h>
+#include <linux/of.h>
 #include <linux/spi/spi.h>
 #include <linux/sizes.h>
 
@@ -72,12 +71,6 @@ static struct altera_ps_data a10_data = {
 	.t_st2ck_us = 10, /* min(t_ST2CK) */
 };
 
-/* Array index is enum altera_ps_devtype */
-static const struct altera_ps_data *altera_ps_data_map[] = {
-	&c5_data,
-	&a10_data,
-};
-
 static const struct of_device_id of_ef_match[] = {
 	{ .compatible = "altr,fpga-passive-serial", .data = &c5_data },
 	{ .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data },
@@ -237,43 +230,16 @@ static const struct fpga_manager_ops altera_ps_ops = {
 	.write_complete = altera_ps_write_complete,
 };
 
-static const struct altera_ps_data *id_to_data(const struct spi_device_id *id)
-{
-	kernel_ulong_t devtype = id->driver_data;
-	const struct altera_ps_data *data;
-
-	/* someone added a altera_ps_devtype without adding to the map array */
-	if (devtype >= ARRAY_SIZE(altera_ps_data_map))
-		return NULL;
-
-	data = altera_ps_data_map[devtype];
-	if (!data || data->devtype != devtype)
-		return NULL;
-
-	return data;
-}
-
 static int altera_ps_probe(struct spi_device *spi)
 {
 	struct altera_ps_conf *conf;
-	const struct of_device_id *of_id;
 	struct fpga_manager *mgr;
 
 	conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
 	if (!conf)
 		return -ENOMEM;
 
-	if (spi->dev.of_node) {
-		of_id = of_match_device(of_ef_match, &spi->dev);
-		if (!of_id)
-			return -ENODEV;
-		conf->data = of_id->data;
-	} else {
-		conf->data = id_to_data(spi_get_device_id(spi));
-		if (!conf->data)
-			return -ENODEV;
-	}
-
+	conf->data = spi_get_device_match_data(spi);
 	conf->spi = spi;
 	conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
 	if (IS_ERR(conf->config)) {
@@ -308,9 +274,9 @@ static int altera_ps_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id altera_ps_spi_ids[] = {
-	{ "cyclone-ps-spi", CYCLONE5 },
-	{ "fpga-passive-serial", CYCLONE5 },
-	{ "fpga-arria10-passive-serial", ARRIA10 },
+	{ "cyclone-ps-spi", (uintptr_t)&c5_data },
+	{ "fpga-passive-serial", (uintptr_t)&c5_data },
+	{ "fpga-arria10-passive-serial", (uintptr_t)&a10_data },
 	{}
 };
 MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data()
  2023-10-06 22:46 [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data() Rob Herring
@ 2023-10-07  7:43 ` Xu Yilun
  2023-10-07  7:55   ` Xu Yilun
  0 siblings, 1 reply; 5+ messages in thread
From: Xu Yilun @ 2023-10-07  7:43 UTC (permalink / raw)
  To: Rob Herring
  Cc: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix, linux-fpga,
	linux-kernel

On Fri, Oct 06, 2023 at 05:46:24PM -0500, Rob Herring wrote:
> Use preferred spi_get_device_match_data() instead of of_match_device() and
> spi_get_device_id() to get the driver match data. With this, adjust the
> includes to explicitly include the correct headers.
> 
> Signed-off-by: Rob Herring <robh@kernel.org>

Acked-by: Xu Yilun <yilun.xu@intel.com>

Applied.

> ---
>  drivers/fpga/altera-ps-spi.c | 44 ++++--------------------------------
>  1 file changed, 5 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c
> index 5e1e009dba89..6be7410e4f09 100644
> --- a/drivers/fpga/altera-ps-spi.c
> +++ b/drivers/fpga/altera-ps-spi.c
> @@ -18,8 +18,7 @@
>  #include <linux/fpga/fpga-mgr.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/module.h>
> -#include <linux/of_gpio.h>
> -#include <linux/of_device.h>
> +#include <linux/of.h>
>  #include <linux/spi/spi.h>
>  #include <linux/sizes.h>
>  
> @@ -72,12 +71,6 @@ static struct altera_ps_data a10_data = {
>  	.t_st2ck_us = 10, /* min(t_ST2CK) */
>  };
>  
> -/* Array index is enum altera_ps_devtype */
> -static const struct altera_ps_data *altera_ps_data_map[] = {
> -	&c5_data,
> -	&a10_data,
> -};
> -
>  static const struct of_device_id of_ef_match[] = {
>  	{ .compatible = "altr,fpga-passive-serial", .data = &c5_data },
>  	{ .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data },
> @@ -237,43 +230,16 @@ static const struct fpga_manager_ops altera_ps_ops = {
>  	.write_complete = altera_ps_write_complete,
>  };
>  
> -static const struct altera_ps_data *id_to_data(const struct spi_device_id *id)
> -{
> -	kernel_ulong_t devtype = id->driver_data;
> -	const struct altera_ps_data *data;
> -
> -	/* someone added a altera_ps_devtype without adding to the map array */
> -	if (devtype >= ARRAY_SIZE(altera_ps_data_map))
> -		return NULL;
> -
> -	data = altera_ps_data_map[devtype];
> -	if (!data || data->devtype != devtype)
> -		return NULL;
> -
> -	return data;
> -}
> -
>  static int altera_ps_probe(struct spi_device *spi)
>  {
>  	struct altera_ps_conf *conf;
> -	const struct of_device_id *of_id;
>  	struct fpga_manager *mgr;
>  
>  	conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
>  	if (!conf)
>  		return -ENOMEM;
>  
> -	if (spi->dev.of_node) {
> -		of_id = of_match_device(of_ef_match, &spi->dev);
> -		if (!of_id)
> -			return -ENODEV;
> -		conf->data = of_id->data;
> -	} else {
> -		conf->data = id_to_data(spi_get_device_id(spi));
> -		if (!conf->data)
> -			return -ENODEV;
> -	}
> -
> +	conf->data = spi_get_device_match_data(spi);
>  	conf->spi = spi;
>  	conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
>  	if (IS_ERR(conf->config)) {
> @@ -308,9 +274,9 @@ static int altera_ps_probe(struct spi_device *spi)
>  }
>  
>  static const struct spi_device_id altera_ps_spi_ids[] = {
> -	{ "cyclone-ps-spi", CYCLONE5 },
> -	{ "fpga-passive-serial", CYCLONE5 },
> -	{ "fpga-arria10-passive-serial", ARRIA10 },
> +	{ "cyclone-ps-spi", (uintptr_t)&c5_data },
> +	{ "fpga-passive-serial", (uintptr_t)&c5_data },
> +	{ "fpga-arria10-passive-serial", (uintptr_t)&a10_data },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data()
  2023-10-07  7:43 ` Xu Yilun
@ 2023-10-07  7:55   ` Xu Yilun
  2023-10-09 12:48     ` Rob Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Xu Yilun @ 2023-10-07  7:55 UTC (permalink / raw)
  To: Rob Herring
  Cc: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix, linux-fpga,
	linux-kernel

On Sat, Oct 07, 2023 at 03:43:41PM +0800, Xu Yilun wrote:
> On Fri, Oct 06, 2023 at 05:46:24PM -0500, Rob Herring wrote:
> > Use preferred spi_get_device_match_data() instead of of_match_device() and
> > spi_get_device_id() to get the driver match data. With this, adjust the
> > includes to explicitly include the correct headers.
> > 
> > Signed-off-by: Rob Herring <robh@kernel.org>
> 
> Acked-by: Xu Yilun <yilun.xu@intel.com>
> 
> Applied.
> 
> >  
> >  static const struct spi_device_id altera_ps_spi_ids[] = {
> > -	{ "cyclone-ps-spi", CYCLONE5 },
> > -	{ "fpga-passive-serial", CYCLONE5 },
> > -	{ "fpga-arria10-passive-serial", ARRIA10 },
> > +	{ "cyclone-ps-spi", (uintptr_t)&c5_data },
> > +	{ "fpga-passive-serial", (uintptr_t)&c5_data },
> > +	{ "fpga-arria10-passive-serial", (uintptr_t)&a10_data },

Sorry, one more. Should cast to kernel_ulong_t?

Thanks,
Yilun

> >  	{}
> >  };
> >  MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids);
> > -- 
> > 2.40.1
> > 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data()
  2023-10-07  7:55   ` Xu Yilun
@ 2023-10-09 12:48     ` Rob Herring
  2023-10-12  5:04       ` Xu Yilun
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2023-10-09 12:48 UTC (permalink / raw)
  To: Xu Yilun
  Cc: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix, linux-fpga,
	linux-kernel

On Sat, Oct 7, 2023 at 2:56 AM Xu Yilun <yilun.xu@linux.intel.com> wrote:
>
> On Sat, Oct 07, 2023 at 03:43:41PM +0800, Xu Yilun wrote:
> > On Fri, Oct 06, 2023 at 05:46:24PM -0500, Rob Herring wrote:
> > > Use preferred spi_get_device_match_data() instead of of_match_device() and
> > > spi_get_device_id() to get the driver match data. With this, adjust the
> > > includes to explicitly include the correct headers.
> > >
> > > Signed-off-by: Rob Herring <robh@kernel.org>
> >
> > Acked-by: Xu Yilun <yilun.xu@intel.com>
> >
> > Applied.
> >
> > >
> > >  static const struct spi_device_id altera_ps_spi_ids[] = {
> > > -   { "cyclone-ps-spi", CYCLONE5 },
> > > -   { "fpga-passive-serial", CYCLONE5 },
> > > -   { "fpga-arria10-passive-serial", ARRIA10 },
> > > +   { "cyclone-ps-spi", (uintptr_t)&c5_data },
> > > +   { "fpga-passive-serial", (uintptr_t)&c5_data },
> > > +   { "fpga-arria10-passive-serial", (uintptr_t)&a10_data },
>
> Sorry, one more. Should cast to kernel_ulong_t?

Either will work. uintptr_t is somewhat new in the kernel and
preferred now I think.

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data()
  2023-10-09 12:48     ` Rob Herring
@ 2023-10-12  5:04       ` Xu Yilun
  0 siblings, 0 replies; 5+ messages in thread
From: Xu Yilun @ 2023-10-12  5:04 UTC (permalink / raw)
  To: Rob Herring
  Cc: Moritz Fischer, Wu Hao, Xu Yilun, Tom Rix, linux-fpga,
	linux-kernel

On Mon, Oct 09, 2023 at 07:48:07AM -0500, Rob Herring wrote:
> On Sat, Oct 7, 2023 at 2:56 AM Xu Yilun <yilun.xu@linux.intel.com> wrote:
> >
> > On Sat, Oct 07, 2023 at 03:43:41PM +0800, Xu Yilun wrote:
> > > On Fri, Oct 06, 2023 at 05:46:24PM -0500, Rob Herring wrote:
> > > > Use preferred spi_get_device_match_data() instead of of_match_device() and
> > > > spi_get_device_id() to get the driver match data. With this, adjust the
> > > > includes to explicitly include the correct headers.
> > > >
> > > > Signed-off-by: Rob Herring <robh@kernel.org>
> > >
> > > Acked-by: Xu Yilun <yilun.xu@intel.com>
> > >
> > > Applied.
> > >
> > > >
> > > >  static const struct spi_device_id altera_ps_spi_ids[] = {
> > > > -   { "cyclone-ps-spi", CYCLONE5 },
> > > > -   { "fpga-passive-serial", CYCLONE5 },
> > > > -   { "fpga-arria10-passive-serial", ARRIA10 },
> > > > +   { "cyclone-ps-spi", (uintptr_t)&c5_data },
> > > > +   { "fpga-passive-serial", (uintptr_t)&c5_data },
> > > > +   { "fpga-arria10-passive-serial", (uintptr_t)&a10_data },
> >
> > Sorry, one more. Should cast to kernel_ulong_t?
> 
> Either will work. uintptr_t is somewhat new in the kernel and
> preferred now I think.

LGTM, Applied.

> 
> Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-12  5:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-06 22:46 [PATCH] fpga: altera-ps-spi: Use spi_get_device_match_data() Rob Herring
2023-10-07  7:43 ` Xu Yilun
2023-10-07  7:55   ` Xu Yilun
2023-10-09 12:48     ` Rob Herring
2023-10-12  5:04       ` Xu Yilun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).