Module: xenomai-3
Branch: wip/rtnet-fixes
Commit: 062ed8e1d9c38a4aa3f058561654600b37fb6c5d
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=062ed8e1d9c38a4aa3f058561654600b37fb6c5d

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Jan  9 17:40:39 2018 +0100

drivers/gpio: expose GPIO chip allocation routine

For creating a new RTDM-based GPIO chip descriptor (struct
rtdm_gpio_chip), mapped to its regular counterpart (struct gpio_chip).

---

 kernel/drivers/gpio/gpio-core.c |   64 +++++++++++++++++++--------------------
 kernel/drivers/gpio/gpio-core.h |    3 ++
 2 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/kernel/drivers/gpio/gpio-core.c b/kernel/drivers/gpio/gpio-core.c
index c19b1f7..05eafb1 100644
--- a/kernel/drivers/gpio/gpio-core.c
+++ b/kernel/drivers/gpio/gpio-core.c
@@ -40,6 +40,10 @@ struct rtdm_gpio_chan {
                is_interrupt : 1;
 };
 
+static LIST_HEAD(rtdm_gpio_chips);
+
+static DEFINE_MUTEX(chip_lock);
+
 static int gpio_pin_interrupt(rtdm_irq_t *irqh)
 {
        struct rtdm_gpio_pin *pin;
@@ -425,11 +429,34 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc,
 }
 EXPORT_SYMBOL_GPL(rtdm_gpiochip_add);
 
-void rtdm_gpiochip_remove(struct rtdm_gpio_chip *rgc)
+int rtdm_gpiochip_alloc(struct gpio_chip *gc, int gpio_subclass)
 {
-       if (!realtime_core_enabled())
-               return;
+       struct rtdm_gpio_chip *rgc;
+       int ret;
 
+       rgc = kzalloc(sizeof(*rgc), GFP_KERNEL);
+       if (rgc == NULL)
+               return -ENOMEM;
+
+       ret = rtdm_gpiochip_add(rgc, gc, gpio_subclass);
+       if (ret) {
+               kfree(rgc);
+               return ret;
+       }
+
+       mutex_lock(&chip_lock);
+       list_add(&rgc->next, &rtdm_gpio_chips);
+       mutex_unlock(&chip_lock);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(rtdm_gpiochip_alloc);
+
+void rtdm_gpiochip_remove(struct rtdm_gpio_chip *rgc)
+{
+       mutex_lock(&chip_lock);
+       list_del(&rgc->next);
+       mutex_unlock(&chip_lock);
        delete_pin_devices(rgc);
        class_destroy(rgc->devclass);
 }
@@ -463,10 +490,6 @@ EXPORT_SYMBOL_GPL(rtdm_gpiochip_add_by_name);
 
 #include <linux/of_platform.h>
 
-LIST_HEAD(rtdm_gpio_chips);
-
-static DEFINE_MUTEX(chip_lock);
-
 struct gpiochip_holder {
        struct gpio_chip *chip;
        struct list_head next;
@@ -497,28 +520,6 @@ static int match_gpio_chip(struct gpio_chip *gc, void 
*data)
        return 0;
 }
 
-static int add_gpio_chip(struct gpio_chip *gc, int type)
-{
-       struct rtdm_gpio_chip *rgc;
-       int ret;
-
-       rgc = kzalloc(sizeof(*rgc), GFP_KERNEL);
-       if (rgc == NULL)
-               return -ENOMEM;
-
-       ret = rtdm_gpiochip_add(rgc, gc, type);
-       if (ret) {
-               kfree(rgc);
-               return ret;
-       }
-
-       mutex_lock(&chip_lock);
-       list_add(&rgc->next, &rtdm_gpio_chips);
-       mutex_unlock(&chip_lock);
-
-       return 0;
-}
-
 int rtdm_gpiochip_scan_of(struct device_node *from, const char *compat,
                          int type)
 {
@@ -543,7 +544,7 @@ int rtdm_gpiochip_scan_of(struct device_node *from, const 
char *compat,
                        ret = 0;
                        list_for_each_entry_safe(h, n, &match.list, next) {
                                list_del(&h->next);
-                               _ret = add_gpio_chip(h->chip, type);
+                               _ret = rtdm_gpiochip_alloc(h->chip, type);
                                kfree(h);
                                if (_ret && !ret)
                                        ret = _ret;
@@ -563,9 +564,6 @@ void rtdm_gpiochip_remove_of(int type)
 
        list_for_each_entry_safe(rgc, n, &rtdm_gpio_chips, next) {
                if (rgc->driver.profile_info.subclass_id == type) {
-                       mutex_lock(&chip_lock);
-                       list_del(&rgc->next);
-                       mutex_unlock(&chip_lock);
                        rtdm_gpiochip_remove(rgc);
                        kfree(rgc);
                }
diff --git a/kernel/drivers/gpio/gpio-core.h b/kernel/drivers/gpio/gpio-core.h
index 11249e8..96e0f7b 100644
--- a/kernel/drivers/gpio/gpio-core.h
+++ b/kernel/drivers/gpio/gpio-core.h
@@ -38,6 +38,9 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc,
                      struct gpio_chip *gc,
                      int gpio_subclass);
 
+int rtdm_gpiochip_alloc(struct gpio_chip *gc,
+                       int gpio_subclass);
+
 void rtdm_gpiochip_remove(struct rtdm_gpio_chip *rgc);
 
 int rtdm_gpiochip_add_by_name(struct rtdm_gpio_chip *rgc,


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to