1 /* Copyright 2018 SiFive, Inc. */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/machine/platform.h>
6 #ifdef METAL_FIXED_FACTOR_CLOCK
8 #include <metal/drivers/fixed-factor-clock.h>
10 #include <metal/machine.h>
12 long __metal_driver_fixed_factor_clock_get_rate_hz(const struct metal_clock *gclk)
14 struct metal_clock *parent = __metal_driver_fixed_factor_clock_parent(gclk);
17 parent_rate = parent->vtable->get_rate_hz(parent);
20 return __metal_driver_fixed_factor_clock_mult(gclk) * parent_rate / __metal_driver_fixed_factor_clock_div(gclk);
23 long __metal_driver_fixed_factor_clock_set_rate_hz(struct metal_clock *gclk, long target_hz)
25 return __metal_driver_fixed_factor_clock_get_rate_hz(gclk);
28 __METAL_DEFINE_VTABLE(__metal_driver_vtable_fixed_factor_clock) = {
29 .clock.get_rate_hz = __metal_driver_fixed_factor_clock_get_rate_hz,
30 .clock.set_rate_hz = __metal_driver_fixed_factor_clock_set_rate_hz,
32 #endif /* METAL_FIXED_FACTOR_CLOCK */