1 /*
2 * SPDX-License-Identifier: Apache-2.0
3 *
4 * Copyright (C) 2022 Google, LLC
5 *
6 */
7
8 #include <zephyr/drivers/clock_control.h>
9
10 #define DT_DRV_COMPAT fixed_clock
11
12 struct fixed_rate_clock_config {
13 uint32_t rate;
14 };
15
fixed_rate_clk_on(const struct device * dev,clock_control_subsys_t sys)16 static int fixed_rate_clk_on(const struct device *dev,
17 clock_control_subsys_t sys)
18 {
19 ARG_UNUSED(dev);
20 ARG_UNUSED(sys);
21
22 return 0;
23 }
24
fixed_rate_clk_off(const struct device * dev,clock_control_subsys_t sys)25 static int fixed_rate_clk_off(const struct device *dev,
26 clock_control_subsys_t sys)
27 {
28 ARG_UNUSED(dev);
29 ARG_UNUSED(sys);
30
31 return 0;
32 }
33
fixed_rate_clk_get_status(const struct device * dev,clock_control_subsys_t sys)34 static enum clock_control_status fixed_rate_clk_get_status(const struct device *dev,
35 clock_control_subsys_t sys)
36 {
37 return CLOCK_CONTROL_STATUS_ON;
38 }
39
fixed_rate_clk_get_rate(const struct device * dev,clock_control_subsys_t sys,uint32_t * rate)40 static int fixed_rate_clk_get_rate(const struct device *dev,
41 clock_control_subsys_t sys,
42 uint32_t *rate)
43 {
44 const struct fixed_rate_clock_config *config = dev->config;
45
46 ARG_UNUSED(sys);
47
48 *rate = config->rate;
49 return 0;
50 }
51
52 static const struct clock_control_driver_api fixed_rate_clk_api = {
53 .on = fixed_rate_clk_on,
54 .off = fixed_rate_clk_off,
55 .get_status = fixed_rate_clk_get_status,
56 .get_rate = fixed_rate_clk_get_rate
57 };
58
fixed_rate_clk_init(const struct device * dev)59 static int fixed_rate_clk_init(const struct device *dev)
60 {
61 ARG_UNUSED(dev);
62
63 return 0;
64 }
65
66 #define FIXED_CLK_INIT(idx) \
67 static const struct fixed_rate_clock_config fixed_rate_clock_config_##idx = { \
68 .rate = DT_INST_PROP(idx, clock_frequency), \
69 }; \
70 DEVICE_DT_INST_DEFINE(idx, \
71 fixed_rate_clk_init, \
72 NULL, NULL, \
73 &fixed_rate_clock_config_##idx, \
74 PRE_KERNEL_1, \
75 CONFIG_CLOCK_CONTROL_INIT_PRIORITY, \
76 &fixed_rate_clk_api \
77 );
78 DT_INST_FOREACH_STATUS_OKAY(FIXED_CLK_INIT)
79