* [PATCH] mtd: sh_flctl: Add power management support @ 2012-03-10 15:31 Bastian Hecht 2012-03-13 11:15 ` Artem Bityutskiy 2012-03-18 14:13 ` [PATCH] mtd: sh_flctl: Add power management with QoS request Bastian Hecht 0 siblings, 2 replies; 5+ messages in thread From: Bastian Hecht @ 2012-03-10 15:31 UTC (permalink / raw) To: linux-sh, linux-mtd; +Cc: Magnus Damm, Laurent Pichart All transactions with the NAND chip require a chip enable signal. So we wrap the runtime_pm_get()/put()s around it. As registers are cached, we need no suspend()/resume() callbacks. Signed-off-by: Bastian Hecht <hechtb@gmail.com> --- drivers/mtd/nand/sh_flctl.c | 31 +++++++++++++++++++++++++------ include/linux/mtd/sh_flctl.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c index d0f1f3c..c72de39 100644 --- a/drivers/mtd/nand/sh_flctl.c +++ b/drivers/mtd/nand/sh_flctl.c @@ -26,6 +26,7 @@ #include <linux/delay.h> #include <linux/io.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/mtd/mtd.h> @@ -515,6 +516,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, struct sh_flctl *flctl = mtd_to_flctl(mtd); uint32_t read_cmd = 0; + BUG_ON(!flctl->power); + flctl->read_bytes = 0; if (command != NAND_CMD_PAGEPROG) flctl->index = 0; @@ -689,12 +692,22 @@ static void flctl_select_chip(struct mtd_info *mtd, int chipnr) case -1: flctl->flcmncr_base &= ~CE0_ENABLE; writel(flctl->flcmncr_base, FLCMNCR(flctl)); + + if (flctl->power) { + pm_runtime_put_sync(&flctl->pdev->dev); + flctl->power = 0; + } break; case 0: flctl->flcmncr_base |= CE0_ENABLE; writel(flctl->flcmncr_base, FLCMNCR(flctl)); if (flctl->holden) writel(HOLDEN, FLHOLDCR(flctl)); + + if (!flctl->power) { + pm_runtime_get_sync(&flctl->pdev->dev); + flctl->power = 1; + } break; default: BUG(); @@ -835,13 +848,13 @@ static int __devinit flctl_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "failed to get I/O memory\n"); - goto err; + goto err_iomap; } flctl->reg = ioremap(res->start, resource_size(res)); if (flctl->reg = NULL) { dev_err(&pdev->dev, "failed to remap I/O memory\n"); - goto err; + goto err_iomap; } platform_set_drvdata(pdev, flctl); @@ -871,23 +884,28 @@ static int __devinit flctl_probe(struct platform_device *pdev) nand->read_word = flctl_read_word; } + pm_runtime_enable(&pdev->dev); + pm_runtime_resume(&pdev->dev); + ret = nand_scan_ident(flctl_mtd, 1, NULL); if (ret) - goto err; + goto err_chip; ret = flctl_chip_init_tail(flctl_mtd); if (ret) - goto err; + goto err_chip; ret = nand_scan_tail(flctl_mtd); if (ret) - goto err; + goto err_chip; mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts); return 0; -err: +err_chip: + pm_runtime_disable(&pdev->dev); +err_iomap: kfree(flctl); return ret; } @@ -897,6 +915,7 @@ static int __devexit flctl_remove(struct platform_device *pdev) struct sh_flctl *flctl = platform_get_drvdata(pdev); nand_release(&flctl->mtd); + pm_runtime_disable(&pdev->dev); kfree(flctl); return 0; diff --git a/include/linux/mtd/sh_flctl.h b/include/linux/mtd/sh_flctl.h index 8bcf299..f34a0a1 100644 --- a/include/linux/mtd/sh_flctl.h +++ b/include/linux/mtd/sh_flctl.h @@ -149,6 +149,7 @@ struct sh_flctl { unsigned page_size:1; /* NAND page size (0 = 512, 1 = 2048) */ unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */ unsigned holden:1; /* Hardware has FLHOLDCR and HOLDEN is set */ + unsigned power:1; /* RTPM flag */ }; struct sh_flctl_platform_data { -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: sh_flctl: Add power management support 2012-03-10 15:31 [PATCH] mtd: sh_flctl: Add power management support Bastian Hecht @ 2012-03-13 11:15 ` Artem Bityutskiy 2012-03-18 14:13 ` Bastian Hecht 2012-03-18 14:13 ` [PATCH] mtd: sh_flctl: Add power management with QoS request Bastian Hecht 1 sibling, 1 reply; 5+ messages in thread From: Artem Bityutskiy @ 2012-03-13 11:15 UTC (permalink / raw) To: Bastian Hecht; +Cc: Magnus Damm, linux-mtd, Laurent Pichart, linux-sh [-- Attachment #1: Type: text/plain, Size: 376 bytes --] On Sat, 2012-03-10 at 16:31 +0100, Bastian Hecht wrote: > All transactions with the NAND chip require a chip enable signal. So we > wrap the runtime_pm_get()/put()s around it. As registers are cached, we > need no suspend()/resume() callbacks. > > Signed-off-by: Bastian Hecht <hechtb@gmail.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] 5+ messages in thread
* Re: [PATCH] mtd: sh_flctl: Add power management support 2012-03-13 11:15 ` Artem Bityutskiy @ 2012-03-18 14:13 ` Bastian Hecht 0 siblings, 0 replies; 5+ messages in thread From: Bastian Hecht @ 2012-03-18 14:13 UTC (permalink / raw) To: dedekind1; +Cc: Magnus Damm, linux-mtd, Laurent Pichart, linux-sh 2012/3/13 Artem Bityutskiy <dedekind1@gmail.com>: > On Sat, 2012-03-10 at 16:31 +0100, Bastian Hecht wrote: >> All transactions with the NAND chip require a chip enable signal. So we >> wrap the runtime_pm_get()/put()s around it. As registers are cached, we >> need no suspend()/resume() callbacks. >> >> Signed-off-by: Bastian Hecht <hechtb@gmail.com> > > Pushed to l2-mtd.git, thanks. Ouch, I've realized that I've sent an old incorrect version where 2 code blocks are swapped. I write to the device before calling runtime_pm_get(). As I was on the way to a new version anyway, I've finished it today and suggest you drop this one and consider pushing the new one. I post it after this mail. Sorry. Best regards, Bastian Hecht > -- > Best Regards, > Artem Bityutskiy ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] mtd: sh_flctl: Add power management with QoS request 2012-03-10 15:31 [PATCH] mtd: sh_flctl: Add power management support Bastian Hecht 2012-03-13 11:15 ` Artem Bityutskiy @ 2012-03-18 14:13 ` Bastian Hecht 2012-03-19 14:13 ` Artem Bityutskiy 1 sibling, 1 reply; 5+ messages in thread From: Bastian Hecht @ 2012-03-18 14:13 UTC (permalink / raw) To: dedekind1, linux-sh, linux-mtd; +Cc: Magnus Damm, Laurent Pichart Adds power management code with fine granularity. Every flash control command is enclosed by runtime_put()/get()s. To make sure that no overhead is generated by too frequent power state switches, a quality of service request is issued. Signed-off-by: Bastian Hecht <hechtb@gmail.com> --- The QoS request states the following: "Please don't go into a power state, from that you can't wake in less than 100 microseconds." On a sh7372 this could happen if the power domain of the FLCTL is shut down. This hurts performance - we don't want this. The patch is based on top of the "SH Mobile sh_flctl driver brush up" patch series. The rtpm patch that I've posted a few days ago contains a stupid mix-up, so I'd suggest to drop it and use this more advanced patch directly. drivers/mtd/nand/sh_flctl.c | 51 ++++++++++++++++++++++++++++++++++------- include/linux/mtd/sh_flctl.h | 3 ++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c index d0f1f3c..6199004 100644 --- a/drivers/mtd/nand/sh_flctl.c +++ b/drivers/mtd/nand/sh_flctl.c @@ -26,6 +26,7 @@ #include <linux/delay.h> #include <linux/io.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/mtd/mtd.h> @@ -515,6 +516,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, struct sh_flctl *flctl = mtd_to_flctl(mtd); uint32_t read_cmd = 0; + pm_runtime_get_sync(&flctl->pdev->dev); + flctl->read_bytes = 0; if (command != NAND_CMD_PAGEPROG) flctl->index = 0; @@ -670,7 +673,7 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, default: break; } - return; + goto runtime_exit; read_normal_exit: writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ @@ -678,23 +681,47 @@ read_normal_exit: start_translation(flctl); read_fiforeg(flctl, flctl->read_bytes, 0); wait_completion(flctl); +runtime_exit: + pm_runtime_put_sync(&flctl->pdev->dev); return; } static void flctl_select_chip(struct mtd_info *mtd, int chipnr) { struct sh_flctl *flctl = mtd_to_flctl(mtd); + int ret; switch (chipnr) { case -1: flctl->flcmncr_base &= ~CE0_ENABLE; + + pm_runtime_get_sync(&flctl->pdev->dev); writel(flctl->flcmncr_base, FLCMNCR(flctl)); + + if (flctl->qos_request) { + dev_pm_qos_remove_request(&flctl->pm_qos); + flctl->qos_request = 0; + } + + pm_runtime_put_sync(&flctl->pdev->dev); break; case 0: flctl->flcmncr_base |= CE0_ENABLE; - writel(flctl->flcmncr_base, FLCMNCR(flctl)); - if (flctl->holden) + + if (!flctl->qos_request) { + ret = dev_pm_qos_add_request(&flctl->pdev->dev, + &flctl->pm_qos, 100); + if (ret < 0) + dev_err(&flctl->pdev->dev, + "PM QoS request failed: %d\n", ret); + flctl->qos_request = 1; + } + + if (flctl->holden) { + pm_runtime_get_sync(&flctl->pdev->dev); writel(HOLDEN, FLHOLDCR(flctl)); + pm_runtime_put_sync(&flctl->pdev->dev); + } break; default: BUG(); @@ -835,13 +862,13 @@ static int __devinit flctl_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "failed to get I/O memory\n"); - goto err; + goto err_iomap; } flctl->reg = ioremap(res->start, resource_size(res)); if (flctl->reg = NULL) { dev_err(&pdev->dev, "failed to remap I/O memory\n"); - goto err; + goto err_iomap; } platform_set_drvdata(pdev, flctl); @@ -871,23 +898,28 @@ static int __devinit flctl_probe(struct platform_device *pdev) nand->read_word = flctl_read_word; } + pm_runtime_enable(&pdev->dev); + pm_runtime_resume(&pdev->dev); + ret = nand_scan_ident(flctl_mtd, 1, NULL); if (ret) - goto err; + goto err_chip; ret = flctl_chip_init_tail(flctl_mtd); if (ret) - goto err; + goto err_chip; ret = nand_scan_tail(flctl_mtd); if (ret) - goto err; + goto err_chip; mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts); return 0; -err: +err_chip: + pm_runtime_disable(&pdev->dev); +err_iomap: kfree(flctl); return ret; } @@ -897,6 +929,7 @@ static int __devexit flctl_remove(struct platform_device *pdev) struct sh_flctl *flctl = platform_get_drvdata(pdev); nand_release(&flctl->mtd); + pm_runtime_disable(&pdev->dev); kfree(flctl); return 0; diff --git a/include/linux/mtd/sh_flctl.h b/include/linux/mtd/sh_flctl.h index 8bcf299..a38e1fa 100644 --- a/include/linux/mtd/sh_flctl.h +++ b/include/linux/mtd/sh_flctl.h @@ -23,6 +23,7 @@ #include <linux/mtd/mtd.h> #include <linux/mtd/nand.h> #include <linux/mtd/partitions.h> +#include <linux/pm_qos.h> /* FLCTL registers */ #define FLCMNCR(f) (f->reg + 0x0) @@ -131,6 +132,7 @@ struct sh_flctl { struct mtd_info mtd; struct nand_chip chip; struct platform_device *pdev; + struct dev_pm_qos_request pm_qos; void __iomem *reg; uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */ @@ -149,6 +151,7 @@ struct sh_flctl { unsigned page_size:1; /* NAND page size (0 = 512, 1 = 2048) */ unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */ unsigned holden:1; /* Hardware has FLHOLDCR and HOLDEN is set */ + unsigned qos_request:1; /* QoS request to prevent deep power shutdown */ }; struct sh_flctl_platform_data { -- 1.7.5.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: sh_flctl: Add power management with QoS request 2012-03-18 14:13 ` [PATCH] mtd: sh_flctl: Add power management with QoS request Bastian Hecht @ 2012-03-19 14:13 ` Artem Bityutskiy 0 siblings, 0 replies; 5+ messages in thread From: Artem Bityutskiy @ 2012-03-19 14:13 UTC (permalink / raw) To: Bastian Hecht; +Cc: Magnus Damm, linux-mtd, Laurent Pichart, linux-sh [-- Attachment #1: Type: text/plain, Size: 448 bytes --] On Sun, 2012-03-18 at 15:13 +0100, Bastian Hecht wrote: > Adds power management code with fine granularity. Every flash control > command is enclosed by runtime_put()/get()s. To make sure that no > overhead is generated by too frequent power state switches, a quality of > service request is issued. > > Signed-off-by: Bastian Hecht <hechtb@gmail.com> Pushed instead of the older version, 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] 5+ messages in thread
end of thread, other threads:[~2012-03-19 14:13 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-03-10 15:31 [PATCH] mtd: sh_flctl: Add power management support Bastian Hecht 2012-03-13 11:15 ` Artem Bityutskiy 2012-03-18 14:13 ` Bastian Hecht 2012-03-18 14:13 ` [PATCH] mtd: sh_flctl: Add power management with QoS request Bastian Hecht 2012-03-19 14:13 ` Artem Bityutskiy
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).