xref: /rk3399_rockchip-uboot/arch/arm/mach-exynos/power.c (revision dc557e9a1fe00ca9d884bd88feef5bebf23fede4)
177b55e8cSThomas Abraham /*
277b55e8cSThomas Abraham  * Copyright (C) 2012 Samsung Electronics
377b55e8cSThomas Abraham  * Donghwa Lee <dh09.lee@samsung.com>
477b55e8cSThomas Abraham  *
577b55e8cSThomas Abraham  * SPDX-License-Identifier:	GPL-2.0+
677b55e8cSThomas Abraham  */
777b55e8cSThomas Abraham 
877b55e8cSThomas Abraham #include <common.h>
977b55e8cSThomas Abraham #include <asm/io.h>
1077b55e8cSThomas Abraham #include <asm/arch/power.h>
1177b55e8cSThomas Abraham 
exynos4_mipi_phy_control(unsigned int dev_index,unsigned int enable)1277b55e8cSThomas Abraham static void exynos4_mipi_phy_control(unsigned int dev_index,
1377b55e8cSThomas Abraham 					unsigned int enable)
1477b55e8cSThomas Abraham {
1577b55e8cSThomas Abraham 	struct exynos4_power *pmu =
1677b55e8cSThomas Abraham 	    (struct exynos4_power *)samsung_get_base_power();
1777b55e8cSThomas Abraham 	unsigned int addr, cfg = 0;
1877b55e8cSThomas Abraham 
1977b55e8cSThomas Abraham 	if (dev_index == 0)
2077b55e8cSThomas Abraham 		addr = (unsigned int)&pmu->mipi_phy0_control;
2177b55e8cSThomas Abraham 	else
2277b55e8cSThomas Abraham 		addr = (unsigned int)&pmu->mipi_phy1_control;
2377b55e8cSThomas Abraham 
2477b55e8cSThomas Abraham 
2577b55e8cSThomas Abraham 	cfg = readl(addr);
2677b55e8cSThomas Abraham 	if (enable)
2777b55e8cSThomas Abraham 		cfg |= (EXYNOS_MIPI_PHY_MRESETN | EXYNOS_MIPI_PHY_ENABLE);
2877b55e8cSThomas Abraham 	else
2977b55e8cSThomas Abraham 		cfg &= ~(EXYNOS_MIPI_PHY_MRESETN | EXYNOS_MIPI_PHY_ENABLE);
3077b55e8cSThomas Abraham 
3177b55e8cSThomas Abraham 	writel(cfg, addr);
3277b55e8cSThomas Abraham }
3377b55e8cSThomas Abraham 
set_mipi_phy_ctrl(unsigned int dev_index,unsigned int enable)3477b55e8cSThomas Abraham void set_mipi_phy_ctrl(unsigned int dev_index, unsigned int enable)
3577b55e8cSThomas Abraham {
3677b55e8cSThomas Abraham 	if (cpu_is_exynos4())
3777b55e8cSThomas Abraham 		exynos4_mipi_phy_control(dev_index, enable);
3877b55e8cSThomas Abraham }
3977b55e8cSThomas Abraham 
exynos5_set_usbhost_phy_ctrl(unsigned int enable)4077b55e8cSThomas Abraham void exynos5_set_usbhost_phy_ctrl(unsigned int enable)
4177b55e8cSThomas Abraham {
4277b55e8cSThomas Abraham 	struct exynos5_power *power =
4377b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
4477b55e8cSThomas Abraham 
4577b55e8cSThomas Abraham 	if (enable) {
4677b55e8cSThomas Abraham 		/* Enabling USBHOST_PHY */
4777b55e8cSThomas Abraham 		setbits_le32(&power->usbhost_phy_control,
4877b55e8cSThomas Abraham 				POWER_USB_HOST_PHY_CTRL_EN);
4977b55e8cSThomas Abraham 	} else {
5077b55e8cSThomas Abraham 		/* Disabling USBHOST_PHY */
5177b55e8cSThomas Abraham 		clrbits_le32(&power->usbhost_phy_control,
5277b55e8cSThomas Abraham 				POWER_USB_HOST_PHY_CTRL_EN);
5377b55e8cSThomas Abraham 	}
5477b55e8cSThomas Abraham }
5577b55e8cSThomas Abraham 
exynos4412_set_usbhost_phy_ctrl(unsigned int enable)5677b55e8cSThomas Abraham void exynos4412_set_usbhost_phy_ctrl(unsigned int enable)
5777b55e8cSThomas Abraham {
5877b55e8cSThomas Abraham 	struct exynos4412_power *power =
5977b55e8cSThomas Abraham 		(struct exynos4412_power *)samsung_get_base_power();
6077b55e8cSThomas Abraham 
6177b55e8cSThomas Abraham 	if (enable) {
6277b55e8cSThomas Abraham 		/* Enabling USBHOST_PHY */
6377b55e8cSThomas Abraham 		setbits_le32(&power->usbhost_phy_control,
6477b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
6577b55e8cSThomas Abraham 		setbits_le32(&power->hsic1_phy_control,
6677b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
6777b55e8cSThomas Abraham 		setbits_le32(&power->hsic2_phy_control,
6877b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
6977b55e8cSThomas Abraham 	} else {
7077b55e8cSThomas Abraham 		/* Disabling USBHOST_PHY */
7177b55e8cSThomas Abraham 		clrbits_le32(&power->usbhost_phy_control,
7277b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
7377b55e8cSThomas Abraham 		clrbits_le32(&power->hsic1_phy_control,
7477b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
7577b55e8cSThomas Abraham 		clrbits_le32(&power->hsic2_phy_control,
7677b55e8cSThomas Abraham 			     POWER_USB_HOST_PHY_CTRL_EN);
7777b55e8cSThomas Abraham 	}
7877b55e8cSThomas Abraham }
7977b55e8cSThomas Abraham 
set_usbhost_phy_ctrl(unsigned int enable)8077b55e8cSThomas Abraham void set_usbhost_phy_ctrl(unsigned int enable)
8177b55e8cSThomas Abraham {
8277b55e8cSThomas Abraham 	if (cpu_is_exynos5())
8377b55e8cSThomas Abraham 		exynos5_set_usbhost_phy_ctrl(enable);
8477b55e8cSThomas Abraham 	else if (cpu_is_exynos4())
8577b55e8cSThomas Abraham 		if (proid_is_exynos4412())
8677b55e8cSThomas Abraham 			exynos4412_set_usbhost_phy_ctrl(enable);
8777b55e8cSThomas Abraham }
8877b55e8cSThomas Abraham 
exynos5_set_usbdrd_phy_ctrl(unsigned int enable)8977b55e8cSThomas Abraham static void exynos5_set_usbdrd_phy_ctrl(unsigned int enable)
9077b55e8cSThomas Abraham {
9177b55e8cSThomas Abraham 	struct exynos5_power *power =
9277b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
9377b55e8cSThomas Abraham 
9477b55e8cSThomas Abraham 	if (enable) {
9577b55e8cSThomas Abraham 		/* Enabling USBDRD_PHY */
9677b55e8cSThomas Abraham 		setbits_le32(&power->usbdrd_phy_control,
9777b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
9877b55e8cSThomas Abraham 	} else {
9977b55e8cSThomas Abraham 		/* Disabling USBDRD_PHY */
10077b55e8cSThomas Abraham 		clrbits_le32(&power->usbdrd_phy_control,
10177b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
10277b55e8cSThomas Abraham 	}
10377b55e8cSThomas Abraham }
10477b55e8cSThomas Abraham 
exynos5420_set_usbdev_phy_ctrl(unsigned int enable)10577b55e8cSThomas Abraham static void exynos5420_set_usbdev_phy_ctrl(unsigned int enable)
10677b55e8cSThomas Abraham {
10777b55e8cSThomas Abraham 	struct exynos5420_power *power =
10877b55e8cSThomas Abraham 		(struct exynos5420_power *)samsung_get_base_power();
10977b55e8cSThomas Abraham 
11077b55e8cSThomas Abraham 	if (enable) {
11177b55e8cSThomas Abraham 		/* Enabling USBDEV_PHY */
11277b55e8cSThomas Abraham 		setbits_le32(&power->usbdev_phy_control,
11377b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
11477b55e8cSThomas Abraham 		setbits_le32(&power->usbdev1_phy_control,
11577b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
11677b55e8cSThomas Abraham 	} else {
11777b55e8cSThomas Abraham 		/* Disabling USBDEV_PHY */
11877b55e8cSThomas Abraham 		clrbits_le32(&power->usbdev_phy_control,
11977b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
12077b55e8cSThomas Abraham 		clrbits_le32(&power->usbdev1_phy_control,
12177b55e8cSThomas Abraham 				POWER_USB_DRD_PHY_CTRL_EN);
12277b55e8cSThomas Abraham 	}
12377b55e8cSThomas Abraham }
12477b55e8cSThomas Abraham 
set_usbdrd_phy_ctrl(unsigned int enable)12577b55e8cSThomas Abraham void set_usbdrd_phy_ctrl(unsigned int enable)
12677b55e8cSThomas Abraham {
12777b55e8cSThomas Abraham 	if (cpu_is_exynos5()) {
128d64c8adeSPrzemyslaw Marczak 		if (proid_is_exynos5420() || proid_is_exynos5422())
12977b55e8cSThomas Abraham 			exynos5420_set_usbdev_phy_ctrl(enable);
13077b55e8cSThomas Abraham 		else
13177b55e8cSThomas Abraham 			exynos5_set_usbdrd_phy_ctrl(enable);
13277b55e8cSThomas Abraham 	}
13377b55e8cSThomas Abraham }
13477b55e8cSThomas Abraham 
exynos5_dp_phy_control(unsigned int enable)13577b55e8cSThomas Abraham static void exynos5_dp_phy_control(unsigned int enable)
13677b55e8cSThomas Abraham {
13777b55e8cSThomas Abraham 	unsigned int cfg;
13877b55e8cSThomas Abraham 	struct exynos5_power *power =
13977b55e8cSThomas Abraham 	    (struct exynos5_power *)samsung_get_base_power();
14077b55e8cSThomas Abraham 
14177b55e8cSThomas Abraham 	cfg = readl(&power->dptx_phy_control);
14277b55e8cSThomas Abraham 	if (enable)
14377b55e8cSThomas Abraham 		cfg |= EXYNOS_DP_PHY_ENABLE;
14477b55e8cSThomas Abraham 	else
14577b55e8cSThomas Abraham 		cfg &= ~EXYNOS_DP_PHY_ENABLE;
14677b55e8cSThomas Abraham 
14777b55e8cSThomas Abraham 	writel(cfg, &power->dptx_phy_control);
14877b55e8cSThomas Abraham }
14977b55e8cSThomas Abraham 
exynos_dp_phy_ctrl(unsigned int enable)150*7eb860dfSSimon Glass void exynos_dp_phy_ctrl(unsigned int enable)
15177b55e8cSThomas Abraham {
15277b55e8cSThomas Abraham 	if (cpu_is_exynos5())
15377b55e8cSThomas Abraham 		exynos5_dp_phy_control(enable);
15477b55e8cSThomas Abraham }
15577b55e8cSThomas Abraham 
exynos5_set_ps_hold_ctrl(void)15677b55e8cSThomas Abraham static void exynos5_set_ps_hold_ctrl(void)
15777b55e8cSThomas Abraham {
15877b55e8cSThomas Abraham 	struct exynos5_power *power =
15977b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
16077b55e8cSThomas Abraham 
16177b55e8cSThomas Abraham 	/* Set PS-Hold high */
16277b55e8cSThomas Abraham 	setbits_le32(&power->ps_hold_control,
16377b55e8cSThomas Abraham 			EXYNOS_PS_HOLD_CONTROL_DATA_HIGH);
16477b55e8cSThomas Abraham }
16577b55e8cSThomas Abraham 
16677b55e8cSThomas Abraham /*
16777b55e8cSThomas Abraham  * Set ps_hold data driving value high
16877b55e8cSThomas Abraham  * This enables the machine to stay powered on
16977b55e8cSThomas Abraham  * after the initial power-on condition goes away
17077b55e8cSThomas Abraham  * (e.g. power button).
17177b55e8cSThomas Abraham  */
set_ps_hold_ctrl(void)17277b55e8cSThomas Abraham void set_ps_hold_ctrl(void)
17377b55e8cSThomas Abraham {
17477b55e8cSThomas Abraham 	if (cpu_is_exynos5())
17577b55e8cSThomas Abraham 		exynos5_set_ps_hold_ctrl();
17677b55e8cSThomas Abraham }
17777b55e8cSThomas Abraham 
17877b55e8cSThomas Abraham 
exynos5_set_xclkout(void)17977b55e8cSThomas Abraham static void exynos5_set_xclkout(void)
18077b55e8cSThomas Abraham {
18177b55e8cSThomas Abraham 	struct exynos5_power *power =
18277b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
18377b55e8cSThomas Abraham 
18477b55e8cSThomas Abraham 	/* use xxti for xclk out */
18577b55e8cSThomas Abraham 	clrsetbits_le32(&power->pmu_debug, PMU_DEBUG_CLKOUT_SEL_MASK,
18677b55e8cSThomas Abraham 				PMU_DEBUG_XXTI);
18777b55e8cSThomas Abraham }
18877b55e8cSThomas Abraham 
set_xclkout(void)18977b55e8cSThomas Abraham void set_xclkout(void)
19077b55e8cSThomas Abraham {
19177b55e8cSThomas Abraham 	if (cpu_is_exynos5())
19277b55e8cSThomas Abraham 		exynos5_set_xclkout();
19377b55e8cSThomas Abraham }
19477b55e8cSThomas Abraham 
19577b55e8cSThomas Abraham /* Enables hardware tripping to power off the system when TMU fails */
set_hw_thermal_trip(void)19677b55e8cSThomas Abraham void set_hw_thermal_trip(void)
19777b55e8cSThomas Abraham {
19877b55e8cSThomas Abraham 	if (cpu_is_exynos5()) {
19977b55e8cSThomas Abraham 		struct exynos5_power *power =
20077b55e8cSThomas Abraham 			(struct exynos5_power *)samsung_get_base_power();
20177b55e8cSThomas Abraham 
20277b55e8cSThomas Abraham 		/* PS_HOLD_CONTROL register ENABLE_HW_TRIP bit*/
20377b55e8cSThomas Abraham 		setbits_le32(&power->ps_hold_control, POWER_ENABLE_HW_TRIP);
20477b55e8cSThomas Abraham 	}
20577b55e8cSThomas Abraham }
20677b55e8cSThomas Abraham 
exynos5_get_reset_status(void)20777b55e8cSThomas Abraham static uint32_t exynos5_get_reset_status(void)
20877b55e8cSThomas Abraham {
20977b55e8cSThomas Abraham 	struct exynos5_power *power =
21077b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
21177b55e8cSThomas Abraham 
21277b55e8cSThomas Abraham 	return power->inform1;
21377b55e8cSThomas Abraham }
21477b55e8cSThomas Abraham 
exynos4_get_reset_status(void)21577b55e8cSThomas Abraham static uint32_t exynos4_get_reset_status(void)
21677b55e8cSThomas Abraham {
21777b55e8cSThomas Abraham 	struct exynos4_power *power =
21877b55e8cSThomas Abraham 		(struct exynos4_power *)samsung_get_base_power();
21977b55e8cSThomas Abraham 
22077b55e8cSThomas Abraham 	return power->inform1;
22177b55e8cSThomas Abraham }
22277b55e8cSThomas Abraham 
get_reset_status(void)22377b55e8cSThomas Abraham uint32_t get_reset_status(void)
22477b55e8cSThomas Abraham {
22577b55e8cSThomas Abraham 	if (cpu_is_exynos5())
22677b55e8cSThomas Abraham 		return exynos5_get_reset_status();
22777b55e8cSThomas Abraham 	else
22877b55e8cSThomas Abraham 		return  exynos4_get_reset_status();
22977b55e8cSThomas Abraham }
23077b55e8cSThomas Abraham 
exynos5_power_exit_wakeup(void)23177b55e8cSThomas Abraham static void exynos5_power_exit_wakeup(void)
23277b55e8cSThomas Abraham {
23377b55e8cSThomas Abraham 	struct exynos5_power *power =
23477b55e8cSThomas Abraham 		(struct exynos5_power *)samsung_get_base_power();
23577b55e8cSThomas Abraham 	typedef void (*resume_func)(void);
23677b55e8cSThomas Abraham 
23777b55e8cSThomas Abraham 	((resume_func)power->inform0)();
23877b55e8cSThomas Abraham }
23977b55e8cSThomas Abraham 
exynos4_power_exit_wakeup(void)24077b55e8cSThomas Abraham static void exynos4_power_exit_wakeup(void)
24177b55e8cSThomas Abraham {
24277b55e8cSThomas Abraham 	struct exynos4_power *power =
24377b55e8cSThomas Abraham 		(struct exynos4_power *)samsung_get_base_power();
24477b55e8cSThomas Abraham 	typedef void (*resume_func)(void);
24577b55e8cSThomas Abraham 
24677b55e8cSThomas Abraham 	((resume_func)power->inform0)();
24777b55e8cSThomas Abraham }
24877b55e8cSThomas Abraham 
power_exit_wakeup(void)24977b55e8cSThomas Abraham void power_exit_wakeup(void)
25077b55e8cSThomas Abraham {
25177b55e8cSThomas Abraham 	if (cpu_is_exynos5())
25277b55e8cSThomas Abraham 		exynos5_power_exit_wakeup();
25377b55e8cSThomas Abraham 	else
25477b55e8cSThomas Abraham 		exynos4_power_exit_wakeup();
25577b55e8cSThomas Abraham }
25677b55e8cSThomas Abraham 
get_boot_mode(void)25777b55e8cSThomas Abraham unsigned int get_boot_mode(void)
25877b55e8cSThomas Abraham {
25977b55e8cSThomas Abraham 	unsigned int om_pin = samsung_get_base_power();
26077b55e8cSThomas Abraham 
26177b55e8cSThomas Abraham 	return readl(om_pin) & OM_PIN_MASK;
26277b55e8cSThomas Abraham }
263