diff mbox series

[V3,27/29] PCI: OF: Add of_pci_get_reset_gpio() to parse reset-gpios from DT

Message ID 20190513180744.16493-28-mmaddireddy@nvidia.com (mailing list archive)
State Superseded, archived
Headers show
Series Enable Tegra PCIe root port features | expand

Commit Message

Manikanta Maddireddy May 13, 2019, 6:07 p.m. UTC
This new helper function could be used by host drivers to get the reset
GPIO descriptor. If the property isn't assigned, it will return NULL to
the caller.

Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
---
V3: New patch to add helper function to parse "reset-gpios"

 drivers/pci/of.c       | 18 ++++++++++++++++++
 include/linux/of_pci.h | 10 ++++++++++
 2 files changed, 28 insertions(+)

Comments

Rob Herring (Arm) May 14, 2019, 6:31 p.m. UTC | #1
On Mon, May 13, 2019 at 11:37:42PM +0530, Manikanta Maddireddy wrote:
> This new helper function could be used by host drivers to get the reset
> GPIO descriptor. If the property isn't assigned, it will return NULL to
> the caller.
> 
> Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
> ---
> V3: New patch to add helper function to parse "reset-gpios"
> 
>  drivers/pci/of.c       | 18 ++++++++++++++++++
>  include/linux/of_pci.h | 10 ++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 9454c90980c9..2a0282115ff0 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -6,6 +6,7 @@
>   */
>  #define pr_fmt(fmt)	"PCI: OF: " fmt
>  
> +#include <linux/gpio/consumer.h>
>  #include <linux/irqdomain.h>
>  #include <linux/kernel.h>
>  #include <linux/pci.h>
> @@ -224,6 +225,23 @@ int of_pci_get_max_link_speed(struct device_node *node)
>  }
>  EXPORT_SYMBOL_GPL(of_pci_get_max_link_speed);
>  
> +/**
> + * of_pci_get_reset_gpio() - Get PCI reset gpio descriptor.
> + *
> + * @node: device node
> + *
> + * Returns PCI reset gpio descriptor from DT, or an ERR_PTR() if the
> + * required property is invalid.
> + */
> +struct gpio_desc *of_pci_get_reset_gpio(struct device *dev,
> +					struct device_node *node,
> +					int dflags, char *label)
> +{
> +	return devm_gpiod_get_from_of_node(dev, node, "reset-gpios", 0, dflags,
> +					   label);
> +}

There's nothing PCI specific about this and 'reset-gpios' is pretty 
widely used. Either we should have this somewhere common or perhaps not 
worth a wrapper to save 1 parameter.

Also, I believe you can pass just 'reset' so the deprecated form 
'reset-gpio' can also be supported. 

Rob
Manikanta Maddireddy May 16, 2019, 5:50 a.m. UTC | #2
On 15-May-19 12:01 AM, Rob Herring wrote:
> On Mon, May 13, 2019 at 11:37:42PM +0530, Manikanta Maddireddy wrote:
>> This new helper function could be used by host drivers to get the reset
>> GPIO descriptor. If the property isn't assigned, it will return NULL to
>> the caller.
>>
>> Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
>> ---
>> V3: New patch to add helper function to parse "reset-gpios"
>>
>>  drivers/pci/of.c       | 18 ++++++++++++++++++
>>  include/linux/of_pci.h | 10 ++++++++++
>>  2 files changed, 28 insertions(+)
>>
>> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
>> index 9454c90980c9..2a0282115ff0 100644
>> --- a/drivers/pci/of.c
>> +++ b/drivers/pci/of.c
>> @@ -6,6 +6,7 @@
>>   */
>>  #define pr_fmt(fmt)	"PCI: OF: " fmt
>>  
>> +#include <linux/gpio/consumer.h>
>>  #include <linux/irqdomain.h>
>>  #include <linux/kernel.h>
>>  #include <linux/pci.h>
>> @@ -224,6 +225,23 @@ int of_pci_get_max_link_speed(struct device_node *node)
>>  }
>>  EXPORT_SYMBOL_GPL(of_pci_get_max_link_speed);
>>  
>> +/**
>> + * of_pci_get_reset_gpio() - Get PCI reset gpio descriptor.
>> + *
>> + * @node: device node
>> + *
>> + * Returns PCI reset gpio descriptor from DT, or an ERR_PTR() if the
>> + * required property is invalid.
>> + */
>> +struct gpio_desc *of_pci_get_reset_gpio(struct device *dev,
>> +					struct device_node *node,
>> +					int dflags, char *label)
>> +{
>> +	return devm_gpiod_get_from_of_node(dev, node, "reset-gpios", 0, dflags,
>> +					   label);
>> +}
> There's nothing PCI specific about this and 'reset-gpios' is pretty 
> widely used. Either we should have this somewhere common or perhaps not 
> worth a wrapper to save 1 parameter.
>
> Also, I believe you can pass just 'reset' so the deprecated form 
> 'reset-gpio' can also be supported. 
>
> Rob

I also think that it doesn't need a wrapper to save one parameter.
I will drop this patch and use devm_gpiod_get_from_of_node() directly
in pci-tegra driver.

Manikanta
diff mbox series

Patch

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 9454c90980c9..2a0282115ff0 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -6,6 +6,7 @@ 
  */
 #define pr_fmt(fmt)	"PCI: OF: " fmt
 
+#include <linux/gpio/consumer.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -224,6 +225,23 @@  int of_pci_get_max_link_speed(struct device_node *node)
 }
 EXPORT_SYMBOL_GPL(of_pci_get_max_link_speed);
 
+/**
+ * of_pci_get_reset_gpio() - Get PCI reset gpio descriptor.
+ *
+ * @node: device node
+ *
+ * Returns PCI reset gpio descriptor from DT, or an ERR_PTR() if the
+ * required property is invalid.
+ */
+struct gpio_desc *of_pci_get_reset_gpio(struct device *dev,
+					struct device_node *node,
+					int dflags, char *label)
+{
+	return devm_gpiod_get_from_of_node(dev, node, "reset-gpios", 0, dflags,
+					   label);
+}
+EXPORT_SYMBOL_GPL(of_pci_get_reset_gpio);
+
 /**
  * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
  *                           is present and valid
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
index 21a89c4880fa..230ddc813ef9 100644
--- a/include/linux/of_pci.h
+++ b/include/linux/of_pci.h
@@ -13,6 +13,9 @@  struct device_node;
 struct device_node *of_pci_find_child_device(struct device_node *parent,
 					     unsigned int devfn);
 int of_pci_get_devfn(struct device_node *np);
+struct gpio_desc *of_pci_get_reset_gpio(struct device *dev,
+					struct device_node *np,
+					int dflags, char *label);
 void of_pci_check_probe_only(void);
 #else
 static inline struct device_node *of_pci_find_child_device(struct device_node *parent,
@@ -26,6 +29,13 @@  static inline int of_pci_get_devfn(struct device_node *np)
 	return -EINVAL;
 }
 
+static inline struct gpio_desc *of_pci_get_reset_gpio(struct device *dev,
+						      struct device_node *np,
+						      int dflags, char *label)
+{
+	return -EINVAL;
+}
+
 static inline void of_pci_check_probe_only(void) { }
 #endif