All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops
@ 2012-07-02  5:58 Shiraz Hashim
  2012-07-02  5:58 ` [PATCH 2/3] mtd/spear_smi: clear status register on init Shiraz Hashim
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shiraz Hashim @ 2012-07-02  5:58 UTC (permalink / raw)
  To: dwmw2, viresh.linux
  Cc: spear--sw-devel, sr, linux-mtd, Viresh Kumar, spear-devel

From: Viresh Kumar <viresh.kumar@st.com>

Use dev_pm_ops to support PM specific callbacks.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/mtd/devices/spear_smi.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index 6796036..cffd36a 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/param.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/spear_smi.h>
@@ -1086,29 +1087,33 @@ static int __devexit spear_smi_remove(struct platform_device *pdev)
 	return 0;
 }
 
-int spear_smi_suspend(struct platform_device *pdev, pm_message_t state)
+#ifdef CONFIG_PM
+static int spear_smi_suspend(struct device *dev)
 {
-	struct spear_smi *dev = platform_get_drvdata(pdev);
+	struct spear_smi *sdev = dev_get_drvdata(dev);
 
-	if (dev && dev->clk)
-		clk_disable_unprepare(dev->clk);
+	if (sdev && sdev->clk)
+		clk_disable_unprepare(sdev->clk);
 
 	return 0;
 }
 
-int spear_smi_resume(struct platform_device *pdev)
+static int spear_smi_resume(struct device *dev)
 {
-	struct spear_smi *dev = platform_get_drvdata(pdev);
+	struct spear_smi *sdev = dev_get_drvdata(dev);
 	int ret = -EPERM;
 
-	if (dev && dev->clk)
-		ret = clk_prepare_enable(dev->clk);
+	if (sdev && sdev->clk)
+		ret = clk_prepare_enable(sdev->clk);
 
 	if (!ret)
-		spear_smi_hw_init(dev);
+		spear_smi_hw_init(sdev);
 	return ret;
 }
 
+static SIMPLE_DEV_PM_OPS(spear_smi_pm_ops, spear_smi_suspend, spear_smi_resume);
+#endif
+
 #ifdef CONFIG_OF
 static const struct of_device_id spear_smi_id_table[] = {
 	{ .compatible = "st,spear600-smi" },
@@ -1123,11 +1128,12 @@ static struct platform_driver spear_smi_driver = {
 		.bus = &platform_bus_type,
 		.owner = THIS_MODULE,
 		.of_match_table = of_match_ptr(spear_smi_id_table),
+#ifdef CONFIG_PM
+		.pm = &spear_smi_pm_ops,
+#endif
 	},
 	.probe = spear_smi_probe,
 	.remove = __devexit_p(spear_smi_remove),
-	.suspend = spear_smi_suspend,
-	.resume = spear_smi_resume,
 };
 
 static int spear_smi_init(void)
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] mtd/spear_smi: clear status register on init
  2012-07-02  5:58 [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Shiraz Hashim
@ 2012-07-02  5:58 ` Shiraz Hashim
  2012-07-02  5:58 ` [PATCH 3/3] mtd/spear_smi: handle return value of timeouts properly Shiraz Hashim
  2012-07-03 11:49 ` [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Shiraz Hashim @ 2012-07-02  5:58 UTC (permalink / raw)
  To: dwmw2, viresh.linux
  Cc: Shiraz Hashim, spear--sw-devel, sr, linux-mtd, spear-devel

It was observed that sometimes smi returned errors while resume from
suspend.

For safety reasons clear status register for any errors during init. In
absence of it smi can return failures during command transmissions.

Signed-off-by: Shiraz Hashim <shiraz.hashim@st.com>
---
 drivers/mtd/devices/spear_smi.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index cffd36a..aec941e 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -336,6 +336,9 @@ static void spear_smi_hw_init(struct spear_smi *dev)
 	val = HOLD1 | BANK_EN | DSEL_TIME | (prescale << 8);
 
 	mutex_lock(&dev->lock);
+	/* clear all interrupt conditions */
+	writel(0, dev->io_base + SMI_SR);
+
 	writel(val, dev->io_base + SMI_CR1);
 	mutex_unlock(&dev->lock);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] mtd/spear_smi: handle return value of timeouts properly
  2012-07-02  5:58 [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Shiraz Hashim
  2012-07-02  5:58 ` [PATCH 2/3] mtd/spear_smi: clear status register on init Shiraz Hashim
@ 2012-07-02  5:58 ` Shiraz Hashim
  2012-07-03 11:49 ` [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Shiraz Hashim @ 2012-07-02  5:58 UTC (permalink / raw)
  To: dwmw2, viresh.linux
  Cc: Antonio BORNEO, spear--sw-devel, spear-devel, Vipin Kumar,
	Shiraz Hashim, linux-mtd, sr

From: Vipin Kumar <vipin.kumar@st.com>

Handle timouts in general and return value of
'wait_event_interruptible_timeout' in particular, to capture all
conditions.

'wait_event_interruptible_timeout' returns either of the following three
values :-
   * 0               - time out occurred.
   * negative
      * -ERESTARTSYS - return because of a signal
      * other        - for a real error
   * positive        - time remaining

Fix particularly 'ERESTARTSYS' condition which is not properly handled
by the smi driver at a couple of places leading to an erroneous
situation.

Signed-off-by: Antonio BORNEO <antonio.borneo@st.com>
Signed-off-by: Shiraz Hashim <shiraz.hashim@st.com>
Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
---
 drivers/mtd/devices/spear_smi.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index aec941e..b85f183 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -241,8 +241,8 @@ static int spear_smi_read_sr(struct spear_smi *dev, u32 bank)
 	/* copy dev->status (lower 16 bits) in order to release lock */
 	if (ret > 0)
 		ret = dev->status & 0xffff;
-	else
-		ret = -EIO;
+	else if (ret == 0)
+		ret = -ETIMEDOUT;
 
 	/* restore the ctrl regs state */
 	writel(ctrlreg1, dev->io_base + SMI_CR1);
@@ -270,16 +270,19 @@ static int spear_smi_wait_till_ready(struct spear_smi *dev, u32 bank,
 	finish = jiffies + timeout;
 	do {
 		status = spear_smi_read_sr(dev, bank);
-		if (status < 0)
-			continue; /* try till timeout */
-		else if (!(status & SR_WIP))
+		if (status < 0) {
+			if (status == -ETIMEDOUT)
+				continue; /* try till finish */
+			return status;
+		} else if (!(status & SR_WIP)) {
 			return 0;
+		}
 
 		cond_resched();
 	} while (!time_after_eq(jiffies, finish));
 
 	dev_err(&dev->pdev->dev, "smi controller is busy, timeout\n");
-	return status;
+	return -EBUSY;
 }
 
 /**
@@ -395,11 +398,11 @@ static int spear_smi_write_enable(struct spear_smi *dev, u32 bank)
 	writel(ctrlreg1, dev->io_base + SMI_CR1);
 	writel(0, dev->io_base + SMI_CR2);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		ret = -EIO;
 		dev_err(&dev->pdev->dev,
 			"smi controller failed on write enable\n");
-	} else {
+	} else if (ret > 0) {
 		/* check whether write mode status is set for required bank */
 		if (dev->status & (1 << (bank + WM_SHIFT)))
 			ret = 0;
@@ -466,10 +469,10 @@ static int spear_smi_erase_sector(struct spear_smi *dev,
 	ret = wait_event_interruptible_timeout(dev->cmd_complete,
 			dev->status & TFF, SMI_CMD_TIMEOUT);
 
-	if (ret <= 0) {
+	if (ret == 0) {
 		ret = -EIO;
 		dev_err(&dev->pdev->dev, "sector erase failed\n");
-	} else
+	} else if (ret > 0)
 		ret = 0; /* success */
 
 	/* restore ctrl regs */
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops
  2012-07-02  5:58 [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Shiraz Hashim
  2012-07-02  5:58 ` [PATCH 2/3] mtd/spear_smi: clear status register on init Shiraz Hashim
  2012-07-02  5:58 ` [PATCH 3/3] mtd/spear_smi: handle return value of timeouts properly Shiraz Hashim
@ 2012-07-03 11:49 ` Artem Bityutskiy
  2 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2012-07-03 11:49 UTC (permalink / raw)
  To: Shiraz Hashim
  Cc: Viresh Kumar, spear--sw-devel, spear-devel, viresh.linux,
	linux-mtd, sr, dwmw2

[-- Attachment #1: Type: text/plain, Size: 287 bytes --]

On Mon, 2012-07-02 at 11:28 +0530, Shiraz Hashim wrote:
> From: Viresh Kumar <viresh.kumar@st.com>
> 
> Use dev_pm_ops to support PM specific callbacks.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@st.com>

Pushed to l2-mtd.git, thanks!

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-03 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-02  5:58 [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Shiraz Hashim
2012-07-02  5:58 ` [PATCH 2/3] mtd/spear_smi: clear status register on init Shiraz Hashim
2012-07-02  5:58 ` [PATCH 3/3] mtd/spear_smi: handle return value of timeouts properly Shiraz Hashim
2012-07-03 11:49 ` [PATCH 1/3] mtd/spear_smi: Move suspend/resume to follow dev_pm_ops Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.