drivers: clock_control: Add clock_fixed_rate driver
Add fixed-clock clock control driver. This is a first step towards making fixed-clocks a first-class citizen in the clock control framework. Since the change is hidden behind a Kconfig enable this is opt-in for now. Signed-off-by: Moritz Fischer <moritzf@google.com>
This commit is contained in:
parent
4828c89fa2
commit
28ed7f057d
|
@ -5,6 +5,7 @@ zephyr_library()
|
|||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_BEETLE beetle_clock_control.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_ADSP clock_control_adsp.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_ESP32 clock_control_esp32.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK clock_control_fixed_rate.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_GD32 clock_control_gd32.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_LITEX clock_control_litex.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_LPC11U6X clock_control_lpc11u6x.c)
|
||||
|
|
|
@ -32,6 +32,8 @@ source "drivers/clock_control/Kconfig.stm32"
|
|||
|
||||
source "drivers/clock_control/Kconfig.beetle"
|
||||
|
||||
source "drivers/clock_control/Kconfig.fixed"
|
||||
|
||||
source "drivers/clock_control/Kconfig.lpc11u6x"
|
||||
|
||||
source "drivers/clock_control/Kconfig.mcux_ccm"
|
||||
|
|
10
drivers/clock_control/Kconfig.fixed
Normal file
10
drivers/clock_control/Kconfig.fixed
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Fixed clock control driver config
|
||||
|
||||
# Copyright (c) 2022 Google, LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config CLOCK_CONTROL_FIXED_RATE_CLOCK
|
||||
bool "Fixed Clock Clock Control"
|
||||
default n
|
||||
help
|
||||
Enable driver for devicetree defined fixed clocks.
|
78
drivers/clock_control/clock_control_fixed_rate.c
Normal file
78
drivers/clock_control/clock_control_fixed_rate.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (C) 2022 Google, LLC
|
||||
*
|
||||
*/
|
||||
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
|
||||
#define DT_DRV_COMPAT fixed_clock
|
||||
|
||||
struct fixed_rate_clock_config {
|
||||
uint32_t rate;
|
||||
};
|
||||
|
||||
static int fixed_rate_clk_on(const struct device *dev,
|
||||
clock_control_subsys_t sys)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
ARG_UNUSED(sys);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fixed_rate_clk_off(const struct device *dev,
|
||||
clock_control_subsys_t sys)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
ARG_UNUSED(sys);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum clock_control_status fixed_rate_clk_get_status(const struct device *dev,
|
||||
clock_control_subsys_t sys)
|
||||
{
|
||||
return CLOCK_CONTROL_STATUS_ON;
|
||||
}
|
||||
|
||||
static int fixed_rate_clk_get_rate(const struct device *dev,
|
||||
clock_control_subsys_t sys,
|
||||
uint32_t *rate)
|
||||
{
|
||||
const struct fixed_rate_clock_config *config = dev->config;
|
||||
|
||||
ARG_UNUSED(sys);
|
||||
|
||||
*rate = config->rate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct clock_control_driver_api fixed_rate_clk_api = {
|
||||
.on = fixed_rate_clk_on,
|
||||
.off = fixed_rate_clk_off,
|
||||
.get_status = fixed_rate_clk_get_status,
|
||||
.get_rate = fixed_rate_clk_get_rate
|
||||
};
|
||||
|
||||
static int fixed_rate_clk_init(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FIXED_CLK_INIT(idx) \
|
||||
static const struct fixed_rate_clock_config fixed_rate_clock_config_##idx = { \
|
||||
.rate = DT_INST_PROP(idx, clock_frequency), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(idx, \
|
||||
fixed_rate_clk_init, \
|
||||
NULL, NULL, \
|
||||
&fixed_rate_clock_config_##idx, \
|
||||
PRE_KERNEL_1, \
|
||||
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, \
|
||||
&fixed_rate_clk_api \
|
||||
);
|
||||
DT_INST_FOREACH_STATUS_OKAY(FIXED_CLK_INIT)
|
9
tests/drivers/clock_control/fixed_clock/CMakeLists.txt
Normal file
9
tests/drivers/clock_control/fixed_clock/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(fixed_clock)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
17
tests/drivers/clock_control/fixed_clock/app.overlay
Normal file
17
tests/drivers/clock_control/fixed_clock/app.overlay
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Google, LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*/
|
||||
|
||||
/ {
|
||||
test {
|
||||
test_fixed_rate_clk0: clk {
|
||||
compatible = "fixed-clock";
|
||||
clock-frequency = <100>;
|
||||
#clock-cells = <0>;
|
||||
};
|
||||
|
||||
};
|
||||
};
|
4
tests/drivers/clock_control/fixed_clock/prj.conf
Normal file
4
tests/drivers/clock_control/fixed_clock/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_CLOCK_CONTROL=y
|
||||
CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK=y
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Google, LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
|
||||
#define TEST_FIXED_RATE_CLK0 DT_NODELABEL(test_fixed_rate_clk0)
|
||||
#define TEST_FIXED_RATE_CLK0_RATE DT_PROP(TEST_FIXED_RATE_CLK0, clock_frequency)
|
||||
|
||||
/*
|
||||
* Basic test for checking correctness of clock_api implementation
|
||||
*/
|
||||
ZTEST(fixed_clk, test_fixed_rate_clk_on_off_status_rate)
|
||||
{
|
||||
const struct device *dev = DEVICE_DT_GET(TEST_FIXED_RATE_CLK0);
|
||||
enum clock_control_status status;
|
||||
uint32_t rate;
|
||||
int err;
|
||||
|
||||
zassert_equal(device_is_ready(dev), true, "%s: Device wasn't ready",
|
||||
dev->name);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_on(dev, 0);
|
||||
zassert_equal(0, err, "%s: Unexpected err (%d)", dev->name, err);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_off(dev, 0);
|
||||
zassert_equal(0, err, "%s: Expected 0, got (%d)",
|
||||
dev->name, err);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_get_rate(dev, 0, &rate);
|
||||
zassert_equal(0, err, "%s: Unexpected err (%d)", dev->name, err);
|
||||
zassert_equal(TEST_FIXED_RATE_CLK0_RATE, rate,
|
||||
"%s: Got wrong rate, expected %u, got %u\n",
|
||||
dev->name, TEST_FIXED_RATE_CLK0_RATE, rate);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(fixed_clk, NULL, NULL, NULL, NULL, NULL);
|
7
tests/drivers/clock_control/fixed_clock/testcase.yaml
Normal file
7
tests/drivers/clock_control/fixed_clock/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
tests:
|
||||
drivers.clock.clock_control_fixed_clock:
|
||||
tags:
|
||||
- drivers
|
||||
- clock
|
||||
platform_allow:
|
||||
- native_posix_64
|
Loading…
Reference in a new issue