Skip to content

Commit 2dc18ee

Browse files
committed
drivers: firmware: Clock control TISCI driver support
Support added for clock control using TISCI added for devices using the binding ti,k2g-sci-clk. This driver relies on the TISCI layer to make calls to the device manager core to set and get the clock rate and retrieve clock status. Signed-off-by: Dave Joseph <d-joseph@ti.com>
1 parent bcf7717 commit 2dc18ee

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF2_GLOBAL_HSFLL clock_cont
4747
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RTS5912_SCCON clock_control_rts5912_sccon.c)
4848
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL clock_control_nrf2_audiopll.c)
4949
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_IT51XXX clock_control_it51xxx.c)
50+
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_TISCI clock_control_tisci.c)
5051

5152
if(CONFIG_CLOCK_CONTROL_NRF2)
5253
zephyr_library_sources(clock_control_nrf2_common.c)

drivers/clock_control/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,6 @@ source "drivers/clock_control/Kconfig.wch_rcc"
114114

115115
source "drivers/clock_control/Kconfig.it51xxx"
116116

117+
source "drivers/clock_control/Kconfig.tisci"
118+
117119
endif # CLOCK_CONTROL

drivers/clock_control/Kconfig.tisci

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2024 Texas Instruments Incorporated.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CLOCK_CONTROL_TISCI
5+
bool "TI SCI Clock Control driver"
6+
default y
7+
depends on TISCI
8+
help
9+
Driver for TISCI based clock control.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2025, Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdbool.h>
8+
#define DT_DRV_COMPAT ti_k2g_sci_clk
9+
10+
#include <stdint.h>
11+
#include <zephyr/device.h>
12+
#include <zephyr/drivers/firmware/tisci/ti_sci.h>
13+
#include <zephyr/drivers/clock_control.h>
14+
#include <zephyr/drivers/clock_control/tisci_clock_control.h>
15+
#include <zephyr/devicetree.h>
16+
#include <zephyr/logging/log.h>
17+
18+
LOG_MODULE_REGISTER(ti_k2g_sci_clk, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
19+
20+
const struct device *dmsc = DEVICE_DT_GET(DT_NODELABEL(dmsc));
21+
22+
static int tisci_get_rate(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
23+
{
24+
struct clock_config *req = (struct clock_config *)sys;
25+
uint64_t temp_rate;
26+
int ret = ti_sci_cmd_clk_get_freq(dmsc, req->dev_id, req->clk_id, &temp_rate);
27+
28+
if (ret) {
29+
return ret;
30+
}
31+
32+
*rate = (uint32_t)temp_rate;
33+
return 0;
34+
}
35+
36+
static int tisci_set_rate(const struct device *dev, void *sys, void *rate)
37+
{
38+
struct clock_config *req = (struct clock_config *)sys;
39+
uint64_t freq = *((uint64_t *)rate);
40+
int ret = ti_sci_cmd_clk_set_freq(dmsc, req->dev_id, req->clk_id, freq, freq, freq);
41+
return ret;
42+
}
43+
44+
static inline enum clock_control_status tisci_get_status(const struct device *dev,
45+
clock_control_subsys_t sys)
46+
{
47+
enum clock_control_status state = CLOCK_CONTROL_STATUS_UNKNOWN;
48+
struct clock_config *req = (struct clock_config *)sys;
49+
bool req_state = true;
50+
bool curr_state = true;
51+
52+
ti_sci_cmd_clk_is_on(dmsc, req->clk_id, req->dev_id, &req_state, &curr_state);
53+
if (curr_state) {
54+
state = CLOCK_CONTROL_STATUS_ON;
55+
}
56+
if (req_state && !curr_state) {
57+
state = CLOCK_CONTROL_STATUS_STARTING;
58+
}
59+
curr_state = true;
60+
ti_sci_cmd_clk_is_off(dmsc, req->clk_id, req->dev_id, NULL, &curr_state);
61+
if (curr_state) {
62+
state = CLOCK_CONTROL_STATUS_OFF;
63+
}
64+
return state;
65+
}
66+
67+
static DEVICE_API(clock_control, tisci_clock_driver_api) = {
68+
.get_rate = tisci_get_rate, .set_rate = tisci_set_rate, .get_status = tisci_get_status};
69+
70+
#define TI_K2G_SCI_CLK_INIT(_n) \
71+
DEVICE_DT_INST_DEFINE(_n, NULL, NULL, NULL, NULL, PRE_KERNEL_1, \
72+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &tisci_clock_driver_api);
73+
74+
DT_INST_FOREACH_STATUS_OKAY(TI_K2G_SCI_CLK_INIT)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 Texas Instruments Incorporated.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: TI-SCI clock controller
5+
6+
compatible: "ti,k2g-sci-clk"
7+
8+
include:
9+
- clock-controller.yaml
10+
- base.yaml
11+
12+
properties:
13+
"#clock-cells":
14+
type: int
15+
required: true
16+
description: >
17+
Number of cells required to specify a clock provided by this controller.
18+
const: 2
19+
20+
clock-cells:
21+
- devid
22+
- clkid
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
8+
#define ZEPHYR_DRIVERS_CLOCK_CONTROL_TISCI_CLOCK_CONTROL_H_
9+
10+
/**
11+
* @struct clock_config
12+
* @brief Clock configuration structure
13+
*
14+
* This structure is used to define the configuration for a clock, including
15+
* the device ID and clock ID.
16+
*
17+
* @param clock_config::dev_id
18+
* Device ID associated with the clock.
19+
*
20+
* @param clock_config::clk_id
21+
* Clock ID within the device.
22+
*/
23+
#include <stdint.h>
24+
struct clock_config {
25+
uint32_t dev_id;
26+
uint32_t clk_id;
27+
};
28+
29+
#define TISCI_GET_CLOCK(_dev) DEVICE_DT_GET(DT_PHANDLE(DT_NODELABEL(_dev), clocks))
30+
#define TISCI_GET_CLOCK_DETAILS(_dev) \
31+
{.dev_id = DT_CLOCKS_CELL(DT_NODELABEL(_dev), devid), \
32+
.clk_id = DT_CLOCKS_CELL(DT_NODELABEL(_dev), clkid)}
33+
#endif

0 commit comments

Comments
 (0)