| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Copyright (C) 2019 Paul Cercueil <[email protected]> |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "cgu.h" |
| 7 |
#include "pm.h" |
| 8 |
|
| 9 |
#include <linux/io.h> |
| 10 |
#include <linux/syscore_ops.h> |
| 11 |
|
| 12 |
#define CGU_REG_LCR 0x04 |
| 13 |
|
| 14 |
#define LCR_LOW_POWER_MODE BIT(0) |
| 15 |
|
| 16 |
static void __iomem * __maybe_unused ingenic_cgu_base; |
| 17 |
|
| 18 |
static int __maybe_unused ingenic_cgu_pm_suspend(void *data) |
| 19 |
{ |
| 20 |
u32 val = readl(ingenic_cgu_base + CGU_REG_LCR); |
| 21 |
|
| 22 |
writel(val | LCR_LOW_POWER_MODE, ingenic_cgu_base + CGU_REG_LCR); |
| 23 |
|
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
static void __maybe_unused ingenic_cgu_pm_resume(void *data) |
| 28 |
{ |
| 29 |
u32 val = readl(ingenic_cgu_base + CGU_REG_LCR); |
| 30 |
|
| 31 |
writel(val & ~LCR_LOW_POWER_MODE, ingenic_cgu_base + CGU_REG_LCR); |
| 32 |
} |
| 33 |
|
| 34 |
static const struct syscore_ops __maybe_unused ingenic_cgu_pm_ops = { |
| 35 |
.suspend = ingenic_cgu_pm_suspend, |
| 36 |
.resume = ingenic_cgu_pm_resume, |
| 37 |
}; |
| 38 |
|
| 39 |
static struct syscore __maybe_unused ingenic_cgu_pm = { |
| 40 |
.ops = &ingenic_cgu_pm_ops, |
| 41 |
}; |
| 42 |
|
| 43 |
void ingenic_cgu_register_syscore(struct ingenic_cgu *cgu) |
| 44 |
{ |
| 45 |
if (IS_ENABLED(CONFIG_PM_SLEEP)) { |
| 46 |
ingenic_cgu_base = cgu->base; |
| 47 |
register_syscore(&ingenic_cgu_pm); |
| 48 |
} |
| 49 |
} |