162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci//
362306a36Sopenharmony_ci// Copyright (c) 2011-2015 Samsung Electronics Co., Ltd.
462306a36Sopenharmony_ci//		http://www.samsung.com/
562306a36Sopenharmony_ci//
662306a36Sopenharmony_ci// Exynos3250 - CPU PMU (Power Management Unit) support
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/soc/samsung/exynos-regs-pmu.h>
962306a36Sopenharmony_ci#include <linux/soc/samsung/exynos-pmu.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "exynos-pmu.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistatic const struct exynos_pmu_conf exynos3250_pmu_config[] = {
1462306a36Sopenharmony_ci	/* { .offset = offset, .val = { AFTR, W-AFTR, SLEEP } */
1562306a36Sopenharmony_ci	{ EXYNOS3_ARM_CORE0_SYS_PWR_REG,		{ 0x0, 0x0, 0x2} },
1662306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ARM_CORE0_LOCAL_SYS_PWR_REG,	{ 0x0, 0x0, 0x0} },
1762306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ARM_CORE0_CENTRAL_SYS_PWR_REG, { 0x0, 0x0, 0x0} },
1862306a36Sopenharmony_ci	{ EXYNOS3_ARM_CORE1_SYS_PWR_REG,		{ 0x0, 0x0, 0x2} },
1962306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ARM_CORE1_LOCAL_SYS_PWR_REG,	{ 0x0, 0x0, 0x0} },
2062306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ARM_CORE1_CENTRAL_SYS_PWR_REG, { 0x0, 0x0, 0x0} },
2162306a36Sopenharmony_ci	{ EXYNOS3_ISP_ARM_SYS_PWR_REG,			{ 0x1, 0x0, 0x0} },
2262306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ISP_ARM_LOCAL_SYS_PWR_REG,	{ 0x0, 0x0, 0x0} },
2362306a36Sopenharmony_ci	{ EXYNOS3_DIS_IRQ_ISP_ARM_CENTRAL_SYS_PWR_REG,	{ 0x0, 0x0, 0x0} },
2462306a36Sopenharmony_ci	{ EXYNOS3_ARM_COMMON_SYS_PWR_REG,		{ 0x0, 0x0, 0x2} },
2562306a36Sopenharmony_ci	{ EXYNOS3_ARM_L2_SYS_PWR_REG,			{ 0x0, 0x0, 0x3} },
2662306a36Sopenharmony_ci	{ EXYNOS3_CMU_ACLKSTOP_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
2762306a36Sopenharmony_ci	{ EXYNOS3_CMU_SCLKSTOP_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
2862306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
2962306a36Sopenharmony_ci	{ EXYNOS3_DRAM_FREQ_DOWN_SYS_PWR_REG,		{ 0x1, 0x1, 0x1} },
3062306a36Sopenharmony_ci	{ EXYNOS3_DDRPHY_DLLOFF_SYS_PWR_REG,		{ 0x1, 0x1, 0x1} },
3162306a36Sopenharmony_ci	{ EXYNOS3_LPDDR_PHY_DLL_LOCK_SYS_PWR_REG,	{ 0x1, 0x1, 0x1} },
3262306a36Sopenharmony_ci	{ EXYNOS3_CMU_ACLKSTOP_COREBLK_SYS_PWR_REG,	{ 0x1, 0x0, 0x0} },
3362306a36Sopenharmony_ci	{ EXYNOS3_CMU_SCLKSTOP_COREBLK_SYS_PWR_REG,	{ 0x1, 0x0, 0x0} },
3462306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_COREBLK_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
3562306a36Sopenharmony_ci	{ EXYNOS3_APLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
3662306a36Sopenharmony_ci	{ EXYNOS3_MPLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
3762306a36Sopenharmony_ci	{ EXYNOS3_BPLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
3862306a36Sopenharmony_ci	{ EXYNOS3_VPLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
3962306a36Sopenharmony_ci	{ EXYNOS3_EPLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4062306a36Sopenharmony_ci	{ EXYNOS3_UPLL_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x1, 0x1} },
4162306a36Sopenharmony_ci	{ EXYNOS3_EPLLUSER_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4262306a36Sopenharmony_ci	{ EXYNOS3_MPLLUSER_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4362306a36Sopenharmony_ci	{ EXYNOS3_BPLLUSER_SYSCLK_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4462306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_CAM_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4562306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_MFC_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4662306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_G3D_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4762306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_LCD0_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4862306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_ISP_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
4962306a36Sopenharmony_ci	{ EXYNOS3_CMU_CLKSTOP_MAUDIO_SYS_PWR_REG,	{ 0x1, 0x0, 0x0} },
5062306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_CAM_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5162306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_MFC_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5262306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_G3D_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5362306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_LCD0_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5462306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_ISP_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5562306a36Sopenharmony_ci	{ EXYNOS3_CMU_RESET_MAUDIO_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
5662306a36Sopenharmony_ci	{ EXYNOS3_TOP_BUS_SYS_PWR_REG,			{ 0x3, 0x0, 0x0} },
5762306a36Sopenharmony_ci	{ EXYNOS3_TOP_RETENTION_SYS_PWR_REG,		{ 0x1, 0x1, 0x1} },
5862306a36Sopenharmony_ci	{ EXYNOS3_TOP_PWR_SYS_PWR_REG,			{ 0x3, 0x3, 0x3} },
5962306a36Sopenharmony_ci	{ EXYNOS3_TOP_BUS_COREBLK_SYS_PWR_REG,		{ 0x3, 0x0, 0x0} },
6062306a36Sopenharmony_ci	{ EXYNOS3_TOP_RETENTION_COREBLK_SYS_PWR_REG,	{ 0x1, 0x1, 0x1} },
6162306a36Sopenharmony_ci	{ EXYNOS3_TOP_PWR_COREBLK_SYS_PWR_REG,		{ 0x3, 0x3, 0x3} },
6262306a36Sopenharmony_ci	{ EXYNOS3_LOGIC_RESET_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
6362306a36Sopenharmony_ci	{ EXYNOS3_OSCCLK_GATE_SYS_PWR_REG,		{ 0x1, 0x1, 0x1} },
6462306a36Sopenharmony_ci	{ EXYNOS3_LOGIC_RESET_COREBLK_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
6562306a36Sopenharmony_ci	{ EXYNOS3_OSCCLK_GATE_COREBLK_SYS_PWR_REG,	{ 0x1, 0x0, 0x1} },
6662306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_DRAM_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
6762306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_MAUDIO_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
6862306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_GPIO_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
6962306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_UART_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7062306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_MMC0_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7162306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_MMC1_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7262306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_MMC2_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7362306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_SPI_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7462306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_EBIA_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7562306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_EBIB_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7662306a36Sopenharmony_ci	{ EXYNOS3_PAD_RETENTION_JTAG_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
7762306a36Sopenharmony_ci	{ EXYNOS3_PAD_ISOLATION_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
7862306a36Sopenharmony_ci	{ EXYNOS3_PAD_ALV_SEL_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
7962306a36Sopenharmony_ci	{ EXYNOS3_XUSBXTI_SYS_PWR_REG,			{ 0x1, 0x1, 0x0} },
8062306a36Sopenharmony_ci	{ EXYNOS3_XXTI_SYS_PWR_REG,			{ 0x1, 0x1, 0x0} },
8162306a36Sopenharmony_ci	{ EXYNOS3_EXT_REGULATOR_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
8262306a36Sopenharmony_ci	{ EXYNOS3_EXT_REGULATOR_COREBLK_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
8362306a36Sopenharmony_ci	{ EXYNOS3_GPIO_MODE_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
8462306a36Sopenharmony_ci	{ EXYNOS3_GPIO_MODE_MAUDIO_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
8562306a36Sopenharmony_ci	{ EXYNOS3_TOP_ASB_RESET_SYS_PWR_REG,		{ 0x1, 0x1, 0x0} },
8662306a36Sopenharmony_ci	{ EXYNOS3_TOP_ASB_ISOLATION_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
8762306a36Sopenharmony_ci	{ EXYNOS3_TOP_ASB_RESET_COREBLK_SYS_PWR_REG,	{ 0x1, 0x1, 0x0} },
8862306a36Sopenharmony_ci	{ EXYNOS3_TOP_ASB_ISOLATION_COREBLK_SYS_PWR_REG, { 0x1, 0x1, 0x0} },
8962306a36Sopenharmony_ci	{ EXYNOS3_CAM_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9062306a36Sopenharmony_ci	{ EXYNOS3_MFC_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9162306a36Sopenharmony_ci	{ EXYNOS3_G3D_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9262306a36Sopenharmony_ci	{ EXYNOS3_LCD0_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9362306a36Sopenharmony_ci	{ EXYNOS3_ISP_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9462306a36Sopenharmony_ci	{ EXYNOS3_MAUDIO_SYS_PWR_REG,			{ 0x7, 0x0, 0x0} },
9562306a36Sopenharmony_ci	{ EXYNOS3_CMU_SYSCLK_ISP_SYS_PWR_REG,		{ 0x1, 0x0, 0x0} },
9662306a36Sopenharmony_ci	{ PMU_TABLE_END,},
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_cistatic unsigned int const exynos3250_list_feed[] = {
10062306a36Sopenharmony_ci	EXYNOS3_ARM_CORE_OPTION(0),
10162306a36Sopenharmony_ci	EXYNOS3_ARM_CORE_OPTION(1),
10262306a36Sopenharmony_ci	EXYNOS3_ARM_CORE_OPTION(2),
10362306a36Sopenharmony_ci	EXYNOS3_ARM_CORE_OPTION(3),
10462306a36Sopenharmony_ci	EXYNOS3_ARM_COMMON_OPTION,
10562306a36Sopenharmony_ci	EXYNOS3_TOP_PWR_OPTION,
10662306a36Sopenharmony_ci	EXYNOS3_CORE_TOP_PWR_OPTION,
10762306a36Sopenharmony_ci	S5P_CAM_OPTION,
10862306a36Sopenharmony_ci	S5P_MFC_OPTION,
10962306a36Sopenharmony_ci	S5P_G3D_OPTION,
11062306a36Sopenharmony_ci	S5P_LCD0_OPTION,
11162306a36Sopenharmony_ci	S5P_ISP_OPTION,
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistatic void exynos3250_powerdown_conf_extra(enum sys_powerdown mode)
11562306a36Sopenharmony_ci{
11662306a36Sopenharmony_ci	unsigned int i;
11762306a36Sopenharmony_ci	unsigned int tmp;
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	/* Enable only SC_FEEDBACK */
12062306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(exynos3250_list_feed); i++) {
12162306a36Sopenharmony_ci		tmp = pmu_raw_readl(exynos3250_list_feed[i]);
12262306a36Sopenharmony_ci		tmp &= ~(EXYNOS3_OPTION_USE_SC_COUNTER);
12362306a36Sopenharmony_ci		tmp |= EXYNOS3_OPTION_USE_SC_FEEDBACK;
12462306a36Sopenharmony_ci		pmu_raw_writel(tmp, exynos3250_list_feed[i]);
12562306a36Sopenharmony_ci	}
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	if (mode != SYS_SLEEP)
12862306a36Sopenharmony_ci		return;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	pmu_raw_writel(XUSBXTI_DURATION, EXYNOS3_XUSBXTI_DURATION);
13162306a36Sopenharmony_ci	pmu_raw_writel(XXTI_DURATION, EXYNOS3_XXTI_DURATION);
13262306a36Sopenharmony_ci	pmu_raw_writel(EXT_REGULATOR_DURATION, EXYNOS3_EXT_REGULATOR_DURATION);
13362306a36Sopenharmony_ci	pmu_raw_writel(EXT_REGULATOR_COREBLK_DURATION,
13462306a36Sopenharmony_ci		       EXYNOS3_EXT_REGULATOR_COREBLK_DURATION);
13562306a36Sopenharmony_ci}
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistatic void exynos3250_pmu_init(void)
13862306a36Sopenharmony_ci{
13962306a36Sopenharmony_ci	unsigned int value;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	/*
14262306a36Sopenharmony_ci	 * To prevent from issuing new bus request form L2 memory system
14362306a36Sopenharmony_ci	 * If core status is power down, should be set '1' to L2 power down
14462306a36Sopenharmony_ci	 */
14562306a36Sopenharmony_ci	value = pmu_raw_readl(EXYNOS3_ARM_COMMON_OPTION);
14662306a36Sopenharmony_ci	value |= EXYNOS3_OPTION_SKIP_DEACTIVATE_ACEACP_IN_PWDN;
14762306a36Sopenharmony_ci	pmu_raw_writel(value, EXYNOS3_ARM_COMMON_OPTION);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci	/* Enable USE_STANDBY_WFI for all CORE */
15062306a36Sopenharmony_ci	pmu_raw_writel(S5P_USE_STANDBY_WFI_ALL, S5P_CENTRAL_SEQ_OPTION);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/*
15362306a36Sopenharmony_ci	 * Set PSHOLD port for output high
15462306a36Sopenharmony_ci	 */
15562306a36Sopenharmony_ci	value = pmu_raw_readl(S5P_PS_HOLD_CONTROL);
15662306a36Sopenharmony_ci	value |= S5P_PS_HOLD_OUTPUT_HIGH;
15762306a36Sopenharmony_ci	pmu_raw_writel(value, S5P_PS_HOLD_CONTROL);
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	/*
16062306a36Sopenharmony_ci	 * Enable signal for PSHOLD port
16162306a36Sopenharmony_ci	 */
16262306a36Sopenharmony_ci	value = pmu_raw_readl(S5P_PS_HOLD_CONTROL);
16362306a36Sopenharmony_ci	value |= S5P_PS_HOLD_EN;
16462306a36Sopenharmony_ci	pmu_raw_writel(value, S5P_PS_HOLD_CONTROL);
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ciconst struct exynos_pmu_data exynos3250_pmu_data = {
16862306a36Sopenharmony_ci	.pmu_config	= exynos3250_pmu_config,
16962306a36Sopenharmony_ci	.pmu_init	= exynos3250_pmu_init,
17062306a36Sopenharmony_ci	.powerdown_conf_extra	= exynos3250_powerdown_conf_extra,
17162306a36Sopenharmony_ci};
172