[PATCH v2] gpio/omap: add *remove* callback in platform_driver

2012-08-08 Thread Tarun Kanti DebBarma
Add *remove* callback so that necessary cleanup operations are
performed when device is unregistered. The device is deleted
from the list and associated clock handle is released by
calling clk_put() and irq descriptor is released using the
irq_free_desc() api.

Signed-off-by: Tarun Kanti DebBarma 
Reported-by: Paul Walmsley 
Reviewed-by: Jon Hunter 
Cc: Kevin Hilman 
Cc: Rajendra Nayak 
Cc: Santosh Shilimkar 
Cc: Cousson, Benoit 
Cc: Paul Walmsley 
---
v2:
Baseline: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Commit: 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (Linux 3.6-rc1)

(1) Use irq_free_descs() instead of irq_free_desc().
Besides, irq_free_desc() was using wrong parameter,
irq_base, instead of bank->irq.
(2) irq_free_descs() moved outside spin_lock/unlock_*()
in order to avoid exception warnings.

(3) pm_runtime_disable() added so that bind can happen successfully

Test Detail:
Step 1: Unbind gpio.5 device in order to invoke the *remove* callback.
#echo "omap_gpio.5" > sys/bus/platform/drivers/omap_gpio/unbind

Step 2: Bind gpio.5 device and confirm probe() for the device succeeds.
#echo "omap_gpio.5" > sys/bus/platform/drivers/omap_gpio/bind

Step 3: Execute read/write GPIO test case.

 drivers/gpio/gpio-omap.c |   35 +++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index e6efd77..50de875 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1152,6 +1152,40 @@ static int __devinit omap_gpio_probe(struct 
platform_device *pdev)
return ret;
 }
 
+/**
+ * omap_gpio_remove - cleanup a registered gpio device
+ * @pdev:   pointer to current gpio platform device
+ *
+ * Called by driver framework whenever a gpio device is unregistered.
+ * GPIO is deleted from the list and associated clock handle freed.
+ */
+static int __devexit omap_gpio_remove(struct platform_device *pdev)
+{
+   struct device *dev = >dev;
+   struct gpio_bank *bank;
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   list_for_each_entry(bank, _gpio_list, node) {
+   spin_lock_irqsave(>lock, flags);
+   if (bank->dev == dev) {
+   clk_put(bank->dbck);
+   list_del(>node);
+   ret = 0;
+   spin_unlock_irqrestore(>lock, flags);
+   break;
+   }
+   spin_unlock_irqrestore(>lock, flags);
+   }
+
+   if (!ret) {
+   pm_runtime_disable(bank->dev);
+   irq_free_descs(bank->irq_base, bank->width);
+   }
+
+   return ret;
+}
+
 #ifdef CONFIG_ARCH_OMAP2PLUS
 
 #if defined(CONFIG_PM_RUNTIME)
@@ -1478,6 +1512,7 @@ MODULE_DEVICE_TABLE(of, omap_gpio_match);
 
 static struct platform_driver omap_gpio_driver = {
.probe  = omap_gpio_probe,
+   .remove = __devexit_p(omap_gpio_remove),
.driver = {
.name   = "omap_gpio",
.pm = _pm_ops,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] gpio/omap: add *remove* callback in platform_driver

2012-08-08 Thread Tarun Kanti DebBarma
Add *remove* callback so that necessary cleanup operations are
performed when device is unregistered. The device is deleted
from the list and associated clock handle is released by
calling clk_put() and irq descriptor is released using the
irq_free_desc() api.

Signed-off-by: Tarun Kanti DebBarma tarun.ka...@ti.com
Reported-by: Paul Walmsley p...@pwsan.com
Reviewed-by: Jon Hunter jon-hun...@ti.com
Cc: Kevin Hilman khil...@ti.com
Cc: Rajendra Nayak rna...@ti.com
Cc: Santosh Shilimkar santosh.shilim...@ti.com
Cc: Cousson, Benoit b-cous...@ti.com
Cc: Paul Walmsley p...@pwsan.com
---
v2:
Baseline: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Commit: 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (Linux 3.6-rc1)

(1) Use irq_free_descs() instead of irq_free_desc().
Besides, irq_free_desc() was using wrong parameter,
irq_base, instead of bank-irq.
(2) irq_free_descs() moved outside spin_lock/unlock_*()
in order to avoid exception warnings.

(3) pm_runtime_disable() added so that bind can happen successfully

Test Detail:
Step 1: Unbind gpio.5 device in order to invoke the *remove* callback.
#echo omap_gpio.5  sys/bus/platform/drivers/omap_gpio/unbind

Step 2: Bind gpio.5 device and confirm probe() for the device succeeds.
#echo omap_gpio.5  sys/bus/platform/drivers/omap_gpio/bind

Step 3: Execute read/write GPIO test case.

 drivers/gpio/gpio-omap.c |   35 +++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index e6efd77..50de875 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1152,6 +1152,40 @@ static int __devinit omap_gpio_probe(struct 
platform_device *pdev)
return ret;
 }
 
+/**
+ * omap_gpio_remove - cleanup a registered gpio device
+ * @pdev:   pointer to current gpio platform device
+ *
+ * Called by driver framework whenever a gpio device is unregistered.
+ * GPIO is deleted from the list and associated clock handle freed.
+ */
+static int __devexit omap_gpio_remove(struct platform_device *pdev)
+{
+   struct device *dev = pdev-dev;
+   struct gpio_bank *bank;
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   list_for_each_entry(bank, omap_gpio_list, node) {
+   spin_lock_irqsave(bank-lock, flags);
+   if (bank-dev == dev) {
+   clk_put(bank-dbck);
+   list_del(bank-node);
+   ret = 0;
+   spin_unlock_irqrestore(bank-lock, flags);
+   break;
+   }
+   spin_unlock_irqrestore(bank-lock, flags);
+   }
+
+   if (!ret) {
+   pm_runtime_disable(bank-dev);
+   irq_free_descs(bank-irq_base, bank-width);
+   }
+
+   return ret;
+}
+
 #ifdef CONFIG_ARCH_OMAP2PLUS
 
 #if defined(CONFIG_PM_RUNTIME)
@@ -1478,6 +1512,7 @@ MODULE_DEVICE_TABLE(of, omap_gpio_match);
 
 static struct platform_driver omap_gpio_driver = {
.probe  = omap_gpio_probe,
+   .remove = __devexit_p(omap_gpio_remove),
.driver = {
.name   = omap_gpio,
.pm = gpio_pm_ops,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] gpio/omap: move bank->dbck initialization to omap_gpio_mod_init()

2012-07-11 Thread Tarun Kanti DebBarma
Since the bank->dbck initialization in a one time operation there
is no need to keep this within gpio_debounce(). Therefore, moving
clk_get(bank->dbck) to omap_gpio_mod_init(). Since the value of
bank->dbck would be NULL at the beginning, this check has been
removed.

Signed-off-by: Tarun Kanti DebBarma 
Reported-by: Paul Walmsley 
Reviewed-by: Jon Hunter 
Cc: Kevin Hilman 
Cc: Rajendra Nayak 
Cc: Santosh Shilimkar 
Cc: Cousson, Benoit 
Cc: Paul Walmsley 
---
 drivers/gpio/gpio-omap.c |   10 --
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index c4ed172..afecdcc 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -889,12 +889,6 @@ static int gpio_debounce(struct gpio_chip *chip, unsigned 
offset,
 
bank = container_of(chip, struct gpio_bank, chip);
 
-   if (!bank->dbck) {
-   bank->dbck = clk_get(bank->dev, "dbclk");
-   if (IS_ERR(bank->dbck))
-   dev_err(bank->dev, "Could not get gpio dbck\n");
-   }
-
spin_lock_irqsave(>lock, flags);
_set_gpio_debounce(bank, offset, debounce);
spin_unlock_irqrestore(>lock, flags);
@@ -966,6 +960,10 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
 /* Initialize interface clk ungated, module enabled */
if (bank->regs->ctrl)
__raw_writel(0, base + bank->regs->ctrl);
+
+   bank->dbck = clk_get(bank->dev, "dbclk");
+   if (IS_ERR(bank->dbck))
+   dev_err(bank->dev, "Could not get gpio dbck\n");
 }
 
 static __devinit void
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] gpio/omap: add *remove* callback in platform_driver

2012-07-11 Thread Tarun Kanti DebBarma
Add *remove* callback so that necessary cleanup operations are
performed when device is unregistered. The device is deleted
from the list and associated clock handle is released by
calling clk_put() and irq descriptor is released using the
irq_free_desc() api.

Signed-off-by: Tarun Kanti DebBarma 
Reported-by: Paul Walmsley 
Reviewed-by: Jon Hunter 
Cc: Kevin Hilman 
Cc: Rajendra Nayak 
Cc: Santosh Shilimkar 
Cc: Cousson, Benoit 
Cc: Paul Walmsley 
---
 drivers/gpio/gpio-omap.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index afecdcc..08929d5 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1140,6 +1140,35 @@ static int __devinit omap_gpio_probe(struct 
platform_device *pdev)
return ret;
 }
 
+/**
+ * omap_gpio_remove - cleanup a registered gpio device
+ * @pdev:   pointer to current gpio platform device
+ *
+ * Called by driver framework whenever a gpio device is unregistered.
+ * GPIO is deleted from the list and associated clock handle freed.
+ */
+static int __devexit omap_gpio_remove(struct platform_device *pdev)
+{
+   struct device *dev = >dev;
+   struct gpio_bank *bank;
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   list_for_each_entry(bank, _gpio_list, node) {
+   spin_lock_irqsave(>lock, flags);
+   if (bank->dev == dev) {
+   list_del(>node);
+   clk_put(bank->dbck);
+   irq_free_desc(bank->irq_base);
+   ret = 0;
+   spin_unlock_irqrestore(>lock, flags);
+   break;
+   }
+   spin_unlock_irqrestore(>lock, flags);
+   }
+   return ret;
+}
+
 #ifdef CONFIG_ARCH_OMAP2PLUS
 
 #if defined(CONFIG_PM_RUNTIME)
@@ -1466,6 +1495,7 @@ MODULE_DEVICE_TABLE(of, omap_gpio_match);
 
 static struct platform_driver omap_gpio_driver = {
.probe  = omap_gpio_probe,
+   .remove = __devexit_p(omap_gpio_remove),
.driver = {
.name   = "omap_gpio",
.pm = _pm_ops,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] gpio/omap: few code realignment and update of missing code

2012-07-11 Thread Tarun Kanti DebBarma
This is in reponse to comments provided to [gpio/omap: add clk_prepare
and clk_unprepare] and is available here for reference:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-June/105762.html

Patch-1 moves the debounce clock handle initialization from gpio_debounce()
to omap_gpio_mod_init(). Since this is a one time initialization it makes
sense to keep it here. Though proposal was to keep in omap_gpio_chip_init()
I found more appropriate to keep in omap_gpio_mod_init() because it is more
related to bank specific initialization.

Patch-2 adds *.remove* callback which is missing in current implementation.
Along with other cleanup operations this function is used for releasing the
clock handle and of course calling clk_unprepare().

Reference:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Commit: bd0a521e88aa7a06ae7aabaed7ae196ed4ad867a (Linux 3.5-rc6)

Tested on: OMAP3630/ZOOM3, BLAZE

Tarun Kanti DebBarma (2):
  gpio/omap: move bank->dbck initialization to omap_gpio_mod_init()
  gpio/omap: add *remove* callback in platform_driver

 drivers/gpio/gpio-omap.c |   40 ++--
 1 files changed, 34 insertions(+), 6 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] gpio/omap: few code realignment and update of missing code

2012-07-11 Thread Tarun Kanti DebBarma
This is in reponse to comments provided to [gpio/omap: add clk_prepare
and clk_unprepare] and is available here for reference:
http://lists.infradead.org/pipermail/linux-arm-kernel/2012-June/105762.html

Patch-1 moves the debounce clock handle initialization from gpio_debounce()
to omap_gpio_mod_init(). Since this is a one time initialization it makes
sense to keep it here. Though proposal was to keep in omap_gpio_chip_init()
I found more appropriate to keep in omap_gpio_mod_init() because it is more
related to bank specific initialization.

Patch-2 adds *.remove* callback which is missing in current implementation.
Along with other cleanup operations this function is used for releasing the
clock handle and of course calling clk_unprepare().

Reference:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Commit: bd0a521e88aa7a06ae7aabaed7ae196ed4ad867a (Linux 3.5-rc6)

Tested on: OMAP3630/ZOOM3, BLAZE

Tarun Kanti DebBarma (2):
  gpio/omap: move bank-dbck initialization to omap_gpio_mod_init()
  gpio/omap: add *remove* callback in platform_driver

 drivers/gpio/gpio-omap.c |   40 ++--
 1 files changed, 34 insertions(+), 6 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] gpio/omap: add *remove* callback in platform_driver

2012-07-11 Thread Tarun Kanti DebBarma
Add *remove* callback so that necessary cleanup operations are
performed when device is unregistered. The device is deleted
from the list and associated clock handle is released by
calling clk_put() and irq descriptor is released using the
irq_free_desc() api.

Signed-off-by: Tarun Kanti DebBarma tarun.ka...@ti.com
Reported-by: Paul Walmsley p...@pwsan.com
Reviewed-by: Jon Hunter jon-hun...@ti.com
Cc: Kevin Hilman khil...@ti.com
Cc: Rajendra Nayak rna...@ti.com
Cc: Santosh Shilimkar santosh.shilim...@ti.com
Cc: Cousson, Benoit b-cous...@ti.com
Cc: Paul Walmsley p...@pwsan.com
---
 drivers/gpio/gpio-omap.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index afecdcc..08929d5 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1140,6 +1140,35 @@ static int __devinit omap_gpio_probe(struct 
platform_device *pdev)
return ret;
 }
 
+/**
+ * omap_gpio_remove - cleanup a registered gpio device
+ * @pdev:   pointer to current gpio platform device
+ *
+ * Called by driver framework whenever a gpio device is unregistered.
+ * GPIO is deleted from the list and associated clock handle freed.
+ */
+static int __devexit omap_gpio_remove(struct platform_device *pdev)
+{
+   struct device *dev = pdev-dev;
+   struct gpio_bank *bank;
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   list_for_each_entry(bank, omap_gpio_list, node) {
+   spin_lock_irqsave(bank-lock, flags);
+   if (bank-dev == dev) {
+   list_del(bank-node);
+   clk_put(bank-dbck);
+   irq_free_desc(bank-irq_base);
+   ret = 0;
+   spin_unlock_irqrestore(bank-lock, flags);
+   break;
+   }
+   spin_unlock_irqrestore(bank-lock, flags);
+   }
+   return ret;
+}
+
 #ifdef CONFIG_ARCH_OMAP2PLUS
 
 #if defined(CONFIG_PM_RUNTIME)
@@ -1466,6 +1495,7 @@ MODULE_DEVICE_TABLE(of, omap_gpio_match);
 
 static struct platform_driver omap_gpio_driver = {
.probe  = omap_gpio_probe,
+   .remove = __devexit_p(omap_gpio_remove),
.driver = {
.name   = omap_gpio,
.pm = gpio_pm_ops,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] gpio/omap: move bank-dbck initialization to omap_gpio_mod_init()

2012-07-11 Thread Tarun Kanti DebBarma
Since the bank-dbck initialization in a one time operation there
is no need to keep this within gpio_debounce(). Therefore, moving
clk_get(bank-dbck) to omap_gpio_mod_init(). Since the value of
bank-dbck would be NULL at the beginning, this check has been
removed.

Signed-off-by: Tarun Kanti DebBarma tarun.ka...@ti.com
Reported-by: Paul Walmsley p...@pwsan.com
Reviewed-by: Jon Hunter jon-hun...@ti.com
Cc: Kevin Hilman khil...@ti.com
Cc: Rajendra Nayak rna...@ti.com
Cc: Santosh Shilimkar santosh.shilim...@ti.com
Cc: Cousson, Benoit b-cous...@ti.com
Cc: Paul Walmsley p...@pwsan.com
---
 drivers/gpio/gpio-omap.c |   10 --
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index c4ed172..afecdcc 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -889,12 +889,6 @@ static int gpio_debounce(struct gpio_chip *chip, unsigned 
offset,
 
bank = container_of(chip, struct gpio_bank, chip);
 
-   if (!bank-dbck) {
-   bank-dbck = clk_get(bank-dev, dbclk);
-   if (IS_ERR(bank-dbck))
-   dev_err(bank-dev, Could not get gpio dbck\n);
-   }
-
spin_lock_irqsave(bank-lock, flags);
_set_gpio_debounce(bank, offset, debounce);
spin_unlock_irqrestore(bank-lock, flags);
@@ -966,6 +960,10 @@ static void omap_gpio_mod_init(struct gpio_bank *bank)
 /* Initialize interface clk ungated, module enabled */
if (bank-regs-ctrl)
__raw_writel(0, base + bank-regs-ctrl);
+
+   bank-dbck = clk_get(bank-dev, dbclk);
+   if (IS_ERR(bank-dbck))
+   dev_err(bank-dev, Could not get gpio dbck\n);
 }
 
 static __devinit void
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/