blob: 1b61da6dc1a32b5ef38f5ff9136af6a593e9cd6a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Donghwa Lee09552712012-04-05 19:36:10 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * Donghwa Lee <dh09.lee@samsung.com>
Donghwa Lee09552712012-04-05 19:36:10 +00005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <mach/cpu.h>
Donghwa Lee09552712012-04-05 19:36:10 +00008#include <asm/io.h>
9#include <asm/arch/power.h>
10
11static void exynos4_mipi_phy_control(unsigned int dev_index,
12 unsigned int enable)
13{
14 struct exynos4_power *pmu =
15 (struct exynos4_power *)samsung_get_base_power();
16 unsigned int addr, cfg = 0;
17
18 if (dev_index == 0)
19 addr = (unsigned int)&pmu->mipi_phy0_control;
20 else
21 addr = (unsigned int)&pmu->mipi_phy1_control;
22
Donghwa Lee09552712012-04-05 19:36:10 +000023 cfg = readl(addr);
24 if (enable)
25 cfg |= (EXYNOS_MIPI_PHY_MRESETN | EXYNOS_MIPI_PHY_ENABLE);
26 else
27 cfg &= ~(EXYNOS_MIPI_PHY_MRESETN | EXYNOS_MIPI_PHY_ENABLE);
28
29 writel(cfg, addr);
30}
31
32void set_mipi_phy_ctrl(unsigned int dev_index, unsigned int enable)
33{
34 if (cpu_is_exynos4())
35 exynos4_mipi_phy_control(dev_index, enable);
36}
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +000037
38void exynos5_set_usbhost_phy_ctrl(unsigned int enable)
39{
40 struct exynos5_power *power =
41 (struct exynos5_power *)samsung_get_base_power();
42
43 if (enable) {
44 /* Enabling USBHOST_PHY */
45 setbits_le32(&power->usbhost_phy_control,
46 POWER_USB_HOST_PHY_CTRL_EN);
47 } else {
48 /* Disabling USBHOST_PHY */
49 clrbits_le32(&power->usbhost_phy_control,
50 POWER_USB_HOST_PHY_CTRL_EN);
51 }
52}
53
Suriyan Ramasami06ff9fb2014-10-29 09:22:42 -070054void exynos4412_set_usbhost_phy_ctrl(unsigned int enable)
55{
56 struct exynos4412_power *power =
57 (struct exynos4412_power *)samsung_get_base_power();
58
59 if (enable) {
60 /* Enabling USBHOST_PHY */
61 setbits_le32(&power->usbhost_phy_control,
62 POWER_USB_HOST_PHY_CTRL_EN);
63 setbits_le32(&power->hsic1_phy_control,
64 POWER_USB_HOST_PHY_CTRL_EN);
65 setbits_le32(&power->hsic2_phy_control,
66 POWER_USB_HOST_PHY_CTRL_EN);
67 } else {
68 /* Disabling USBHOST_PHY */
69 clrbits_le32(&power->usbhost_phy_control,
70 POWER_USB_HOST_PHY_CTRL_EN);
71 clrbits_le32(&power->hsic1_phy_control,
72 POWER_USB_HOST_PHY_CTRL_EN);
73 clrbits_le32(&power->hsic2_phy_control,
74 POWER_USB_HOST_PHY_CTRL_EN);
75 }
76}
77
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +000078void set_usbhost_phy_ctrl(unsigned int enable)
79{
80 if (cpu_is_exynos5())
81 exynos5_set_usbhost_phy_ctrl(enable);
Suriyan Ramasami06ff9fb2014-10-29 09:22:42 -070082 else if (cpu_is_exynos4())
83 if (proid_is_exynos4412())
84 exynos4412_set_usbhost_phy_ctrl(enable);
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +000085}
Donghwa Leea6b453f2012-07-02 01:15:56 +000086
Vivek Gautam4e16e2f2013-09-14 14:02:47 +053087static void exynos5_set_usbdrd_phy_ctrl(unsigned int enable)
88{
89 struct exynos5_power *power =
90 (struct exynos5_power *)samsung_get_base_power();
91
92 if (enable) {
93 /* Enabling USBDRD_PHY */
94 setbits_le32(&power->usbdrd_phy_control,
95 POWER_USB_DRD_PHY_CTRL_EN);
96 } else {
97 /* Disabling USBDRD_PHY */
98 clrbits_le32(&power->usbdrd_phy_control,
99 POWER_USB_DRD_PHY_CTRL_EN);
100 }
101}
102
Joonyoung Shim1c0dfce2015-01-21 13:51:32 +0900103static void exynos5420_set_usbdev_phy_ctrl(unsigned int enable)
104{
105 struct exynos5420_power *power =
106 (struct exynos5420_power *)samsung_get_base_power();
107
108 if (enable) {
109 /* Enabling USBDEV_PHY */
110 setbits_le32(&power->usbdev_phy_control,
111 POWER_USB_DRD_PHY_CTRL_EN);
112 setbits_le32(&power->usbdev1_phy_control,
113 POWER_USB_DRD_PHY_CTRL_EN);
114 } else {
115 /* Disabling USBDEV_PHY */
116 clrbits_le32(&power->usbdev_phy_control,
117 POWER_USB_DRD_PHY_CTRL_EN);
118 clrbits_le32(&power->usbdev1_phy_control,
119 POWER_USB_DRD_PHY_CTRL_EN);
120 }
121}
122
Vivek Gautam4e16e2f2013-09-14 14:02:47 +0530123void set_usbdrd_phy_ctrl(unsigned int enable)
124{
Joonyoung Shim1c0dfce2015-01-21 13:51:32 +0900125 if (cpu_is_exynos5()) {
Simon Glass8d451b42018-12-10 10:37:40 -0700126 if (proid_is_exynos542x())
Joonyoung Shim1c0dfce2015-01-21 13:51:32 +0900127 exynos5420_set_usbdev_phy_ctrl(enable);
128 else
129 exynos5_set_usbdrd_phy_ctrl(enable);
130 }
Vivek Gautam4e16e2f2013-09-14 14:02:47 +0530131}
132
Donghwa Leea6b453f2012-07-02 01:15:56 +0000133static void exynos5_dp_phy_control(unsigned int enable)
134{
135 unsigned int cfg;
136 struct exynos5_power *power =
137 (struct exynos5_power *)samsung_get_base_power();
138
139 cfg = readl(&power->dptx_phy_control);
140 if (enable)
141 cfg |= EXYNOS_DP_PHY_ENABLE;
142 else
143 cfg &= ~EXYNOS_DP_PHY_ENABLE;
144
145 writel(cfg, &power->dptx_phy_control);
146}
147
Simon Glassbfd239c2016-02-21 21:08:57 -0700148void exynos_dp_phy_ctrl(unsigned int enable)
Donghwa Leea6b453f2012-07-02 01:15:56 +0000149{
150 if (cpu_is_exynos5())
151 exynos5_dp_phy_control(enable);
152}
Rajeshwari Shinde6c4e99b2013-02-12 20:40:01 +0000153
154static void exynos5_set_ps_hold_ctrl(void)
155{
156 struct exynos5_power *power =
157 (struct exynos5_power *)samsung_get_base_power();
158
159 /* Set PS-Hold high */
160 setbits_le32(&power->ps_hold_control,
161 EXYNOS_PS_HOLD_CONTROL_DATA_HIGH);
162}
163
Doug Anderson6a39e7f2014-05-29 21:40:54 +0530164/*
165 * Set ps_hold data driving value high
166 * This enables the machine to stay powered on
167 * after the initial power-on condition goes away
168 * (e.g. power button).
169 */
Rajeshwari Shinde6c4e99b2013-02-12 20:40:01 +0000170void set_ps_hold_ctrl(void)
171{
172 if (cpu_is_exynos5())
173 exynos5_set_ps_hold_ctrl();
174}
Rajeshwari Shinde73de8d62013-02-14 19:46:11 +0000175
Rajeshwari Shinde73de8d62013-02-14 19:46:11 +0000176static void exynos5_set_xclkout(void)
177{
178 struct exynos5_power *power =
179 (struct exynos5_power *)samsung_get_base_power();
180
181 /* use xxti for xclk out */
182 clrsetbits_le32(&power->pmu_debug, PMU_DEBUG_CLKOUT_SEL_MASK,
183 PMU_DEBUG_XXTI);
184}
185
186void set_xclkout(void)
187{
188 if (cpu_is_exynos5())
189 exynos5_set_xclkout();
190}
Akshay Saraswatb9fa8c12013-02-25 01:13:06 +0000191
192/* Enables hardware tripping to power off the system when TMU fails */
193void set_hw_thermal_trip(void)
194{
195 if (cpu_is_exynos5()) {
196 struct exynos5_power *power =
197 (struct exynos5_power *)samsung_get_base_power();
198
199 /* PS_HOLD_CONTROL register ENABLE_HW_TRIP bit*/
200 setbits_le32(&power->ps_hold_control, POWER_ENABLE_HW_TRIP);
201 }
202}
Rajeshwari Shinde33dcbd22013-07-04 12:29:14 +0530203
204static uint32_t exynos5_get_reset_status(void)
205{
206 struct exynos5_power *power =
207 (struct exynos5_power *)samsung_get_base_power();
208
209 return power->inform1;
210}
211
212static uint32_t exynos4_get_reset_status(void)
213{
214 struct exynos4_power *power =
215 (struct exynos4_power *)samsung_get_base_power();
216
217 return power->inform1;
218}
219
220uint32_t get_reset_status(void)
221{
222 if (cpu_is_exynos5())
223 return exynos5_get_reset_status();
224 else
225 return exynos4_get_reset_status();
226}
227
228static void exynos5_power_exit_wakeup(void)
229{
230 struct exynos5_power *power =
231 (struct exynos5_power *)samsung_get_base_power();
232 typedef void (*resume_func)(void);
233
234 ((resume_func)power->inform0)();
235}
236
237static void exynos4_power_exit_wakeup(void)
238{
239 struct exynos4_power *power =
240 (struct exynos4_power *)samsung_get_base_power();
241 typedef void (*resume_func)(void);
242
243 ((resume_func)power->inform0)();
244}
245
246void power_exit_wakeup(void)
247{
248 if (cpu_is_exynos5())
249 exynos5_power_exit_wakeup();
250 else
251 exynos4_power_exit_wakeup();
252}
Przemyslaw Marczak93976f72014-09-01 13:50:44 +0200253
254unsigned int get_boot_mode(void)
255{
256 unsigned int om_pin = samsung_get_base_power();
257
258 return readl(om_pin) & OM_PIN_MASK;
259}