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 * $FreeBSD$ 34 */ 35 36 #ifndef _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_ 37 #define _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_ 38 39 #include "bhnd_pwrctl_hostb_if.h" 40 41 #include "bhnd_pwrctlvar.h" 42 43 int bhnd_pwrctl_init(struct bhnd_pwrctl_softc *sc); 44 int bhnd_pwrctl_setclk(struct bhnd_pwrctl_softc *sc, 45 bhnd_clock clock); 46 uint32_t bhnd_pwrctl_getclk_speed(struct bhnd_pwrctl_softc *sc); 47 u_int bhnd_pwrctl_fast_pwrup_delay(struct bhnd_pwrctl_softc *sc); 48 49 /** 50 * If supported by the chipset, return the clock source for the given clock. 51 * 52 * This function is only supported on early PWRCTL-equipped chipsets 53 * that expose clock management via their host bridge interface. Currently, 54 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9. 55 * 56 * @param dev A bhnd bus child device. 57 * @param clock The clock for which a clock source will be returned. 58 * 59 * @retval bhnd_clksrc The clock source for @p clock. 60 * @retval BHND_CLKSRC_UNKNOWN If @p clock is unsupported, or its 61 * clock source is not known to the bus. 62 */ 63 static inline bhnd_clksrc 64 bhnd_pwrctl_hostb_get_clksrc(device_t dev, bhnd_clock clock) 65 { 66 return (BHND_PWRCTL_HOSTB_GET_CLKSRC(device_get_parent(dev), dev, 67 clock)); 68 } 69 70 /** 71 * If supported by the chipset, gate @p clock 72 * 73 * This function is only supported on early PWRCTL-equipped chipsets 74 * that expose clock management via their host bridge interface. Currently, 75 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9. 76 * 77 * @param dev A bhnd bus child device. 78 * @param clock The clock to be disabled. 79 * 80 * @retval 0 success 81 * @retval ENODEV If bus-level clock source management is not supported. 82 * @retval ENXIO If bus-level management of @p clock is not supported. 83 */ 84 static inline int 85 bhnd_pwrctl_hostb_gate_clock(device_t dev, bhnd_clock clock) 86 { 87 return (BHND_PWRCTL_HOSTB_GATE_CLOCK(device_get_parent(dev), dev, 88 clock)); 89 } 90 91 /** 92 * If supported by the chipset, ungate @p clock 93 * 94 * This function is only supported on early PWRCTL-equipped chipsets 95 * that expose clock management via their host bridge interface. Currently, 96 * this includes PCI (not PCIe) devices, with ChipCommon core revisions 0-9. 97 * 98 * @param dev A bhnd bus child device. 99 * @param clock The clock to be enabled. 100 * 101 * @retval 0 success 102 * @retval ENODEV If bus-level clock source management is not supported. 103 * @retval ENXIO If bus-level management of @p clock is not supported. 104 */ 105 static inline int 106 bhnd_pwrctl_hostb_ungate_clock(device_t dev, bhnd_clock clock) 107 { 108 return (BHND_PWRCTL_HOSTB_UNGATE_CLOCK(device_get_parent(dev), dev, 109 clock)); 110 } 111 112 #endif /* _BHND_PWRCTL_BHND_PWRCTL_PRIVATE_H_ */ 113