mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] net: enc28j60: support getting irq number from gpio phandle in the device tree
@ 2025-03-09  7:47 Hanyuan Zhao
  2025-03-09 15:41 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Hanyuan Zhao @ 2025-03-09  7:47 UTC (permalink / raw)
  To: davem, kuba, andrew+netdev, edumazet, pabeni
  Cc: netdev, linux-kernel, Hanyuan Zhao

This patch allows the kernel to automatically requests the pin, configures
it as an input, and converts it to an IRQ number, according to a GPIO
phandle specified in device tree. This simplifies the process by
eliminating the need to manually define pinctrl and interrupt nodes.
Additionally, it is necessary for platforms that do not support pin
configuration and properties via the device tree.

Signed-off-by: Hanyuan Zhao <hanyuan-z@qq.com>
---
 drivers/net/ethernet/microchip/enc28j60.c | 25 ++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
index d6c9491537e4..b3613e45c900 100644
--- a/drivers/net/ethernet/microchip/enc28j60.c
+++ b/drivers/net/ethernet/microchip/enc28j60.c
@@ -24,6 +24,7 @@
 #include <linux/skbuff.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
+#include <linux/of_gpio.h>
 
 #include "enc28j60_hw.h"
 
@@ -1526,6 +1527,7 @@ static int enc28j60_probe(struct spi_device *spi)
 	struct net_device *dev;
 	struct enc28j60_net *priv;
 	int ret = 0;
+	unsigned long irq_flags = IRQF_ONESHOT;
 
 	if (netif_msg_drv(&debug))
 		dev_info(&spi->dev, "Ethernet driver %s loaded\n", DRV_VERSION);
@@ -1558,20 +1560,33 @@ static int enc28j60_probe(struct spi_device *spi)
 		eth_hw_addr_random(dev);
 	enc28j60_set_hw_macaddr(dev);
 
+	if (spi->irq > 0) {
+		dev->irq = spi->irq;
+	} else {
+		/* Try loading device tree property irq-gpios */
+		struct gpio_desc *irq_gpio_desc = devm_fwnode_gpiod_get_index(&spi->dev,
+				of_fwnode_handle(spi->dev.of_node), "irq", 0, GPIOD_IN, NULL);
+		if (IS_ERR(irq_gpio_desc)) {
+			dev_err(&spi->dev, "unable to get a valid irq gpio\n");
+			goto error_irq;
+		}
+		dev->irq = gpiod_to_irq(irq_gpio_desc);
+		irq_flags |= IRQF_TRIGGER_FALLING;
+	}
+
 	/* Board setup must set the relevant edge trigger type;
 	 * level triggers won't currently work.
 	 */
-	ret = request_threaded_irq(spi->irq, NULL, enc28j60_irq, IRQF_ONESHOT,
+	ret = request_threaded_irq(dev->irq, NULL, enc28j60_irq, irq_flags,
 				   DRV_NAME, priv);
 	if (ret < 0) {
 		if (netif_msg_probe(priv))
 			dev_err(&spi->dev, "request irq %d failed (ret = %d)\n",
-				spi->irq, ret);
+				dev->irq, ret);
 		goto error_irq;
 	}
 
 	dev->if_port = IF_PORT_10BASET;
-	dev->irq = spi->irq;
 	dev->netdev_ops = &enc28j60_netdev_ops;
 	dev->watchdog_timeo = TX_TIMEOUT;
 	dev->ethtool_ops = &enc28j60_ethtool_ops;
@@ -1589,7 +1604,7 @@ static int enc28j60_probe(struct spi_device *spi)
 	return 0;
 
 error_register:
-	free_irq(spi->irq, priv);
+	free_irq(dev->irq, priv);
 error_irq:
 	free_netdev(dev);
 error_alloc:
@@ -1601,7 +1616,7 @@ static void enc28j60_remove(struct spi_device *spi)
 	struct enc28j60_net *priv = spi_get_drvdata(spi);
 
 	unregister_netdev(priv->netdev);
-	free_irq(spi->irq, priv);
+	free_irq(priv->netdev->irq, priv);
 	free_netdev(priv->netdev);
 }
 
-- 
2.43.0


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

* Re: [PATCH 1/2] net: enc28j60: support getting irq number from gpio phandle in the device tree
  2025-03-09  7:47 [PATCH 1/2] net: enc28j60: support getting irq number from gpio phandle in the device tree Hanyuan Zhao
@ 2025-03-09 15:41 ` Andrew Lunn
       [not found]   ` <tencent_BE0060E3A7AF384BAF4DA37FD2121B8E1D07@qq.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2025-03-09 15:41 UTC (permalink / raw)
  To: Hanyuan Zhao
  Cc: davem, kuba, andrew+netdev, edumazet, pabeni, netdev, linux-kernel

On Sun, Mar 09, 2025 at 03:47:08PM +0800, Hanyuan Zhao wrote:
> This patch allows the kernel to automatically requests the pin, configures
> it as an input, and converts it to an IRQ number, according to a GPIO
> phandle specified in device tree. This simplifies the process by
> eliminating the need to manually define pinctrl and interrupt nodes.
> Additionally, it is necessary for platforms that do not support pin
> configuration and properties via the device tree.
> 
> Signed-off-by: Hanyuan Zhao <hanyuan-z@qq.com>
> ---
>  drivers/net/ethernet/microchip/enc28j60.c | 25 ++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
> index d6c9491537e4..b3613e45c900 100644
> --- a/drivers/net/ethernet/microchip/enc28j60.c
> +++ b/drivers/net/ethernet/microchip/enc28j60.c
> @@ -24,6 +24,7 @@
>  #include <linux/skbuff.h>
>  #include <linux/delay.h>
>  #include <linux/spi/spi.h>
> +#include <linux/of_gpio.h>
>  
>  #include "enc28j60_hw.h"
>  
> @@ -1526,6 +1527,7 @@ static int enc28j60_probe(struct spi_device *spi)
>  	struct net_device *dev;
>  	struct enc28j60_net *priv;
>  	int ret = 0;
> +	unsigned long irq_flags = IRQF_ONESHOT;
>  
>  	if (netif_msg_drv(&debug))
>  		dev_info(&spi->dev, "Ethernet driver %s loaded\n", DRV_VERSION);
> @@ -1558,20 +1560,33 @@ static int enc28j60_probe(struct spi_device *spi)
>  		eth_hw_addr_random(dev);
>  	enc28j60_set_hw_macaddr(dev);
>  
> +	if (spi->irq > 0) {
> +		dev->irq = spi->irq;
> +	} else {
> +		/* Try loading device tree property irq-gpios */
> +		struct gpio_desc *irq_gpio_desc = devm_fwnode_gpiod_get_index(&spi->dev,
> +				of_fwnode_handle(spi->dev.of_node), "irq", 0, GPIOD_IN, NULL);
> +		if (IS_ERR(irq_gpio_desc)) {
> +			dev_err(&spi->dev, "unable to get a valid irq gpio\n");
> +			goto error_irq;
> +		}
> +		dev->irq = gpiod_to_irq(irq_gpio_desc);

My understanding is that you should not need most of this. The IRQ
core will handle converting a GPIO to an interrupt, if you just list
is as an interrupt source in the normal way.

> +		irq_flags |= IRQF_TRIGGER_FALLING;

You say:

> Additionally, it is necessary for platforms that do not support pin
> configuration and properties via the device tree.

Are you talking about ACPI?

	Andrew

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

* Re: [PATCH 1/2] net: enc28j60: support getting irq number from gpiophandle in the device tree
       [not found]   ` <tencent_BE0060E3A7AF384BAF4DA37FD2121B8E1D07@qq.com>
@ 2025-03-10 12:06     ` Andrew Lunn
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2025-03-10 12:06 UTC (permalink / raw)
  To: hanyuan-z
  Cc: davem, kuba, andrew+netdev, edumazet, pabeni, netdev, linux-kernel

On Mon, Mar 10, 2025 at 10:20:01AM +0800, hanyuan-z wrote:
> Hi&nbsp;Andrew,&nbsp;<br/><br/>&gt;&nbsp;My&nbsp;understanding&nbsp;is&nbsp;that&nbsp;you&nbsp;should&nbsp;not&nbsp;need&nbsp;most&nbsp;of&nbsp;this.&nbsp;The&nbsp;IRQ<br/>&gt;&nbsp;core&nbsp;will&nbsp;handle&nbsp;converting&nbsp;a&nbsp;GPIO&nbsp;to&nbsp;an&nbsp;interrupt,&nbsp;if&nbsp;you&nbsp;just&nbsp;list<br/>&gt;&nbsp;is&nbsp;as&nbsp;an&nbsp;interrupt&nbsp;source&nbsp;in&nbsp;the&nbsp;normal&nbsp;way.<br/><br/>&gt;&nbsp;You&nbsp;say:<br/>&gt;<br/>&gt;&nbsp;&gt;&nbsp;Additionally,&nbsp;it&nbsp;is&nbsp;necessary&nbsp;for&nbsp;platforms&nbsp;that&nbsp;do&nbsp;not&nbsp;support&nbsp;pin<br/>&gt;&nbsp;&gt;&nbsp;configuration&nbsp;and&nbsp;properties&nbsp;via&nbsp;the&nbsp;device&nbsp;tree.<br/>&gt;<br/>&gt;&nbsp;Are&nbsp;you&nbsp;talking&nbsp;about&nbsp;ACPI?<br/><br/>Thanks&nbsp;for&nbsp;your&nbsp;review.&nbsp;Let&nbsp;me&nbsp;explain&nbsp;them.<br/><br/>I&nbsp;understand&nbsp;that&nbsp;specifying&nbsp;the&nbsp;interrupt&nbsp;as:<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;interrupts&nbsp;=&nbsp;&lt;&amp;gpio2&nbsp;23&nbsp;IRQ_TYPE_LEVEL_LOW&gt;;<br/><br/>would&nbsp;also&nbsp;work,&nbsp;and&nbsp;the&nbsp;IRQ&nbsp;subsystem&nbsp;will&nbsp;properly&nbsp;handle&nbsp;the<br/>conversion&nbsp;during&nbsp;the&nbsp;SPI&nbsp;probe.&nbsp;However,&nbsp;my&nbsp;problem&nbsp;is&nbsp;that&nbsp;the<br/>GPIO&nbsp;pin&nbsp;itself&nbsp;needs&nbsp;to&nbsp;be&nbsp;explicitly&nbsp;requested&nbsp;and&nbsp;configured&nbsp;a<br/>an&nbsp;input&nbsp;before&nbsp;it&nbsp;can&nbsp;be&nbsp;used&nbsp;as&nbsp;an&nbsp;IRQ&nbsp;pin.<br/><br/>My&nbsp;embedded&nbsp;platform&nbsp;has&nbsp;limited&nbsp;support,&nbsp;it&nbsp;only&nbsp;provides&nbsp;a<br/>hard-coded&nbsp;pin&nbsp;control&nbsp;driver&nbsp;and&nbsp;does&nbsp;not&nbsp;support&nbsp;configuring<br/>pinctrl&nbsp;properties&nbsp;in&nbsp;the&nbsp;device&nbsp;tree.&nbsp;So,&nbsp;there&nbsp;is&nbsp;no&nbsp;generic<br/>way&nbsp;to&nbsp;request&nbsp;the&nbsp;pin&nbsp;and&nbsp;set&nbsp;its&nbsp;direction&nbsp;via&nbsp;device&nbsp;tree&nbsp;bindings.<br/><br/>I&nbsp;noticed&nbsp;that&nbsp;some&nbsp;existing&nbsp;NIC&nbsp;drivers&nbsp;solve&nbsp;this&nbsp;issue&nbsp;by&nbsp;specifying<br/>`irq-gpios`&nbsp;in&nbsp;the&nbsp;device&nbsp;tree,&nbsp;which&nbsp;ensures&nbsp;that&nbsp;the&nbsp;GPIO&nbsp;is&nbsp;properly<br/>initialized&nbsp;before&nbsp;being&nbsp;converted&nbsp;to&nbsp;an&nbsp;IRQ.<br/><br/>That&nbsp;was&nbsp;my&nbsp;motivation&nbsp;for&nbsp;these&nbsp;patches.<br/><br/>And&nbsp;my&nbsp;changes&nbsp;are&nbsp;not&nbsp;related&nbsp;to&nbsp;ACPI&nbsp;in&nbsp;any&nbsp;way—they&nbsp;are&nbsp;mainly<br/>focused&nbsp;on&nbsp;device&nbsp;tree&nbsp;handling.<br/><br/>Thanks,&nbsp;&nbsp;<br/>Hanyuan&nbsp;Zhao&nbsp;&nbsp;<br/>

Please use plain text for emails.

	Andrew

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

end of thread, other threads:[~2025-03-10 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-09  7:47 [PATCH 1/2] net: enc28j60: support getting irq number from gpio phandle in the device tree Hanyuan Zhao
2025-03-09 15:41 ` Andrew Lunn
     [not found]   ` <tencent_BE0060E3A7AF384BAF4DA37FD2121B8E1D07@qq.com>
2025-03-10 12:06     ` [PATCH 1/2] net: enc28j60: support getting irq number from gpiophandle " Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®