diff options
author | Gabriel Fernandez <gabriel.fernandez@st.com> | 2020-10-13 09:36:25 +0200 |
---|---|---|
committer | Yann Gautier <yann.gautier@st.com> | 2021-12-22 13:07:23 +0100 |
commit | 847c6bc8e6d55b1c0f31a52407aa61515cd6c612 (patch) | |
tree | 578509e25e2e017c8240b1e50e60888f53a9fa0b /drivers/clk | |
parent | 47833abd7772a49aa1b591392584549fb5a2c28f (diff) | |
download | arm-trusted-firmware-847c6bc8e6d55b1c0f31a52407aa61515cd6c612.tar.gz |
feat(clk): add a minimal clock framework
This is mainly a clock interface with clk_ops callbacks.
Those callbacks are: enable, disable, get_rate, set_parent,
and is_enabled.
This framework is compiled for STM32MP1.
Change-Id: I5119a2aeaf103ceaae7a60d9e423caf0c148d794
Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@st.com>
Diffstat (limited to 'drivers/clk')
-rw-r--r-- | drivers/clk/clk.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c new file mode 100644 index 000000000..4cbc0f70f --- /dev/null +++ b/drivers/clk/clk.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021, STMicroelectronics - All Rights Reserved + * Author(s): Ludovic Barre, <ludovic.barre@st.com> for STMicroelectronics. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <assert.h> +#include <errno.h> +#include <stdbool.h> + +#include <drivers/clk.h> + +static const struct clk_ops *ops; + +int clk_enable(unsigned long id) +{ + assert((ops != NULL) && (ops->enable != NULL)); + + return ops->enable(id); +} + +void clk_disable(unsigned long id) +{ + assert((ops != NULL) && (ops->disable != NULL)); + + ops->disable(id); +} + +unsigned long clk_get_rate(unsigned long id) +{ + assert((ops != NULL) && (ops->get_rate != NULL)); + + return ops->get_rate(id); +} + +int clk_get_parent(unsigned long id) +{ + assert((ops != NULL) && (ops->get_parent != NULL)); + + return ops->get_parent(id); +} + +bool clk_is_enabled(unsigned long id) +{ + assert((ops != NULL) && (ops->is_enabled != NULL)); + + return ops->is_enabled(id); +} + +/* + * Initialize the clk. The fields in the provided clk + * ops pointer must be valid. + */ +void clk_register(const struct clk_ops *ops_ptr) +{ + assert((ops_ptr != NULL) && + (ops_ptr->enable != NULL) && + (ops_ptr->disable != NULL) && + (ops_ptr->get_rate != NULL) && + (ops_ptr->get_parent != NULL) && + (ops_ptr->is_enabled != NULL)); + + ops = ops_ptr; +} |