mtd: sh_flctl: Add power management with QoS request
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> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
42d7fbe223
commit
cfe781946d
|
@ -26,6 +26,7 @@
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
|
#include <linux/pm_runtime.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
|
||||||
#include <linux/mtd/mtd.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);
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
||||||
uint32_t read_cmd = 0;
|
uint32_t read_cmd = 0;
|
||||||
|
|
||||||
|
pm_runtime_get_sync(&flctl->pdev->dev);
|
||||||
|
|
||||||
flctl->read_bytes = 0;
|
flctl->read_bytes = 0;
|
||||||
if (command != NAND_CMD_PAGEPROG)
|
if (command != NAND_CMD_PAGEPROG)
|
||||||
flctl->index = 0;
|
flctl->index = 0;
|
||||||
|
@ -670,7 +673,7 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command,
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
goto runtime_exit;
|
||||||
|
|
||||||
read_normal_exit:
|
read_normal_exit:
|
||||||
writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */
|
writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */
|
||||||
|
@ -678,23 +681,47 @@ read_normal_exit:
|
||||||
start_translation(flctl);
|
start_translation(flctl);
|
||||||
read_fiforeg(flctl, flctl->read_bytes, 0);
|
read_fiforeg(flctl, flctl->read_bytes, 0);
|
||||||
wait_completion(flctl);
|
wait_completion(flctl);
|
||||||
|
runtime_exit:
|
||||||
|
pm_runtime_put_sync(&flctl->pdev->dev);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flctl_select_chip(struct mtd_info *mtd, int chipnr)
|
static void flctl_select_chip(struct mtd_info *mtd, int chipnr)
|
||||||
{
|
{
|
||||||
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
struct sh_flctl *flctl = mtd_to_flctl(mtd);
|
||||||
|
int ret;
|
||||||
|
|
||||||
switch (chipnr) {
|
switch (chipnr) {
|
||||||
case -1:
|
case -1:
|
||||||
flctl->flcmncr_base &= ~CE0_ENABLE;
|
flctl->flcmncr_base &= ~CE0_ENABLE;
|
||||||
|
|
||||||
|
pm_runtime_get_sync(&flctl->pdev->dev);
|
||||||
writel(flctl->flcmncr_base, FLCMNCR(flctl));
|
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;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
flctl->flcmncr_base |= CE0_ENABLE;
|
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));
|
writel(HOLDEN, FLHOLDCR(flctl));
|
||||||
|
pm_runtime_put_sync(&flctl->pdev->dev);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BUG();
|
BUG();
|
||||||
|
@ -835,13 +862,13 @@ static int __devinit flctl_probe(struct platform_device *pdev)
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
dev_err(&pdev->dev, "failed to get I/O memory\n");
|
dev_err(&pdev->dev, "failed to get I/O memory\n");
|
||||||
goto err;
|
goto err_iomap;
|
||||||
}
|
}
|
||||||
|
|
||||||
flctl->reg = ioremap(res->start, resource_size(res));
|
flctl->reg = ioremap(res->start, resource_size(res));
|
||||||
if (flctl->reg == NULL) {
|
if (flctl->reg == NULL) {
|
||||||
dev_err(&pdev->dev, "failed to remap I/O memory\n");
|
dev_err(&pdev->dev, "failed to remap I/O memory\n");
|
||||||
goto err;
|
goto err_iomap;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, flctl);
|
platform_set_drvdata(pdev, flctl);
|
||||||
|
@ -871,23 +898,28 @@ static int __devinit flctl_probe(struct platform_device *pdev)
|
||||||
nand->read_word = flctl_read_word;
|
nand->read_word = flctl_read_word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pm_runtime_enable(&pdev->dev);
|
||||||
|
pm_runtime_resume(&pdev->dev);
|
||||||
|
|
||||||
ret = nand_scan_ident(flctl_mtd, 1, NULL);
|
ret = nand_scan_ident(flctl_mtd, 1, NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err_chip;
|
||||||
|
|
||||||
ret = flctl_chip_init_tail(flctl_mtd);
|
ret = flctl_chip_init_tail(flctl_mtd);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err_chip;
|
||||||
|
|
||||||
ret = nand_scan_tail(flctl_mtd);
|
ret = nand_scan_tail(flctl_mtd);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err_chip;
|
||||||
|
|
||||||
mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
|
mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err_chip:
|
||||||
|
pm_runtime_disable(&pdev->dev);
|
||||||
|
err_iomap:
|
||||||
kfree(flctl);
|
kfree(flctl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -897,6 +929,7 @@ static int __devexit flctl_remove(struct platform_device *pdev)
|
||||||
struct sh_flctl *flctl = platform_get_drvdata(pdev);
|
struct sh_flctl *flctl = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
nand_release(&flctl->mtd);
|
nand_release(&flctl->mtd);
|
||||||
|
pm_runtime_disable(&pdev->dev);
|
||||||
kfree(flctl);
|
kfree(flctl);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <linux/mtd/mtd.h>
|
#include <linux/mtd/mtd.h>
|
||||||
#include <linux/mtd/nand.h>
|
#include <linux/mtd/nand.h>
|
||||||
#include <linux/mtd/partitions.h>
|
#include <linux/mtd/partitions.h>
|
||||||
|
#include <linux/pm_qos.h>
|
||||||
|
|
||||||
/* FLCTL registers */
|
/* FLCTL registers */
|
||||||
#define FLCMNCR(f) (f->reg + 0x0)
|
#define FLCMNCR(f) (f->reg + 0x0)
|
||||||
|
@ -131,6 +132,7 @@ struct sh_flctl {
|
||||||
struct mtd_info mtd;
|
struct mtd_info mtd;
|
||||||
struct nand_chip chip;
|
struct nand_chip chip;
|
||||||
struct platform_device *pdev;
|
struct platform_device *pdev;
|
||||||
|
struct dev_pm_qos_request pm_qos;
|
||||||
void __iomem *reg;
|
void __iomem *reg;
|
||||||
|
|
||||||
uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */
|
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 page_size:1; /* NAND page size (0 = 512, 1 = 2048) */
|
||||||
unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */
|
unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */
|
||||||
unsigned holden:1; /* Hardware has FLHOLDCR and HOLDEN is set */
|
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 {
|
struct sh_flctl_platform_data {
|
||||||
|
|
Loading…
Reference in New Issue