2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
5 * Copyright (c) 2017 The FreeBSD Foundation
8 * Portions of this software were developed by Landon Fuller
9 * under sponsorship from the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
38 #ifndef _BHND_CORES_PMU_BHND_PMU_H_
39 #define _BHND_CORES_PMU_BHND_PMU_H_
41 #include <sys/types.h>
43 #include <dev/bhnd/bhnd.h>
45 #include "bhnd_pmu_if.h"
46 #include "bhnd_pmu_types.h"
50 * Return the current value of a PMU chipctrl register.
52 * @param dev A bhnd(4) PMU device.
53 * @param reg The PMU chipctrl register to be read.
55 * Drivers should only use function for functionality that is not
56 * available via another bhnd_chipc() function.
58 * @returns The chipctrl register value, or 0 if undefined by this hardware.
60 static inline uint32_t
61 bhnd_pmu_read_chipctrl(device_t dev, uint32_t reg)
63 return (BHND_PMU_READ_CHIPCTRL(dev, reg));
67 * Write @p value with @p mask to a PMU chipctrl register.
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.
74 * Drivers should only use function for functionality that is not
75 * available via another bhnd_pmu() function.
78 bhnd_pmu_write_chipctrl(device_t dev, uint32_t reg, uint32_t value,
81 return (BHND_PMU_WRITE_CHIPCTRL(dev, reg, value, mask));
85 * Return the current value of a PMU regulator control register.
87 * @param dev A bhnd(4) PMU device.
88 * @param reg The PMU regctrl register to be read.
90 * Drivers should only use function for functionality that is not
91 * available via another bhnd_chipc() function.
93 * @returns The regctrl register value, or 0 if undefined by this hardware.
95 static inline uint32_t
96 bhnd_pmu_read_regctrl(device_t dev, uint32_t reg)
98 return (BHND_PMU_READ_REGCTRL(dev, reg));
102 * Write @p value with @p mask to a PMU regulator control register.
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.
109 * Drivers should only use function for functionality that is not
110 * available via another bhnd_pmu() function.
113 bhnd_pmu_write_regctrl(device_t dev, uint32_t reg, uint32_t value,
116 return (BHND_PMU_WRITE_REGCTRL(dev, reg, value, mask));
120 * Return the current value of a PMU PLL control register.
122 * @param dev A bhnd(4) PMU device.
123 * @param reg The PMU pllctrl register to be read.
125 * Drivers should only use function for functionality that is not
126 * available via another bhnd_chipc() function.
128 * @returns The pllctrl register value, or 0 if undefined by this hardware.
130 static inline uint32_t
131 bhnd_pmu_read_pllctrl(device_t dev, uint32_t reg)
133 return (BHND_PMU_READ_PLLCTRL(dev, reg));
137 * Write @p value with @p mask to a PMU PLL control register.
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.
144 * Drivers should only use function for functionality that is not
145 * available via another bhnd_pmu() function.
148 bhnd_pmu_write_pllctrl(device_t dev, uint32_t reg, uint32_t value,
151 return (BHND_PMU_WRITE_PLLCTRL(dev, reg, value, mask));
155 * Set a hardware-specific output voltage register value for @p regulator.
157 * @param dev PMU device.
158 * @param regulator Regulator to be configured.
159 * @param value The raw voltage register value.
162 * @retval ENODEV If @p regulator is not supported by this driver.
165 bhnd_pmu_set_voltage_raw(device_t dev, bhnd_pmu_regulator regulator,
168 return (BHND_PMU_SET_VOLTAGE_RAW(dev, regulator, value));
172 * Enable the given @p regulator.
174 * @param dev PMU device.
175 * @param regulator Regulator to be enabled.
178 * @retval ENODEV If @p regulator is not supported by this driver.
181 bhnd_pmu_enable_regulator(device_t dev, bhnd_pmu_regulator regulator)
183 return (BHND_PMU_ENABLE_REGULATOR(dev, regulator));
187 * Disable the given @p regulator.
189 * @param dev PMU device.
190 * @param regulator Regulator to be disabled.
193 * @retval ENODEV If @p regulator is not supported by this driver.
196 bhnd_pmu_disable_regulator(device_t dev, bhnd_pmu_regulator regulator)
198 return (BHND_PMU_DISABLE_REGULATOR(dev, regulator));
202 * Return the transition latency required for @p clock in microseconds, if
205 * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
206 * 'fastpwrup_dly' value.
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
214 * @retval ENODEV If the transition latency for @p clock is not available.
217 bhnd_pmu_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
219 return (BHND_PMU_GET_CLOCK_LATENCY(dev, clock, latency));
223 * Return the frequency for @p clock in Hz, if known.
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.
230 * @retval ENODEV If the frequency for @p clock is not available.
233 bhnd_pmu_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
235 return (BHND_PMU_GET_CLOCK_FREQ(dev, clock, freq));
239 * Request that the PMU configure itself for a given hardware-specific
242 * @param dev PMU device.
243 * @param spuravoid The requested mode.
246 * @retval ENODEV If @p regulator is not supported by this driver.
249 bhnd_pmu_request_spuravoid(device_t dev, bhnd_pmu_spuravoid spuravoid)
251 return (BHND_PMU_REQUEST_SPURAVOID(dev, spuravoid));
256 * Return the PMU's maximum state transition latency in microseconds.
258 * This upper bound may be used to busy-wait on PMU clock and resource state
261 * @param dev PMU device.
264 bhnd_pmu_get_max_transition_latency(device_t dev)
266 return (BHND_PMU_GET_MAX_TRANSITION_LATENCY(dev));
269 #endif /* _BHND_CORES_PMU_BHND_PMU_H_ */