1*847c6bc8SGabriel Fernandez /* 2*847c6bc8SGabriel Fernandez * Copyright (c) 2021, STMicroelectronics - All Rights Reserved 3*847c6bc8SGabriel Fernandez * Author(s): Ludovic Barre, <ludovic.barre@st.com> for STMicroelectronics. 4*847c6bc8SGabriel Fernandez * 5*847c6bc8SGabriel Fernandez * SPDX-License-Identifier: BSD-3-Clause 6*847c6bc8SGabriel Fernandez */ 7*847c6bc8SGabriel Fernandez 8*847c6bc8SGabriel Fernandez #include <assert.h> 9*847c6bc8SGabriel Fernandez #include <errno.h> 10*847c6bc8SGabriel Fernandez #include <stdbool.h> 11*847c6bc8SGabriel Fernandez 12*847c6bc8SGabriel Fernandez #include <drivers/clk.h> 13*847c6bc8SGabriel Fernandez 14*847c6bc8SGabriel Fernandez static const struct clk_ops *ops; 15*847c6bc8SGabriel Fernandez 16*847c6bc8SGabriel Fernandez int clk_enable(unsigned long id) 17*847c6bc8SGabriel Fernandez { 18*847c6bc8SGabriel Fernandez assert((ops != NULL) && (ops->enable != NULL)); 19*847c6bc8SGabriel Fernandez 20*847c6bc8SGabriel Fernandez return ops->enable(id); 21*847c6bc8SGabriel Fernandez } 22*847c6bc8SGabriel Fernandez 23*847c6bc8SGabriel Fernandez void clk_disable(unsigned long id) 24*847c6bc8SGabriel Fernandez { 25*847c6bc8SGabriel Fernandez assert((ops != NULL) && (ops->disable != NULL)); 26*847c6bc8SGabriel Fernandez 27*847c6bc8SGabriel Fernandez ops->disable(id); 28*847c6bc8SGabriel Fernandez } 29*847c6bc8SGabriel Fernandez 30*847c6bc8SGabriel Fernandez unsigned long clk_get_rate(unsigned long id) 31*847c6bc8SGabriel Fernandez { 32*847c6bc8SGabriel Fernandez assert((ops != NULL) && (ops->get_rate != NULL)); 33*847c6bc8SGabriel Fernandez 34*847c6bc8SGabriel Fernandez return ops->get_rate(id); 35*847c6bc8SGabriel Fernandez } 36*847c6bc8SGabriel Fernandez 37*847c6bc8SGabriel Fernandez int clk_get_parent(unsigned long id) 38*847c6bc8SGabriel Fernandez { 39*847c6bc8SGabriel Fernandez assert((ops != NULL) && (ops->get_parent != NULL)); 40*847c6bc8SGabriel Fernandez 41*847c6bc8SGabriel Fernandez return ops->get_parent(id); 42*847c6bc8SGabriel Fernandez } 43*847c6bc8SGabriel Fernandez 44*847c6bc8SGabriel Fernandez bool clk_is_enabled(unsigned long id) 45*847c6bc8SGabriel Fernandez { 46*847c6bc8SGabriel Fernandez assert((ops != NULL) && (ops->is_enabled != NULL)); 47*847c6bc8SGabriel Fernandez 48*847c6bc8SGabriel Fernandez return ops->is_enabled(id); 49*847c6bc8SGabriel Fernandez } 50*847c6bc8SGabriel Fernandez 51*847c6bc8SGabriel Fernandez /* 52*847c6bc8SGabriel Fernandez * Initialize the clk. The fields in the provided clk 53*847c6bc8SGabriel Fernandez * ops pointer must be valid. 54*847c6bc8SGabriel Fernandez */ 55*847c6bc8SGabriel Fernandez void clk_register(const struct clk_ops *ops_ptr) 56*847c6bc8SGabriel Fernandez { 57*847c6bc8SGabriel Fernandez assert((ops_ptr != NULL) && 58*847c6bc8SGabriel Fernandez (ops_ptr->enable != NULL) && 59*847c6bc8SGabriel Fernandez (ops_ptr->disable != NULL) && 60*847c6bc8SGabriel Fernandez (ops_ptr->get_rate != NULL) && 61*847c6bc8SGabriel Fernandez (ops_ptr->get_parent != NULL) && 62*847c6bc8SGabriel Fernandez (ops_ptr->is_enabled != NULL)); 63*847c6bc8SGabriel Fernandez 64*847c6bc8SGabriel Fernandez ops = ops_ptr; 65*847c6bc8SGabriel Fernandez } 66