1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
5 * Copyright (c) 2017 The FreeBSD Foundation
6 * All rights reserved.
7 *
8 * Portions of this software were developed by Landon Fuller
9 * under sponsorship from the FreeBSD Foundation.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
19 * redistribution must be conditioned upon including a substantially
20 * similar Disclaimer requirement for further binary redistribution.
21 *
22 * NO WARRANTY
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
26 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGES.
34 *
35 * $FreeBSD$
36 */
37
38 #ifndef _BHND_CORES_PMU_BHND_PMU_H_
39 #define _BHND_CORES_PMU_BHND_PMU_H_
40
41 #include <sys/types.h>
42
43 #include <dev/bhnd/bhnd.h>
44
45 #include "bhnd_pmu_if.h"
46 #include "bhnd_pmu_types.h"
47
48 /**
49 * Return the current value of a PMU chipctrl register.
50 *
51 * @param dev A bhnd(4) PMU device.
52 * @param reg The PMU chipctrl register to be read.
53 *
54 * Drivers should only use function for functionality that is not
55 * available via another bhnd_chipc() function.
56 *
57 * @returns The chipctrl register value, or 0 if undefined by this hardware.
58 */
59 static inline uint32_t
60 bhnd_pmu_read_chipctrl(device_t dev, uint32_t reg)
61 {
62 return (BHND_PMU_READ_CHIPCTRL(dev, reg));
63 }
64
65 /**
66 * Write @p value with @p mask to a PMU chipctrl register.
67 *
68 * @param dev A bhnd(4) PMU device.
69 * @param reg The PMU chipctrl register to be written.
70 * @param value The value to write.
71 * @param mask The mask of bits to be written from @p value.
72 *
73 * Drivers should only use function for functionality that is not
74 * available via another bhnd_pmu() function.
75 */
76 static inline void
77 bhnd_pmu_write_chipctrl(device_t dev, uint32_t reg, uint32_t value,
78 uint32_t mask)
79 {
80 return (BHND_PMU_WRITE_CHIPCTRL(dev, reg, value, mask));
81 }
82
83 /**
84 * Return the current value of a PMU regulator control register.
85 *
86 * @param dev A bhnd(4) PMU device.
87 * @param reg The PMU regctrl register to be read.
88 *
89 * Drivers should only use function for functionality that is not
90 * available via another bhnd_chipc() function.
91 *
92 * @returns The regctrl register value, or 0 if undefined by this hardware.
93 */
94 static inline uint32_t
95 bhnd_pmu_read_regctrl(device_t dev, uint32_t reg)
96 {
97 return (BHND_PMU_READ_REGCTRL(dev, reg));
98 }
99
100 /**
101 * Write @p value with @p mask to a PMU regulator control register.
102 *
103 * @param dev A bhnd(4) PMU device.
104 * @param reg The PMU regctrl register to be written.
105 * @param value The value to write.
106 * @param mask The mask of bits to be written from @p value.
107 *
108 * Drivers should only use function for functionality that is not
109 * available via another bhnd_pmu() function.
110 */
111 static inline void
112 bhnd_pmu_write_regctrl(device_t dev, uint32_t reg, uint32_t value,
113 uint32_t mask)
114 {
115 return (BHND_PMU_WRITE_REGCTRL(dev, reg, value, mask));
116 }
117
118 /**
119 * Return the current value of a PMU PLL control register.
120 *
121 * @param dev A bhnd(4) PMU device.
122 * @param reg The PMU pllctrl register to be read.
123 *
124 * Drivers should only use function for functionality that is not
125 * available via another bhnd_chipc() function.
126 *
127 * @returns The pllctrl register value, or 0 if undefined by this hardware.
128 */
129 static inline uint32_t
130 bhnd_pmu_read_pllctrl(device_t dev, uint32_t reg)
131 {
132 return (BHND_PMU_READ_PLLCTRL(dev, reg));
133 }
134
135 /**
136 * Write @p value with @p mask to a PMU PLL control register.
137 *
138 * @param dev A bhnd(4) PMU device.
139 * @param reg The PMU pllctrl register to be written.
140 * @param value The value to write.
141 * @param mask The mask of bits to be written from @p value.
142 *
143 * Drivers should only use function for functionality that is not
144 * available via another bhnd_pmu() function.
145 */
146 static inline void
147 bhnd_pmu_write_pllctrl(device_t dev, uint32_t reg, uint32_t value,
148 uint32_t mask)
149 {
150 return (BHND_PMU_WRITE_PLLCTRL(dev, reg, value, mask));
151 }
152
153 /**
154 * Set a hardware-specific output voltage register value for @p regulator.
155 *
156 * @param dev PMU device.
157 * @param regulator Regulator to be configured.
158 * @param value The raw voltage register value.
159 *
160 * @retval 0 success
161 * @retval ENODEV If @p regulator is not supported by this driver.
162 */
163 static inline int
164 bhnd_pmu_set_voltage_raw(device_t dev, bhnd_pmu_regulator regulator,
165 uint32_t value)
166 {
167 return (BHND_PMU_SET_VOLTAGE_RAW(dev, regulator, value));
168 }
169
170 /**
171 * Enable the given @p regulator.
172 *
173 * @param dev PMU device.
174 * @param regulator Regulator to be enabled.
175 *
176 * @retval 0 success
177 * @retval ENODEV If @p regulator is not supported by this driver.
178 */
179 static inline int
180 bhnd_pmu_enable_regulator(device_t dev, bhnd_pmu_regulator regulator)
181 {
182 return (BHND_PMU_ENABLE_REGULATOR(dev, regulator));
183 }
184
185 /**
186 * Disable the given @p regulator.
187 *
188 * @param dev PMU device.
189 * @param regulator Regulator to be disabled.
190 *
191 * @retval 0 success
192 * @retval ENODEV If @p regulator is not supported by this driver.
193 */
194 static inline int
195 bhnd_pmu_disable_regulator(device_t dev, bhnd_pmu_regulator regulator)
196 {
197 return (BHND_PMU_DISABLE_REGULATOR(dev, regulator));
198 }
199
200 /**
201 * Return the transition latency required for @p clock in microseconds, if
202 * known.
203 *
204 * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
205 * 'fastpwrup_dly' value.
206 *
207 * @param dev PMU device.
208 * @param clock The clock to be queried for transition latency.
209 * @param[out] latency On success, the transition latency of @p clock in
210 * microseconds.
211 *
212 * @retval 0 success
213 * @retval ENODEV If the transition latency for @p clock is not available.
214 */
215 static inline int
216 bhnd_pmu_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
217 {
218 return (BHND_PMU_GET_CLOCK_LATENCY(dev, clock, latency));
219 }
220
221 /**
222 * Return the frequency for @p clock in Hz, if known.
223 *
224 * @param dev PMU device.
225 * @param clock The clock to be queried.
226 * @param[out] freq On success, the frequency of @p clock in Hz.
227 *
228 * @retval 0 success
229 * @retval ENODEV If the frequency for @p clock is not available.
230 */
231 static inline int
232 bhnd_pmu_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
233 {
234 return (BHND_PMU_GET_CLOCK_FREQ(dev, clock, freq));
235 }
236
237 /**
238 * Request that the PMU configure itself for a given hardware-specific
239 * spuravoid mode.
240 *
241 * @param dev PMU device.
242 * @param spuravoid The requested mode.
243 *
244 * @retval 0 success
245 * @retval ENODEV If @p regulator is not supported by this driver.
246 */
247 static inline int
248 bhnd_pmu_request_spuravoid(device_t dev, bhnd_pmu_spuravoid spuravoid)
249 {
250 return (BHND_PMU_REQUEST_SPURAVOID(dev, spuravoid));
251 }
252
253 /**
254 * Return the PMU's maximum state transition latency in microseconds.
255 *
256 * This upper bound may be used to busy-wait on PMU clock and resource state
257 * transitions.
258 *
259 * @param dev PMU device.
260 */
261 static inline u_int
262 bhnd_pmu_get_max_transition_latency(device_t dev)
263 {
264 return (BHND_PMU_GET_MAX_TRANSITION_LATENCY(dev));
265 }
266
267 #endif /* _BHND_CORES_PMU_BHND_PMU_H_ */
Cache object: b175be0b92c4f4f94c1df8fe4d1767a7
|