1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (c) 2010 Google, Inc
4 * Copyright (c) 2014 NVIDIA Corporation
5 *
6 * Author:
7 * Colin Cross <ccross@google.com>
8 */
9
10 #ifndef __SOC_TEGRA_PMC_H__
11 #define __SOC_TEGRA_PMC_H__
12
13 #include <linux/reboot.h>
14
15 #include <soc/tegra/pm.h>
16
17 struct clk;
18 struct reset_control;
19 struct tegra_pmc;
20
21 bool tegra_pmc_cpu_is_powered(unsigned int cpuid);
22 int tegra_pmc_cpu_power_on(unsigned int cpuid);
23 int tegra_pmc_cpu_remove_clamping(unsigned int cpuid);
24
25 /*
26 * powergate and I/O rail APIs
27 */
28
29 #define TEGRA_POWERGATE_CPU 0
30 #define TEGRA_POWERGATE_3D 1
31 #define TEGRA_POWERGATE_VENC 2
32 #define TEGRA_POWERGATE_PCIE 3
33 #define TEGRA_POWERGATE_VDEC 4
34 #define TEGRA_POWERGATE_L2 5
35 #define TEGRA_POWERGATE_MPE 6
36 #define TEGRA_POWERGATE_HEG 7
37 #define TEGRA_POWERGATE_SATA 8
38 #define TEGRA_POWERGATE_CPU1 9
39 #define TEGRA_POWERGATE_CPU2 10
40 #define TEGRA_POWERGATE_CPU3 11
41 #define TEGRA_POWERGATE_CELP 12
42 #define TEGRA_POWERGATE_3D1 13
43 #define TEGRA_POWERGATE_CPU0 14
44 #define TEGRA_POWERGATE_C0NC 15
45 #define TEGRA_POWERGATE_C1NC 16
46 #define TEGRA_POWERGATE_SOR 17
47 #define TEGRA_POWERGATE_DIS 18
48 #define TEGRA_POWERGATE_DISB 19
49 #define TEGRA_POWERGATE_XUSBA 20
50 #define TEGRA_POWERGATE_XUSBB 21
51 #define TEGRA_POWERGATE_XUSBC 22
52 #define TEGRA_POWERGATE_VIC 23
53 #define TEGRA_POWERGATE_IRAM 24
54 #define TEGRA_POWERGATE_NVDEC 25
55 #define TEGRA_POWERGATE_NVJPG 26
56 #define TEGRA_POWERGATE_AUD 27
57 #define TEGRA_POWERGATE_DFD 28
58 #define TEGRA_POWERGATE_VE2 29
59 #define TEGRA_POWERGATE_MAX TEGRA_POWERGATE_VE2
60
61 #define TEGRA_POWERGATE_3D0 TEGRA_POWERGATE_3D
62
63 /**
64 * enum tegra_io_pad - I/O pad group identifier
65 *
66 * I/O pins on Tegra SoCs are grouped into so-called I/O pads. Each such pad
67 * can be used to control the common voltage signal level and power state of
68 * the pins of the given pad.
69 */
70 enum tegra_io_pad {
71 TEGRA_IO_PAD_AUDIO,
72 TEGRA_IO_PAD_AUDIO_HV,
73 TEGRA_IO_PAD_BB,
74 TEGRA_IO_PAD_CAM,
75 TEGRA_IO_PAD_COMP,
76 TEGRA_IO_PAD_CONN,
77 TEGRA_IO_PAD_CSIA,
78 TEGRA_IO_PAD_CSIB,
79 TEGRA_IO_PAD_CSIC,
80 TEGRA_IO_PAD_CSID,
81 TEGRA_IO_PAD_CSIE,
82 TEGRA_IO_PAD_CSIF,
83 TEGRA_IO_PAD_CSIG,
84 TEGRA_IO_PAD_CSIH,
85 TEGRA_IO_PAD_DAP3,
86 TEGRA_IO_PAD_DAP5,
87 TEGRA_IO_PAD_DBG,
88 TEGRA_IO_PAD_DEBUG_NONAO,
89 TEGRA_IO_PAD_DMIC,
90 TEGRA_IO_PAD_DMIC_HV,
91 TEGRA_IO_PAD_DP,
92 TEGRA_IO_PAD_DSI,
93 TEGRA_IO_PAD_DSIB,
94 TEGRA_IO_PAD_DSIC,
95 TEGRA_IO_PAD_DSID,
96 TEGRA_IO_PAD_EDP,
97 TEGRA_IO_PAD_EMMC,
98 TEGRA_IO_PAD_EMMC2,
99 TEGRA_IO_PAD_EQOS,
100 TEGRA_IO_PAD_GPIO,
101 TEGRA_IO_PAD_GP_PWM2,
102 TEGRA_IO_PAD_GP_PWM3,
103 TEGRA_IO_PAD_HDMI,
104 TEGRA_IO_PAD_HDMI_DP0,
105 TEGRA_IO_PAD_HDMI_DP1,
106 TEGRA_IO_PAD_HDMI_DP2,
107 TEGRA_IO_PAD_HDMI_DP3,
108 TEGRA_IO_PAD_HSIC,
109 TEGRA_IO_PAD_HV,
110 TEGRA_IO_PAD_LVDS,
111 TEGRA_IO_PAD_MIPI_BIAS,
112 TEGRA_IO_PAD_NAND,
113 TEGRA_IO_PAD_PEX_BIAS,
114 TEGRA_IO_PAD_PEX_CLK_BIAS,
115 TEGRA_IO_PAD_PEX_CLK1,
116 TEGRA_IO_PAD_PEX_CLK2,
117 TEGRA_IO_PAD_PEX_CLK3,
118 TEGRA_IO_PAD_PEX_CLK_2_BIAS,
119 TEGRA_IO_PAD_PEX_CLK_2,
120 TEGRA_IO_PAD_PEX_CNTRL,
121 TEGRA_IO_PAD_PEX_CTL2,
122 TEGRA_IO_PAD_PEX_L0_RST,
123 TEGRA_IO_PAD_PEX_L1_RST,
124 TEGRA_IO_PAD_PEX_L5_RST,
125 TEGRA_IO_PAD_PWR_CTL,
126 TEGRA_IO_PAD_SDMMC1,
127 TEGRA_IO_PAD_SDMMC1_HV,
128 TEGRA_IO_PAD_SDMMC2,
129 TEGRA_IO_PAD_SDMMC2_HV,
130 TEGRA_IO_PAD_SDMMC3,
131 TEGRA_IO_PAD_SDMMC3_HV,
132 TEGRA_IO_PAD_SDMMC4,
133 TEGRA_IO_PAD_SOC_GPIO10,
134 TEGRA_IO_PAD_SOC_GPIO12,
135 TEGRA_IO_PAD_SOC_GPIO13,
136 TEGRA_IO_PAD_SOC_GPIO53,
137 TEGRA_IO_PAD_SPI,
138 TEGRA_IO_PAD_SPI_HV,
139 TEGRA_IO_PAD_SYS_DDC,
140 TEGRA_IO_PAD_UART,
141 TEGRA_IO_PAD_UART4,
142 TEGRA_IO_PAD_UART5,
143 TEGRA_IO_PAD_UFS,
144 TEGRA_IO_PAD_USB0,
145 TEGRA_IO_PAD_USB1,
146 TEGRA_IO_PAD_USB2,
147 TEGRA_IO_PAD_USB3,
148 TEGRA_IO_PAD_USB_BIAS,
149 TEGRA_IO_PAD_AO_HV,
150 };
151
152 #ifdef CONFIG_SOC_TEGRA_PMC
153 struct tegra_pmc *devm_tegra_pmc_get(struct device *dev);
154
155 int tegra_pmc_powergate_power_on(struct tegra_pmc *pmc, unsigned int id);
156 int tegra_pmc_powergate_power_off(struct tegra_pmc *pmc, unsigned int id);
157 int tegra_pmc_powergate_remove_clamping(struct tegra_pmc *pmc, unsigned int id);
158
159 /* Must be called with clk disabled, and returns with clk enabled */
160 int tegra_pmc_powergate_sequence_power_up(struct tegra_pmc *pmc,
161 unsigned int id, struct clk *clk,
162 struct reset_control *rst);
163 int tegra_pmc_io_pad_power_enable(struct tegra_pmc *pmc, enum tegra_io_pad id);
164 int tegra_pmc_io_pad_power_disable(struct tegra_pmc *pmc, enum tegra_io_pad id);
165
166 /* legacy */
167 int tegra_powergate_power_on(unsigned int id);
168 int tegra_powergate_power_off(unsigned int id);
169 int tegra_powergate_remove_clamping(unsigned int id);
170
171 int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
172 struct reset_control *rst);
173
174 int tegra_io_pad_power_enable(enum tegra_io_pad id);
175 int tegra_io_pad_power_disable(enum tegra_io_pad id);
176
177 void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode);
178 void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode);
179
180 bool tegra_pmc_core_domain_state_synced(void);
181
182 #else
devm_tegra_pmc_get(struct device * dev)183 static inline struct tegra_pmc *devm_tegra_pmc_get(struct device *dev)
184 {
185 return ERR_PTR(-ENOSYS);
186 }
187
188 static inline int
tegra_pmc_powergate_power_on(struct tegra_pmc * pmc,unsigned int id)189 tegra_pmc_powergate_power_on(struct tegra_pmc *pmc, unsigned int id)
190 {
191 return -ENOSYS;
192 }
193
194 static inline int
tegra_pmc_powergate_power_off(struct tegra_pmc * pmc,unsigned int id)195 tegra_pmc_powergate_power_off(struct tegra_pmc *pmc, unsigned int id)
196 {
197 return -ENOSYS;
198 }
199
200 static inline int
tegra_pmc_powergate_remove_clamping(struct tegra_pmc * pmc,unsigned int id)201 tegra_pmc_powergate_remove_clamping(struct tegra_pmc *pmc, unsigned int id)
202 {
203 return -ENOSYS;
204 }
205
206 /* Must be called with clk disabled, and returns with clk enabled */
207 static inline int
tegra_pmc_powergate_sequence_power_up(struct tegra_pmc * pmc,unsigned int id,struct clk * clk,struct reset_control * rst)208 tegra_pmc_powergate_sequence_power_up(struct tegra_pmc *pmc, unsigned int id,
209 struct clk *clk,
210 struct reset_control *rst)
211 {
212 return -ENOSYS;
213 }
214
215 static inline int
tegra_pmc_io_pad_power_enable(struct tegra_pmc * pmc,enum tegra_io_pad id)216 tegra_pmc_io_pad_power_enable(struct tegra_pmc *pmc, enum tegra_io_pad id)
217 {
218 return -ENOSYS;
219 }
220
221 static inline int
tegra_pmc_io_pad_power_disable(struct tegra_pmc * pmc,enum tegra_io_pad id)222 tegra_pmc_io_pad_power_disable(struct tegra_pmc *pmc, enum tegra_io_pad id)
223 {
224 return -ENOSYS;
225 }
226
tegra_powergate_power_on(unsigned int id)227 static inline int tegra_powergate_power_on(unsigned int id)
228 {
229 return -ENOSYS;
230 }
231
tegra_powergate_power_off(unsigned int id)232 static inline int tegra_powergate_power_off(unsigned int id)
233 {
234 return -ENOSYS;
235 }
236
tegra_powergate_remove_clamping(unsigned int id)237 static inline int tegra_powergate_remove_clamping(unsigned int id)
238 {
239 return -ENOSYS;
240 }
241
tegra_powergate_sequence_power_up(unsigned int id,struct clk * clk,struct reset_control * rst)242 static inline int tegra_powergate_sequence_power_up(unsigned int id,
243 struct clk *clk,
244 struct reset_control *rst)
245 {
246 return -ENOSYS;
247 }
248
tegra_io_pad_power_enable(enum tegra_io_pad id)249 static inline int tegra_io_pad_power_enable(enum tegra_io_pad id)
250 {
251 return -ENOSYS;
252 }
253
tegra_io_pad_power_disable(enum tegra_io_pad id)254 static inline int tegra_io_pad_power_disable(enum tegra_io_pad id)
255 {
256 return -ENOSYS;
257 }
258
tegra_io_pad_get_voltage(enum tegra_io_pad id)259 static inline int tegra_io_pad_get_voltage(enum tegra_io_pad id)
260 {
261 return -ENOSYS;
262 }
263
tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)264 static inline void tegra_pmc_set_suspend_mode(enum tegra_suspend_mode mode)
265 {
266 }
267
tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)268 static inline void tegra_pmc_enter_suspend_mode(enum tegra_suspend_mode mode)
269 {
270 }
271
tegra_pmc_core_domain_state_synced(void)272 static inline bool tegra_pmc_core_domain_state_synced(void)
273 {
274 return false;
275 }
276
277 #endif /* CONFIG_SOC_TEGRA_PMC */
278
279 #if defined(CONFIG_SOC_TEGRA_PMC) && defined(CONFIG_PM_SLEEP)
280 enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void);
281 #else
tegra_pmc_get_suspend_mode(void)282 static inline enum tegra_suspend_mode tegra_pmc_get_suspend_mode(void)
283 {
284 return TEGRA_SUSPEND_NONE;
285 }
286 #endif
287
288 #endif /* __SOC_TEGRA_PMC_H__ */
289