Line data Source code
1 0 : /*
2 : * Copyright (c) 2025 Core Devices LLC
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #ifndef _INCLUDE_ZEPHYR_DRIVERS_CLOCK_CONTROL_SF32LB_H_
7 : #define _INCLUDE_ZEPHYR_DRIVERS_CLOCK_CONTROL_SF32LB_H_
8 :
9 : #include <stdint.h>
10 :
11 : #include <zephyr/device.h>
12 : #include <zephyr/devicetree.h>
13 : #include <zephyr/devicetree/clocks.h>
14 : #include <zephyr/drivers/clock_control.h>
15 :
16 : /**
17 : * @brief Clock Control (SF32LB specifics)
18 : * @defgroup clock_control_sf32lb Clock Control (SF32LB specifics)
19 : * @ingroup clock_control_interface
20 : * @{
21 : */
22 :
23 : /** @brief SF32LB Clock DT spec */
24 1 : struct sf32lb_clock_dt_spec {
25 : /** Clock controller (RCC) */
26 1 : const struct device *dev;
27 : /** Clock ID */
28 1 : uint16_t id;
29 : };
30 :
31 : /**
32 : * @brief Initialize a `sf32lb_clock_dt_spec` structure from a DT node.
33 : *
34 : * @param node_id DT node identifier
35 : */
36 1 : #define SF32LB_CLOCK_DT_SPEC_GET(node_id) \
37 : { \
38 : .dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(node_id)), \
39 : .id = DT_CLOCKS_CELL(node_id, id), \
40 : }
41 :
42 : /**
43 : * @brief Same as SF32LB_CLOCK_DT_SPEC_GET but with a default value
44 : *
45 : * @param node_id DT node identifier
46 : * @param default_spec Default value to be used if the node has no clocks property.
47 : */
48 1 : #define SF32LB_CLOCK_DT_SPEC_GET_OR(node_id, default_spec) \
49 : COND_CODE_1(DT_CLOCKS_HAS_IDX(node_id, 0), \
50 : (SF32LB_CLOCK_DT_SPEC_GET(node_id)), (default_spec))
51 :
52 : /**
53 : * @brief Initialize a `sf32lb_clock_dt_spec` structure from a DT instance.
54 : *
55 : * @param index DT instance index
56 : */
57 1 : #define SF32LB_CLOCK_DT_INST_SPEC_GET(index) SF32LB_CLOCK_DT_SPEC_GET(DT_DRV_INST(index))
58 :
59 : /**
60 : * @brief Same as SF32LB_CLOCK_DT_INST_SPEC_GET but with a default value.
61 : *
62 : * @param index DT instance index
63 : * @param default_spec Default value to be used if the node has no clocks property.
64 : */
65 1 : #define SF32LB_CLOCK_DT_INST_SPEC_GET_OR(index, default_spec) \
66 : SF32LB_CLOCK_DT_SPEC_GET_OR(DT_DRV_INST(index), default_spec)
67 : /**
68 : * @brief Check if the clock device is ready
69 : *
70 : * @param spec SF32LB clock DT spec
71 : *
72 : * @return true If the clock device is ready.
73 : * @return false If the clock device is not ready.
74 : */
75 1 : static inline bool sf3232lb_clock_is_ready_dt(const struct sf32lb_clock_dt_spec *spec)
76 : {
77 : return device_is_ready(spec->dev);
78 : }
79 :
80 : /**
81 : * @brief Turn on a clock using a `sf32lb_clock_dt_spec` structure.
82 : *
83 : * @param spec SF32LB clock DT spec
84 : * @return See clock_control_on().
85 : */
86 1 : static inline int sf32lb_clock_control_on_dt(const struct sf32lb_clock_dt_spec *spec)
87 : {
88 : return clock_control_on(spec->dev, (clock_control_subsys_t)&spec->id);
89 : }
90 :
91 : /**
92 : * @brief Turn off a clock using a `sf32lb_clock_dt_spec` structure.
93 : *
94 : * @param spec SF32LB clock DT spec
95 : * @return See clock_control_off().
96 : */
97 1 : static inline int sf32lb_clock_control_off_dt(const struct sf32lb_clock_dt_spec *spec)
98 : {
99 : return clock_control_off(spec->dev, (clock_control_subsys_t)&spec->id);
100 : }
101 :
102 : /** @} */
103 :
104 : #endif /* _INCLUDE_ZEPHYR_DRIVERS_CLOCK_CONTROL_SF32LB_H_ */
|