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