Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Bamvor Jian Zhang <bamv2005@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: <kernel@axis.com>, <devicetree@vger.kernel.org>,
	<andy.shevchenko@gmail.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v4] gpio: mockup: Allow probing from device tree
Date: Thu, 29 Oct 2020 09:17:20 +0100	[thread overview]
Message-ID: <20201029081721.9593-1-vincent.whitchurch@axis.com> (raw)

Allow the mockup driver to be probed via the device tree without any
module parameters, allowing it to be used to configure and test higher
level drivers like the leds-gpio driver and corresponding userspace
before actual hardware is available.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---

Notes:
    v4:
    - Remove of_match_ptr() to fix unused variable warning with W=1
    - Include linux/mod_devicetable.h instead of linux/of.h
    
    v3:
    - Keep includes sorted alphabetically
    - Drop CONFIG_OF ifdefs
    
    v2:
    - Remove most of the added code, since the latest driver doesn't need it.
    - Drop DT binding document, since Rob Herring was OK with not documenting this:
      https://lore.kernel.org/linux-devicetree/5baa1ae6.1c69fb81.847f2.3ab1@mx.google.com/

Range-diff against v3:
1:  1e9b8f36676d ! 1:  4e8fdcfe1a47 gpio: mockup: Allow probing from device tree
    @@ Commit message
     
     
      ## Notes ##
    +    v4:
    +    - Remove of_match_ptr() to fix unused variable warning with W=1
    +    - Include linux/mod_devicetable.h instead of linux/of.h
    +
         v3:
         - Keep includes sorted alphabetically
         - Drop CONFIG_OF ifdefs
    @@ Notes
     
      ## drivers/gpio/gpio-mockup.c ##
     @@
    + #include <linux/irq.h>
      #include <linux/irq_sim.h>
      #include <linux/irqdomain.h>
    ++#include <linux/mod_devicetable.h>
      #include <linux/module.h>
    -+#include <linux/of.h>
      #include <linux/platform_device.h>
      #include <linux/property.h>
    - #include <linux/slab.h>
     @@ drivers/gpio/gpio-mockup.c: static int gpio_mockup_probe(struct platform_device *pdev)
      	return 0;
      }
    @@ drivers/gpio/gpio-mockup.c: static int gpio_mockup_probe(struct platform_device
      static struct platform_driver gpio_mockup_driver = {
      	.driver = {
      		.name = "gpio-mockup",
    -+		.of_match_table = of_match_ptr(gpio_mockup_of_match),
    ++		.of_match_table = gpio_mockup_of_match,
      	},
      	.probe = gpio_mockup_probe,
      };

 drivers/gpio/gpio-mockup.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 67ed4f238d43..28b757d34046 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -15,6 +15,7 @@
 #include <linux/irq.h>
 #include <linux/irq_sim.h>
 #include <linux/irqdomain.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -460,9 +461,16 @@ static int gpio_mockup_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id gpio_mockup_of_match[] = {
+	{ .compatible = "gpio-mockup", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, gpio_mockup_of_match);
+
 static struct platform_driver gpio_mockup_driver = {
 	.driver = {
 		.name = "gpio-mockup",
+		.of_match_table = gpio_mockup_of_match,
 	},
 	.probe = gpio_mockup_probe,
 };
@@ -556,8 +564,7 @@ static int __init gpio_mockup_init(void)
 {
 	int i, num_chips, err;
 
-	if ((gpio_mockup_num_ranges < 2) ||
-	    (gpio_mockup_num_ranges % 2) ||
+	if ((gpio_mockup_num_ranges % 2) ||
 	    (gpio_mockup_num_ranges > GPIO_MOCKUP_MAX_RANGES))
 		return -EINVAL;
 
-- 
2.28.0


             reply	other threads:[~2020-10-29  8:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29  8:17 Vincent Whitchurch [this message]
2020-10-29  9:39 ` [PATCH v4] gpio: mockup: Allow probing from device tree Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201029081721.9593-1-vincent.whitchurch@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bamv2005@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@axis.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox