Skip to contentSkip to conversation

gpio: mockup: Allow probing from device tree

PATCH In review Vincent Whitchurch 2 participants 2 messages Oct 29, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 gpio: mockup: Allow probing from device tree

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.

---

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/[email protected]/

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(-)
drivers/gpio/gpio-mockup.c +9 -2
index 67ed4f238d43..28b757d34046 100644
@@ -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;
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 53 lines · Vincent Whitchurch

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.

---

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/[email protected]/

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
Quoted 9 lines
      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,
      };

Please don't do the above.

Quoted 43 lines
 drivers/gpio/gpio-mockup.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpio/gpio-mockup.c +9 -3
index 67ed4f238d43..28b757d34046 100644
@@ -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;
 
--
Quoted 2 lines

2.28.0

Applied now, thanks!

Bartosz