1 /*-
2 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
3 * Copyright (c) 2017 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Landon Fuller
7 * under sponsorship from the FreeBSD Foundation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
19 *
20 * NO WARRANTY
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 */
34
35 #ifndef _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_
36 #define _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_
37
38 #include "bhnd_pwrctl_hostb_if.h"
39
40 #include "bhnd_pwrctlvar.h"
41
42 int bhnd_pwrctl_init(struct bhnd_pwrctl_softc *sc);
43 int bhnd_pwrctl_setclk(struct bhnd_pwrctl_softc *sc,
44 bhnd_clock clock);
45 uint32_t bhnd_pwrctl_getclk_speed(struct bhnd_pwrctl_softc *sc);
46 u_int bhnd_pwrctl_fast_pwrup_delay(struct bhnd_pwrctl_softc *sc);
47
48 /**
49 * If supported by the chipset, return the clock source for the given clock.
50 *
51 * This function is only supported on early PWRCTL-equipped chipsets
52 * that expose clock management via their host bridge interface. Currently,
53 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
54 *
55 * @param dev A bhnd bus child device.
56 * @param clock The clock for which a clock source will be returned.
57 *
58 * @retval bhnd_clksrc The clock source for @p clock.
59 * @retval BHND_CLKSRC_UNKNOWN If @p clock is unsupported, or its
60 * clock source is not known to the bus.
61 */
62 static inline bhnd_clksrc
bhnd_pwrctl_hostb_get_clksrc(device_t dev,bhnd_clock clock)63 bhnd_pwrctl_hostb_get_clksrc(device_t dev, bhnd_clock clock)
64 {
65 return (BHND_PWRCTL_HOSTB_GET_CLKSRC(device_get_parent(dev), dev,
66 clock));
67 }
68
69 /**
70 * If supported by the chipset, gate @p clock
71 *
72 * This function is only supported on early PWRCTL-equipped chipsets
73 * that expose clock management via their host bridge interface. Currently,
74 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
75 *
76 * @param dev A bhnd bus child device.
77 * @param clock The clock to be disabled.
78 *
79 * @retval 0 success
80 * @retval ENODEV If bus-level clock source management is not supported.
81 * @retval ENXIO If bus-level management of @p clock is not supported.
82 */
83 static inline int
bhnd_pwrctl_hostb_gate_clock(device_t dev,bhnd_clock clock)84 bhnd_pwrctl_hostb_gate_clock(device_t dev, bhnd_clock clock)
85 {
86 return (BHND_PWRCTL_HOSTB_GATE_CLOCK(device_get_parent(dev), dev,
87 clock));
88 }
89
90 /**
91 * If supported by the chipset, ungate @p clock
92 *
93 * This function is only supported on early PWRCTL-equipped chipsets
94 * that expose clock management via their host bridge interface. Currently,
95 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9.
96 *
97 * @param dev A bhnd bus child device.
98 * @param clock The clock to be enabled.
99 *
100 * @retval 0 success
101 * @retval ENODEV If bus-level clock source management is not supported.
102 * @retval ENXIO If bus-level management of @p clock is not supported.
103 */
104 static inline int
bhnd_pwrctl_hostb_ungate_clock(device_t dev,bhnd_clock clock)105 bhnd_pwrctl_hostb_ungate_clock(device_t dev, bhnd_clock clock)
106 {
107 return (BHND_PWRCTL_HOSTB_UNGATE_CLOCK(device_get_parent(dev), dev,
108 clock));
109 }
110
111 #endif /* _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_ */
112