1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef MOD_MOCK_CLOCK_H
9 #define MOD_MOCK_CLOCK_H
10 
11 #include <fwk_id.h>
12 #include <fwk_module_idx.h>
13 
14 #include <stdbool.h>
15 #include <stdint.h>
16 
17 /*!
18  * \ingroup GroupModules
19  * \defgroup GroupMockClock Mock Clock Driver
20  *
21  * \details The `mock_clock` module provides a mock clock driver for use
22  *      alongside the `clock` interface on systems that do not provide a real
23  *      clock driver.
24  *
25  * \warning When using this module to mock a pre-existing driver
26  *      for any reason, this driver must be forced to bind to the
27  *      ::MOD_MOCK_CLOCK_API_TYPE_RESPONSE_DRIVER API through its module
28  *      configuration. This will avoid any conflict between the pre-existing
29  *      driver and the mocked one.
30  * \{
31  */
32 
33 /*!
34  * \brief Rate lookup table entry.
35  */
36 struct mod_mock_clock_rate {
37     /*! Rate of the clock in Hertz. */
38     uint32_t rate;
39 
40     /*! The clock divider used to attain the rate. */
41     unsigned int divider;
42 };
43 
44 /*!
45  * \brief Element configuration.
46  */
47 struct mod_mock_clock_element_cfg {
48     /*! Pointer to the clock's rate lookup table. */
49     const struct mod_mock_clock_rate *rate_table;
50 
51     /*! The number of rates in the rate lookup table. */
52     unsigned int rate_count;
53 
54     /*! The default rate value if the clock device is running at startup. */
55     uint32_t default_rate;
56 };
57 
58 /*!
59  * \brief API indices.
60  *
61  * \warning The mock clock implements the clock driver API only. The response
62  *      driver API only acts as a pointer to be bound to.
63  */
64 enum mod_mock_clock_api_type {
65     /*!
66      * \brief Clock driver.
67      *
68      * \note This API implements the mod_clock::mod_clock_driver_api interface.
69      *
70      * \warning Binding to this API must occur through an element of this
71      *      module.
72      */
73     MOD_MOCK_CLOCK_API_TYPE_DRIVER,
74 
75     /*!
76      * \brief Clock driver response.
77      *
78      * \note This API implements the mod_clock::mod_clock_driver_response_api
79      * interface.
80      *
81      * \warning Binding to this API must occur through an element of this
82      *      module.
83      */
84     MOD_MOCK_CLOCK_API_TYPE_RESPONSE_DRIVER,
85 
86     /*!
87      * \brief Number of defined APIs.
88      */
89     MOD_MOCK_CLOCK_API_COUNT,
90 };
91 
92 /*!
93  * \brief Driver API identifier.
94  *
95  * \note This identifier corresponds to the ::MOD_MOCK_CLOCK_API_TYPE_DRIVER API
96  *      index.
97  */
98 static const fwk_id_t mod_mock_clock_api_id_driver =
99     FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_CLOCK, MOD_MOCK_CLOCK_API_TYPE_DRIVER);
100 
101 /*!
102  * \}
103  */
104 
105 #endif /* MOD_MOCK_CLOCK_H */
106