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