1 /*
2 * Copyright 2024 Felipe Neves
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/drivers/clock_control.h>
10 #include <zephyr/logging/log.h>
11
12 LOG_MODULE_REGISTER(camera_ext_clock, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
13
camera_ext_clock_enable(void)14 int camera_ext_clock_enable(void)
15 {
16 int ret;
17 uint32_t rate;
18 const struct device *cam_ext_clk_dev = DEVICE_DT_GET(DT_NODELABEL(pwmclock));
19
20 if (!device_is_ready(cam_ext_clk_dev)) {
21 LOG_ERR("Camera external clock source device is not ready!");
22 return -ENODEV;
23 }
24
25 ret = clock_control_on(cam_ext_clk_dev, (clock_control_subsys_t)0);
26 if (ret < 0) {
27 LOG_ERR("Failed to enable camera external clock error: (%d)", ret);
28 return ret;
29 }
30
31 ret = clock_control_get_rate(cam_ext_clk_dev, (clock_control_subsys_t)0, &rate);
32 if (ret < 0) {
33 LOG_ERR("Failed to get camera external clock rate, error: (%d)", ret);
34 return ret;
35 }
36
37 LOG_INF("Camera external clock rate: (%u) Hz", rate);
38
39 return 0;
40 }
41
42 SYS_INIT(camera_ext_clock_enable, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
43