linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: avinashphilip@ti.com (Philip Avinash)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/4] mtd: devices: elm: Low power transition support
Date: Wed, 23 Jan 2013 15:15:44 +0530	[thread overview]
Message-ID: <1358934346-16822-3-git-send-email-avinashphilip@ti.com> (raw)
In-Reply-To: <1358933176-12409-1-git-send-email-avinashphilip@ti.com>

In low power modes of AM335X platforms, peripherals power is cut off.
This patch supports low power sleep transition support for ELM driver.

Signed-off-by: Philip Avinash <avinashphilip@ti.com>
---
 drivers/mtd/devices/elm.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/mtd/devices/elm.c b/drivers/mtd/devices/elm.c
index f78f43f..4793cb0 100644
--- a/drivers/mtd/devices/elm.c
+++ b/drivers/mtd/devices/elm.c
@@ -20,6 +20,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/of.h>
+#include <linux/sched.h>
 #include <linux/pm_runtime.h>
 #include <linux/platform_data/elm.h>
 
@@ -62,6 +63,7 @@ struct elm_info {
 	struct completion elm_completion;
 	struct list_head list;
 	enum bch_ecc bch_type;
+	bool idle;
 };
 
 static LIST_HEAD(elm_devices);
@@ -86,9 +88,11 @@ void elm_config(struct device *dev, enum bch_ecc bch_type)
 	u32 reg_val;
 	struct elm_info *info = dev_get_drvdata(dev);
 
+	info->idle = true;
 	reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16);
 	elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val);
 	info->bch_type = bch_type;
+	info->idle = false;
 }
 EXPORT_SYMBOL(elm_config);
 
@@ -280,6 +284,7 @@ void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc,
 	struct elm_info *info = dev_get_drvdata(dev);
 	u32 reg_val;
 
+	info->idle = true;
 	/* Enable page mode interrupt */
 	reg_val = elm_read_reg(info, ELM_IRQSTATUS);
 	elm_write_reg(info, ELM_IRQSTATUS, reg_val & INTR_STATUS_PAGE_VALID);
@@ -298,6 +303,7 @@ void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc,
 	reg_val = elm_read_reg(info, ELM_IRQENABLE);
 	elm_write_reg(info, ELM_IRQENABLE, reg_val & ~INTR_EN_PAGE_MASK);
 	elm_error_correction(info, err_vec);
+	info->idle = false;
 }
 EXPORT_SYMBOL(elm_decode_bch_error_page);
 
@@ -368,6 +374,7 @@ static int elm_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&info->list);
 	list_add(&info->list, &elm_devices);
 	platform_set_drvdata(pdev, info);
+	info->idle = false;
 	return ret;
 }
 
@@ -379,6 +386,38 @@ static int elm_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int elm_suspend(struct device *dev)
+{
+	struct elm_info *info = dev_get_drvdata(dev);
+	wait_queue_head_t wq;
+	DECLARE_WAITQUEUE(wait, current);
+
+	init_waitqueue_head(&wq);
+	while (1) {
+		/* Make sure that ELM not running */
+		if (info->idle) {
+			add_wait_queue(&wq, &wait);
+			schedule();
+			remove_wait_queue(&wq, &wait);
+		} else {
+			break;
+		}
+	}
+	pm_runtime_put_sync(dev);
+	return 0;
+}
+
+static int elm_resume(struct device *dev)
+{
+	struct elm_info *info = dev_get_drvdata(dev);
+
+	pm_runtime_get_sync(dev);
+	elm_config(dev, info->bch_type);
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(elm_pm_ops, elm_suspend, elm_resume);
+
 #ifdef CONFIG_OF
 static const struct of_device_id elm_of_match[] = {
 	{ .compatible = "ti,am33xx-elm" },
@@ -392,6 +431,7 @@ static struct platform_driver elm_driver = {
 		.name	= "elm",
 		.owner	= THIS_MODULE,
 		.of_match_table = of_match_ptr(elm_of_match),
+		.pm	= &elm_pm_ops,
 	},
 	.probe	= elm_probe,
 	.remove	= elm_remove,
-- 
1.7.9.5

  parent reply	other threads:[~2013-01-23  9:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-23  9:26 [PATCH 0/4] LOW power sleep support for OMAP nand driver Philip Avinash
2013-01-23  9:26 ` [PATCH 1/4] arch: arm: gpmc: gpmc migration support Philip Avinash
2013-02-01 22:05   ` Tony Lindgren
2013-02-06 11:38     ` Philip, Avinash
2013-01-23  9:45 ` Philip Avinash [this message]
2013-01-23  9:45 ` [PATCH 3/4] arm: gpmc: Low power transition support Philip Avinash
2013-01-23  9:45 ` [PATCH 4/4] mtd: nand: omap2: " Philip Avinash

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358934346-16822-3-git-send-email-avinashphilip@ti.com \
    --to=avinashphilip@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).