xref: /freebsd/sys/dev/bhnd/cores/pmu/bhnd_pmu.h (revision 4f52dfbb)
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 /**
50  * Return the current value of a PMU chipctrl register.
51  *
52  * @param dev A bhnd(4) PMU device.
53  * @param reg The PMU chipctrl register to be read.
54  *
55  * Drivers should only use function for functionality that is not
56  * available via another bhnd_chipc() function.
57  *
58  * @returns The chipctrl register value, or 0 if undefined by this hardware.
59  */
60 static inline uint32_t
61 bhnd_pmu_read_chipctrl(device_t dev, uint32_t reg)
62 {
63 	return (BHND_PMU_READ_CHIPCTRL(dev, reg));
64 }
65 
66 /**
67  * Write @p value with @p mask to a PMU chipctrl register.
68  *
69  * @param dev A bhnd(4) PMU device.
70  * @param reg The PMU chipctrl register to be written.
71  * @param value The value to write.
72  * @param mask The mask of bits to be written from @p value.
73  *
74  * Drivers should only use function for functionality that is not
75  * available via another bhnd_pmu() function.
76  */
77 static inline void
78 bhnd_pmu_write_chipctrl(device_t dev, uint32_t reg, uint32_t value,
79     uint32_t mask)
80 {
81 	return (BHND_PMU_WRITE_CHIPCTRL(dev, reg, value, mask));
82 }
83 
84 /**
85  * Return the current value of a PMU regulator control register.
86  *
87  * @param dev A bhnd(4) PMU device.
88  * @param reg The PMU regctrl register to be read.
89  *
90  * Drivers should only use function for functionality that is not
91  * available via another bhnd_chipc() function.
92  *
93  * @returns The regctrl register value, or 0 if undefined by this hardware.
94  */
95 static inline uint32_t
96 bhnd_pmu_read_regctrl(device_t dev, uint32_t reg)
97 {
98 	return (BHND_PMU_READ_REGCTRL(dev, reg));
99 }
100 
101 /**
102  * Write @p value with @p mask to a PMU regulator control register.
103  *
104  * @param dev A bhnd(4) PMU device.
105  * @param reg The PMU regctrl register to be written.
106  * @param value The value to write.
107  * @param mask The mask of bits to be written from @p value.
108  *
109  * Drivers should only use function for functionality that is not
110  * available via another bhnd_pmu() function.
111  */
112 static inline void
113 bhnd_pmu_write_regctrl(device_t dev, uint32_t reg, uint32_t value,
114     uint32_t mask)
115 {
116 	return (BHND_PMU_WRITE_REGCTRL(dev, reg, value, mask));
117 }
118 
119 /**
120  * Return the current value of a PMU PLL control register.
121  *
122  * @param dev A bhnd(4) PMU device.
123  * @param reg The PMU pllctrl register to be read.
124  *
125  * Drivers should only use function for functionality that is not
126  * available via another bhnd_chipc() function.
127  *
128  * @returns The pllctrl register value, or 0 if undefined by this hardware.
129  */
130 static inline uint32_t
131 bhnd_pmu_read_pllctrl(device_t dev, uint32_t reg)
132 {
133 	return (BHND_PMU_READ_PLLCTRL(dev, reg));
134 }
135 
136 /**
137  * Write @p value with @p mask to a PMU PLL control register.
138  *
139  * @param dev A bhnd(4) PMU device.
140  * @param reg The PMU pllctrl register to be written.
141  * @param value The value to write.
142  * @param mask The mask of bits to be written from @p value.
143  *
144  * Drivers should only use function for functionality that is not
145  * available via another bhnd_pmu() function.
146  */
147 static inline void
148 bhnd_pmu_write_pllctrl(device_t dev, uint32_t reg, uint32_t value,
149     uint32_t mask)
150 {
151 	return (BHND_PMU_WRITE_PLLCTRL(dev, reg, value, mask));
152 }
153 
154 /**
155  * Set a hardware-specific output voltage register value for @p regulator.
156  *
157  * @param dev PMU device.
158  * @param regulator Regulator to be configured.
159  * @param value The raw voltage register value.
160  *
161  * @retval 0 success
162  * @retval ENODEV If @p regulator is not supported by this driver.
163  */
164 static inline int
165 bhnd_pmu_set_voltage_raw(device_t dev, bhnd_pmu_regulator regulator,
166     uint32_t value)
167 {
168 	return (BHND_PMU_SET_VOLTAGE_RAW(dev, regulator, value));
169 }
170 
171 /**
172  * Enable the given @p regulator.
173  *
174  * @param dev PMU device.
175  * @param regulator Regulator to be enabled.
176  *
177  * @retval 0 success
178  * @retval ENODEV If @p regulator is not supported by this driver.
179  */
180 static inline int
181 bhnd_pmu_enable_regulator(device_t dev, bhnd_pmu_regulator regulator)
182 {
183 	return (BHND_PMU_ENABLE_REGULATOR(dev, regulator));
184 }
185 
186 /**
187  * Disable the given @p regulator.
188  *
189  * @param dev PMU device.
190  * @param regulator Regulator to be disabled.
191  *
192  * @retval 0 success
193  * @retval ENODEV If @p regulator is not supported by this driver.
194  */
195 static inline int
196 bhnd_pmu_disable_regulator(device_t dev, bhnd_pmu_regulator regulator)
197 {
198 	return (BHND_PMU_DISABLE_REGULATOR(dev, regulator));
199 }
200 
201 /**
202  * Return the transition latency required for @p clock in microseconds, if
203  * known.
204  *
205  * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
206  * 'fastpwrup_dly' value.
207  *
208  * @param	dev	PMU device.
209  * @param	clock	The clock to be queried for transition latency.
210  * @param[out]	latency	On success, the transition latency of @p clock in
211  *			microseconds.
212  *
213  * @retval 0 success
214  * @retval ENODEV If the transition latency for @p clock is not available.
215  */
216 static inline int
217 bhnd_pmu_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
218 {
219 	return (BHND_PMU_GET_CLOCK_LATENCY(dev, clock, latency));
220 }
221 
222 /**
223  * Return the frequency for @p clock in Hz, if known.
224  *
225  * @param dev PMU device.
226  * @param clock The clock to be queried.
227  * @param[out] freq On success, the frequency of @p clock in Hz.
228  *
229  * @retval 0 success
230  * @retval ENODEV If the frequency for @p clock is not available.
231  */
232 static inline int
233 bhnd_pmu_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
234 {
235 	return (BHND_PMU_GET_CLOCK_FREQ(dev, clock, freq));
236 }
237 
238 /**
239  * Request that the PMU configure itself for a given hardware-specific
240  * spuravoid mode.
241  *
242  * @param dev PMU device.
243  * @param spuravoid The requested mode.
244  *
245  * @retval 0 success
246  * @retval ENODEV If @p regulator is not supported by this driver.
247  */
248 static inline int
249 bhnd_pmu_request_spuravoid(device_t dev, bhnd_pmu_spuravoid spuravoid)
250 {
251 	return (BHND_PMU_REQUEST_SPURAVOID(dev, spuravoid));
252 }
253 
254 
255 /**
256  * Return the PMU's maximum state transition latency in microseconds.
257  *
258  * This upper bound may be used to busy-wait on PMU clock and resource state
259  * transitions.
260  *
261  * @param dev PMU device.
262  */
263 static inline u_int
264 bhnd_pmu_get_max_transition_latency(device_t dev)
265 {
266 	return (BHND_PMU_GET_MAX_TRANSITION_LATENCY(dev));
267 }
268 
269 #endif /* _BHND_CORES_PMU_BHND_PMU_H_ */
270